-
Notifications
You must be signed in to change notification settings - Fork 0
/
unpack.perl
68 lines (60 loc) · 1.54 KB
/
unpack.perl
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
#!/usr/bin/perl -I /home/audris/lib/x86_64-linux-gnu/perl
use strict;
use warnings;
use Try::Tiny;
use Compress::Raw::Zlib;
use Compress::LZF;
open A, "packfile";
binmode(A);
my @stat = stat "packfile";
my $s = $stat[7];
my $c ="";
my $rl=read (A, $c, $s);
my $strB = substr($c, 0, $s-20);
my $strE = substr($c, $s-20, $s);
my $sha = unpack "H*", $strE;
my ($m, $v, $no, $str1) = unpack "a4 N N a*", $strB;
my $left = length ($str1);
print "rl=$rl s=$s $m version=$v nObj=$no $sha left=$left\n";
while (length ($str1) > 6){
my ($t0, $str0) = unpack "C a*", $str1;
$str1 = $str0;
my $h = $t0 & 128;
my $sz0 = $t0 & 0b1111;
$t0 = ($t0 >> 4) & 0b111;
my @a = ($sz0);
while ($h){
printf "$h next %b\n", $sz0;
$sz0 = unpack "C a*", $str1;
$h = $sz0 & 128;
$left -= 1;
$str1 = substr ($str1, 1, length($str1)-1);
$sz0 = ($sz0 & 127);
push @a, $sz0;
}
my $len1 = 0;
for my $i (0..$#a){
my $mult = 1;
$mult = 16 * (128**($i-1)) if $i > 1;
$len1 += $a[$i] * $mult;
printf "i=%d %b %d\n", $i, $a[$i], $a[$i]*$mult;
}
printf "type=%b len1=%d\n", $t0, $len1;
my ($inf, $status) = new Compress::Raw::Zlib::Inflate( -Bufsize => 300 );
my $code;
print "status=$status lB=".(length($str1))."\n";
$status = $inf->inflate($str1, $code);
print "lA=".(length($str1))."\n";
print "$code\n";
}
sub safeDecomp {
my ($codeC, $msg) = @_;
eval {
my $code = decompress ($codeC);
return $code;
} or do {
my $ex = $@;
#print STDERR "Error: $ex, $msg\n";
return "";
}
}