18
18
19
19
import com .google .classyshark .silverghost .contentreader .BinaryContentReader ;
20
20
import com .google .classyshark .silverghost .contentreader .ContentReader ;
21
- import com .google .classyshark .silverghost .contentreader .dex .DexReader ;
22
- import com .google .classyshark .silverghost .translator .xml .XmlDecompressor ;
23
-
24
- import com .google .classyshark .silverghost .io .SherlockHash ;
25
-
26
21
import java .io .File ;
27
- import java .io .FileInputStream ;
28
22
import java .util .ArrayList ;
29
23
import java .util .List ;
30
- import java . util . zip . ZipEntry ;
31
- import java .util . zip . ZipInputStream ;
24
+
25
+ import static com . google . classyshark . silverghost . translator . java .dex . Multidex . readClassNamesFromMultidex ;
32
26
33
27
public class ApkReader implements BinaryContentReader {
34
28
@@ -44,7 +38,7 @@ public ApkReader(File binaryArchive) {
44
38
public void read () {
45
39
readClassNamesFromMultidex (binaryArchive , allClassNames , components );
46
40
47
- // TODO add check for manifest
41
+ // TODO add isPrivate for manifest
48
42
// allClassNames.add(6, "AndroidManifest.xml");
49
43
}
50
44
@@ -58,95 +52,4 @@ public List<ContentReader.Component> getComponents() {
58
52
// TODO add manifest here
59
53
return components ;
60
54
}
61
-
62
- private static void readClassNamesFromMultidex (File binaryArchiveFile ,
63
- List <String > classNames ,
64
- List <ContentReader .Component > components ) {
65
- ZipInputStream zipInputStream ;
66
- try {
67
- zipInputStream = new ZipInputStream (new FileInputStream (
68
- binaryArchiveFile ));
69
-
70
- ZipEntry zipEntry ;
71
-
72
- int dexIndex = 0 ;
73
- while (true ) {
74
- zipEntry = zipInputStream .getNextEntry ();
75
-
76
- if (zipEntry == null ) {
77
- break ;
78
- }
79
-
80
- if (zipEntry .getName ().endsWith (".xml" )) {
81
- classNames .add (zipEntry .getName ());
82
- }
83
-
84
- if (zipEntry .getName ().endsWith (".dex" )) {
85
- String fName = "classes" ;
86
- if (dexIndex > 0 ) {
87
- fName = fName + dexIndex ;
88
- }
89
- String ext = "dex" ;
90
-
91
- File file = SherlockHash .INSTANCE .getFileFromZipStream (binaryArchiveFile ,
92
- zipInputStream , fName , ext );
93
-
94
- List <String > classesAtDex =
95
- DexReader .readClassNamesFromDex (file );
96
-
97
- classNames .add (fName + ".dex" );
98
- classNames .addAll (classesAtDex );
99
- dexIndex ++;
100
- }
101
- if (zipEntry .getName ().startsWith ("lib" )) {
102
- components .add (
103
- new ContentReader .Component (zipEntry .getName (),
104
- ContentReader .ARCHIVE_COMPONENT .NATIVE_LIBRARY ));
105
- }
106
-
107
- // Dynamic dex loading
108
- if (zipEntry .getName ().endsWith ("jar" ) || zipEntry .getName ().endsWith ("zip" )) {
109
- String fName = "inner_zip" ;
110
- String ext = "zip" ;
111
-
112
- File innerZip = SherlockHash .INSTANCE .getFileFromZipStream (binaryArchiveFile ,
113
- zipInputStream , fName , ext );
114
-
115
- // so far we have a zip file
116
- ZipInputStream fromInnerZip = new ZipInputStream (new FileInputStream (
117
- innerZip ));
118
-
119
- ZipEntry innerZipEntry ;
120
-
121
- while (true ) {
122
- innerZipEntry = fromInnerZip .getNextEntry ();
123
-
124
- if (innerZipEntry == null ) {
125
- break ;
126
- }
127
-
128
- if (innerZipEntry .getName ().endsWith (".dex" )) {
129
- fName = "inner_zip_classes" + dexIndex ;
130
- ext = "dex" ;
131
- File tempDexFile =
132
- SherlockHash .INSTANCE .getFileFromZipStream (binaryArchiveFile ,
133
- fromInnerZip , fName , ext );
134
-
135
- List <String > classesAtDex =
136
- DexReader .readClassNamesFromDex (tempDexFile );
137
-
138
- String name = zipEntry .getName () + "###" + innerZipEntry .getName ();
139
-
140
- classNames .add (name );
141
- classNames .addAll (classesAtDex );
142
- }
143
- }
144
- }
145
- }
146
- zipInputStream .close ();
147
-
148
- } catch (Exception e ) {
149
- e .printStackTrace ();
150
- }
151
- }
152
55
}
0 commit comments