Makefile: display firmware size
[RRG-proxmark3.git] / tools / pm3_cs8.pl
blobf1bfaf81ddcafafd3273497fa5f5dcf6763d1ea3
1 #!/usr/bin/perl
3 # Convert proxmark3 trace or wav files to formats to be used by Inspectrum
5 # Converts proxmark3 trace to cs8 (Complex 8-bit signed integer samples, eg HackRF IQ format)
6 # and .wav to cs16 (Complex 16-bit signed integer samples, eg BladeRF IQ format)
8 # -samy kamkar, https://samy.pl
10 # we use `sox` to convert, set this to full path if preferred
11 my $SOX = "sox";
13 use strict;
15 die "usage: $0 [/path/to/sox (optional)] <pm3.trace or file.wav> [...more traces]\n" unless @ARGV;
16 $SOX = shift if $ARGV[0] =~ m/(?:[\/\\]|^)sox$/;
17 trace_conv($_) for @ARGV;
19 sub trace_conv
21 my $file = shift;
22 if ($file =~ /wav$/i)
24 my @run = ($SOX, qw/$file -t raw -e signed-integer -b 16 $file.cs16/);
25 run_rewrite($file, @run);
26 print "Wrote $file.cs16\n\n";
28 else
30 my $f = "/tmp/pm3.trace." . rand();
31 open(F, ">$f") || die "Can't write to $f: $!";
32 open(IN, "<$file") || die "Can't read $file: $!";
33 while (<IN>)
35 chomp;
36 print F pack "c", $_;
38 close(IN);
39 close(F);
41 # upsample 100x and pad 2nd channel with zeroes
42 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/);
43 run_rewrite($f, @run);
45 # pad file since inspectrum doesn't handle small files so well
46 open(OUT, ">$file.cs8") || die $!;
47 open(IN, "<$f.cs8") || die $!;
48 print OUT while <IN>;
49 print OUT "\0" x (1024 * 1024);
50 close(IN);
51 close(OUT);
53 unlink($f, "$f.cs8");
54 print "Wrote $file.cs8\n\n";
58 sub run_rewrite
60 my ($file, @run) = @_;
61 s/\$file/$file/ foreach @run;
62 print "Running: @run\n";
64 my $ret = system(@run);
65 die "Failed: $! ($ret)\ndo you have $run[0] installed?\n" if $ret;