Skip to content

Instantly share code, notes, and snippets.

@develop7
Forked from steeve/aml_fw_unpack.pl
Created December 7, 2015 20:13
Show Gist options
  • Save develop7/2f0a6bf1934a9dcc40e1 to your computer and use it in GitHub Desktop.
Save develop7/2f0a6bf1934a9dcc40e1 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
use strict;
if ($#ARGV < 0) {
print "Usage: aml_fw_unpack.pl file.img\n";
exit(1);
}
my $filecontent;
{
local $/=undef;
open(FILE, $ARGV[0]) or die "Can't open $ARGV[0]: $!\n";
binmode(FILE);
$filecontent = <FILE>;
close(FILE);
}
my $numfiles = unpack("C", substr($filecontent,0x18,1));
$numfiles = $numfiles - 1;
print "$numfiles files\n";
my ($i, $desc_offset, $fn_offset, $fn_offset2, $fs_offset, $fo_offset, $fn, $fn2, $fs, $fo);
for($i=0; $i < $numfiles; $i++) {
$desc_offset = 0x80 * ($i+1);
$fn_offset = $desc_offset + 0x80;
$fn_offset2 = $desc_offset + 0x60;
$fs_offset = $desc_offset + 88;
$fo_offset = $desc_offset + 80;
$fn = substr($filecontent, $fn_offset, 0x20);
$fn2 = substr($filecontent, $fn_offset2, 0x20);
$fs = unpack("V", substr($filecontent, $fs_offset, 8));
$fo = unpack("V", substr($filecontent, $fo_offset, 8));
$fn =~ s/\0//g;
$fn2 =~ s/\0//g;
printf("File $i: name=$fn-$fn2, size=0x%X (%d), offset=0x%X (%d) \n", $fs, $fs, $fo, $fo);
print "$fn-$fn2\n";
open(FILE, ">", "$fn-$fn2") or die "Can't open $fn-$fn2 for writing: $!\n";
binmode(FILE);
print FILE substr($filecontent, $fo, $fs);
close(FILE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment