proxmark3/tools/srecswap.pl

36 lines
620 B
Perl
Raw Normal View History

2010-02-21 05:56:46 +08:00
#!/usr/bin/perl
# endian-swap S records; we need this because the JTAG tools we're using
# expect the memory image in byte-swapped format
#
# Jonathan Westhues, April 2004
if(@ARGV == 0) {
die "usage: $0 file-to-endian-swap.s19 > out.s19\n";
2010-02-21 05:56:46 +08:00
}
while(<>) {
chomp;
2010-02-21 05:56:46 +08:00
if(/^S0/) {
next;
}
if(/^S7/) {
print "$_\n";
next;
}
2010-02-21 05:56:46 +08:00
if(not /^S3(..)(........)(.*)(..)$/) {
die "bad S record at line $.\n";
}
2010-02-21 05:56:46 +08:00
$data = $3;
$checksum = $4;
2010-02-21 05:56:46 +08:00
print "S3$1$2";
while($data =~ m#(..)(..)(..)(..)#g) {
print "$4$3$2$1";
}
print "$checksum\n";
2010-02-21 05:56:46 +08:00
}