]>
git.saurik.com Git - android/aapt.git/blob - printapk.cpp
1 #include <utils/ResourceTypes.h>
2 #include <utils/String8.h>
3 #include <utils/String16.h>
4 #include <zipfile/zipfile.h>
10 using namespace android
;
16 "usage: apk APKFILE\n"
18 "APKFILE an android packge file produced by aapt.\n"
25 main(int argc
, char** argv
)
44 fd
= open(filename
, O_RDONLY
);
46 fprintf(stderr
, "apk: couldn't open file for read: %s\n", filename
);
50 size
= lseek(fd
, 0, SEEK_END
);
51 amt
= lseek(fd
, 0, SEEK_SET
);
53 if (size
< 0 || amt
< 0) {
54 fprintf(stderr
, "apk: error determining file size: %s\n", filename
);
60 fprintf(stderr
, "apk: file too big: %s\n", filename
);
64 amt
= read(fd
, buf
, size
);
66 fprintf(stderr
, "apk: error reading file: %s\n", filename
);
72 zip
= init_zipfile(buf
, size
);
74 fprintf(stderr
, "apk: file doesn't seem to be a zip file: %s\n",
81 while ((entry
= iterate_zipfile(zip
, &cookie
))) {
82 char* name
= get_zipentry_name(entry
);
83 printf(" %s\n", name
);
87 entry
= lookup_zipentry(zip
, "resources.arsc");
89 size
= get_zipentry_size(entry
);
90 bufsize
= size
+ (size
/ 1000) + 1;
91 resfile
= malloc(bufsize
);
93 err
= decompress_zipentry(entry
, resfile
, bufsize
);
95 fprintf(stderr
, "apk: error decompressing resources.arsc");
99 ResTable
res(resfile
, size
, resfile
);
102 size_t tableCount
= res
.getTableCount();
103 printf("Tables: %d\n", (int)tableCount
);
104 for (size_t tableIndex
=0; tableIndex
<tableCount
; tableIndex
++) {
105 const ResStringPool
* strings
= res
.getTableStringBlock(tableIndex
);
106 size_t stringCount
= strings
->size();
107 for (size_t stringIndex
=0; stringIndex
<stringCount
; stringIndex
++) {
109 const char16_t* ch
= strings
->stringAt(stringIndex
, &len
);
110 String8
s(String16(ch
, len
));
111 printf(" [%3d] %s\n", (int)stringIndex
, s
.string());
115 size_t basePackageCount
= res
.getBasePackageCount();
116 printf("Base Packages: %d\n", (int)basePackageCount
);
117 for (size_t bpIndex
=0; bpIndex
<basePackageCount
; bpIndex
++) {
118 const char16_t* ch
= res
.getBasePackageName(bpIndex
);
119 String8 s
= String8(String16(ch
));
120 printf(" [%3d] %s\n", (int)bpIndex
, s
.string());