-
Notifications
You must be signed in to change notification settings - Fork 4
/
aaptdump
executable file
·78 lines (60 loc) · 2.01 KB
/
aaptdump
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
72
73
74
75
76
77
78
#!/usr/bin/perl
use File::Path qw(make_path);
use File::Basename;
# Create under current directory
while( $apkpath=shift ) {
my ($apkname, $apkdir ) = fileparse( $apkpath, ( ".apk" ) );
print "Dumping $apkname\n";
if( !mkdir "$apkname" ) {
print STDERR "Failed to create directory $apkname: $!\n";
return 1;
}
open( RESOURCES, "-|", "aapt", ("d", "--values", "resources", $apkpath) )
or die "Failed to read resources";
open( OUTPUT, ">", "$apkname/resources.txt" )
or die "Faile to create $apkname/resources.txt: $!";
while( <RESOURCES> ) {
chomp;
if( m/^\s*resource 0x.* \(PUBLIC\)$/ ) {
s/ \(PUBLIC\)$//;
}
if( s/ flags=0x4([0-9a-f]{7})$/ flags=0x0\1/ ) {
} elsif( m/^\s*resource 0x.*: t=0x03 d=0x[0-9a-f]{8} \(s=0x[0-9a-f]{4} r=0x[0-9a-f]{2}\)$/ )
{
s/: t=0x03 d=0x[0-9a-f]{8} /: t=0x03 d=0x00000000 /;
}
print OUTPUT "$_\n";
}
close OUTPUT;
close RESOURCES;
open( APKLIST, "-|", "aapt", ("l", $apkpath))
or die "Failed to open APK list";
while( <APKLIST> ) {
chomp;
my $file=$_;
if( m'^res/raw.*\.xml$' ) {
} elsif( m'^res/.*\.xml$' ) {
xml_dump( $apkpath, $_, $apkname );
} elsif( m'^res/(xml|anim|layout|menu)' ) {
# ALL files under those directories are xml
xml_dump( $apkpath, $_, $apkname );
}
}
}
sub xml_dump
{
my( $apkpath, $filename, $outdir ) = @_;
my $error;
make_path( dirname("$outdir/$filename"), { error => \$error } );
open XMLFILE, "-|", "aapt", ("d", "xmltree", $apkpath, $filename)
or die "Failed to dump XML tree $filename";
open OUTFILE, ">", "$outdir/$filename"
or die "Faile to create output file $outdir/$filename: $!";
while( <XMLFILE> ) {
chomp;
s/^(\s*E: .*) \(line=([0-9]+)\)$/\1 (line=0)/;
print OUTFILE "$_\n";
}
close XMLFILE;
close OUTFILE;
}