forked from open2jamorg/open2jam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
snp_unpacker.pl
72 lines (63 loc) · 1.13 KB
/
snp_unpacker.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use warnings;
use Data::Dumper;
use Compress::Zlib;
my $filename = shift;
open DATA, $filename or die $!;
binmode DATA;
my $header;
read DATA, $header, 24 or die $!;
my $h = unpack2hash(join(' ',qw/
Z8:$signature
i:$unk
i:$file_count
i:$dir_count
i:$size
/), $header);
print Dumper $h;
while (!eof DATA)
{
read DATA, $header, 0x91 or die $!;
my $f = unpack2hash(join(' ',qw/
c:$isDir
Z128:$name
i:$sizeOriginal
i:$sizePacked
i:$parentDirOffset
i:$nextAdressOffset
/), $header);
print Dumper $f;
if($f->{'sizePacked'} > 0)
{
dump_unpacked($f->{'name'},$f->{'sizePacked'});
}
}
my $buf;
sub dump_unpacked
{
my ($ref,$size) = @_;
open MP, ">$ref";
binmode MP;
read DATA, $buf, $size;
my $unpkd = uncompress($buf);
print MP $unpkd;
close MP;
}
sub unpack2hash
{
my ($template, $source) = @_;
my $hash = {};
foreach(split ' ',$template)
{
my ($temp,$type,$var) = split /:(.)/;
if($type eq '@')
{
@{$hash->{$var}} = unpack $temp, $source;
}elsif($type eq '$')
{
$hash->{$var} = unpack $temp, $source;
}
else{ die "need context type\n" }
substr $source, 0, length(pack $temp), '';
}
return $hash;
}