mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-01-31 12:31:32 +08:00
Support multiple files, sanitize input, detect sox
This commit is contained in:
parent
406d048059
commit
5f7fe45f58
1 changed files with 52 additions and 29 deletions
|
@ -1,43 +1,66 @@
|
|||
#!/usr/bin/perl
|
||||
#
|
||||
# Convert proxmark3 trace or wav files to formats to be used by Inspectrum
|
||||
#
|
||||
# Converts proxmark3 trace to cs8 (Complex 8-bit signed integer samples, eg HackRF IQ format)
|
||||
# and .wav to cs16 (Complex 16-bit signed integer samples, eg BladeRF IQ format)
|
||||
#
|
||||
# -samy kamkar, https://samy.pl
|
||||
|
||||
# we use `sox` to convert, set this to full path if preferred
|
||||
my $SOX = "sox";
|
||||
|
||||
use strict;
|
||||
|
||||
die "usage: $0 <pm3.trace/file.wav>\n" unless @ARGV == 1;
|
||||
# Convert proxmark3 trace to cs8 (complex int8/hackrf fmt) for inspectrum
|
||||
# From miek
|
||||
die "usage: $0 [/path/to/sox (optional)] <pm3.trace or file.wav> [...more traces]\n" unless @ARGV;
|
||||
$SOX = shift if $ARGV[0] =~ m/(?:[\/\\]|^)sox$/;
|
||||
trace_conv($_) for @ARGV;
|
||||
|
||||
if ($ARGV[0] =~ /wav$/)
|
||||
sub trace_conv
|
||||
{
|
||||
system("sox $ARGV[0] -t raw -e signed-integer -b 16 $ARGV[0].cs16");
|
||||
}
|
||||
else
|
||||
{
|
||||
#perl -ne 'chomp; print pack "c", $_' p.trace > p.c8
|
||||
my $f = "/tmp/pm3.trace." . rand();
|
||||
open(F, ">$f") || die $!;
|
||||
open(IN, "<$ARGV[0]");
|
||||
while (<IN>)
|
||||
my $file = shift;
|
||||
if ($file =~ /wav$/i)
|
||||
{
|
||||
chomp;
|
||||
print F pack "c", $_;
|
||||
my @run = ($SOX, qw/$file -t raw -e signed-integer -b 16 $file.cs16/);
|
||||
run_rewrite($file, @run);
|
||||
print "Wrote $file.cs16\n\n";
|
||||
}
|
||||
close(IN);
|
||||
close(F);
|
||||
else
|
||||
{
|
||||
my $f = "/tmp/pm3.trace." . rand();
|
||||
open(F, ">$f") || die "Can't write to $f: $!";
|
||||
open(IN, "<$file") || die "Can't read $file: $!";
|
||||
while (<IN>)
|
||||
{
|
||||
chomp;
|
||||
print F pack "c", $_;
|
||||
}
|
||||
close(IN);
|
||||
close(F);
|
||||
|
||||
# upsample 100x and pad 2nd channel with zeroes
|
||||
system("sox -t s8 -r 1 -c 1 -v 0.5 $f -t s8 -r 100 -c 2 $f.cs8 remix 1 0");
|
||||
# upsample 100x and pad 2nd channel with zeroes
|
||||
my @run = ($SOX, qw/-t s8 -r 1 -c 1 -v 0.5 $file -t s8 -r 100 -c 2 $file.cs8 remix 1 0/);
|
||||
run_rewrite($f, @run);
|
||||
|
||||
open(OUT, ">$ARGV[0].cs8") || die $!;
|
||||
open(IN, "<$f.cs8") || die $!;
|
||||
print OUT while <IN>;
|
||||
print OUT "\0" x (1024 * 1024);
|
||||
close(IN);
|
||||
close(OUT);
|
||||
# pad file since inspectrum doesn't handle small files so well
|
||||
open(OUT, ">$file.cs8") || die $!;
|
||||
open(IN, "<$f.cs8") || die $!;
|
||||
print OUT while <IN>;
|
||||
print OUT "\0" x (1024 * 1024);
|
||||
close(IN);
|
||||
close(OUT);
|
||||
|
||||
unlink($f, "$f.cs8");
|
||||
unlink($f, "$f.cs8");
|
||||
print "Wrote $file.cs8\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
# pad file since inspectrum doesn't handle small files so well
|
||||
#system("dd if=/dev/zero of=$f.pad bs=1m count=1 >>/dev/null");
|
||||
sub run_rewrite
|
||||
{
|
||||
my ($file, @run) = @_;
|
||||
s/\$file/$file/ foreach @run;
|
||||
print "Running: @run\n";
|
||||
|
||||
#system("cat $f.cs8 $f.pad > $ARGV[1]");
|
||||
my $ret = system(@run);
|
||||
die "Failed: $! ($ret)\ndo you have $run[0] installed?\n" if $ret;
|
||||
}
|
Loading…
Reference in a new issue