Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit 2d492dc

Browse files
committed
init drop added reading and class showing
Missing dex parameters
1 parent 042be64 commit 2d492dc

File tree

3 files changed

+109
-1
lines changed

3 files changed

+109
-1
lines changed

ClassySharkWS/src/com/google/classyshark/silverghost/contentreader/apk/ApkReader.java

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ private static void readClassNamesFromMultidex(File binaryArchiveFile,
7575
}
7676

7777
if (zipEntry.getName().endsWith(".dex")) {
78+
7879
File file = File.createTempFile("classes" + dexIndex, "dex");
7980
file.deleteOnExit();
8081

@@ -89,7 +90,7 @@ private static void readClassNamesFromMultidex(File binaryArchiveFile,
8990
fos.close();
9091

9192
List<String> classesAtDex =
92-
DexReader.readClassNamesFromDex(binaryArchiveFile);
93+
DexReader.readClassNamesFromDex(file);
9394

9495
classNames.add("classes" + dexIndex + ".dex");
9596
classNames.addAll(classesAtDex);
@@ -100,6 +101,58 @@ private static void readClassNamesFromMultidex(File binaryArchiveFile,
100101
new ContentReader.Component(zipEntry.getName(),
101102
ContentReader.ARCHIVE_COMPONENT.NATIVE_LIBRARY));
102103
}
104+
105+
// Dynamic dex loading
106+
if (zipEntry.getName().endsWith("jar") || zipEntry.getName().endsWith("zip")) {
107+
File innerZip = File.createTempFile("inner_zip", "zip");
108+
innerZip.deleteOnExit();
109+
110+
FileOutputStream fos =
111+
new FileOutputStream(innerZip);
112+
byte[] bytes = new byte[1024];
113+
int length;
114+
while ((length = zipFile.read(bytes)) >= 0) {
115+
fos.write(bytes, 0, length);
116+
}
117+
118+
fos.close();
119+
120+
// so far we have a zip file
121+
ZipInputStream fromInnerZip = new ZipInputStream(new FileInputStream(
122+
innerZip));
123+
124+
ZipEntry innerZipEntry;
125+
126+
while (true) {
127+
innerZipEntry = fromInnerZip.getNextEntry();
128+
129+
if (innerZipEntry == null) {
130+
break;
131+
}
132+
133+
if (innerZipEntry.getName().endsWith(".dex")) {
134+
File tempDexFile = File.createTempFile("inner_zip_classes" + dexIndex, "dex");
135+
tempDexFile.deleteOnExit();
136+
137+
FileOutputStream fos1 = new FileOutputStream(tempDexFile);
138+
byte[] bytes1 = new byte[1024];
139+
140+
while ((length = fromInnerZip.read(bytes1)) >= 0) {
141+
fos1.write(bytes1, 0, length);
142+
}
143+
144+
fos1.close();
145+
146+
List<String> classesAtDex =
147+
DexReader.readClassNamesFromDex(tempDexFile);
148+
149+
String name = zipEntry.getName() + "###" + innerZipEntry.getName();
150+
151+
classNames.add(name);
152+
classNames.addAll(classesAtDex);
153+
}
154+
}
155+
}
103156
}
104157
zipFile.close();
105158

ClassySharkWS/src/com/google/classyshark/silverghost/translator/dex/DexInfoTranslator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ private static File extractClassesDex(String dexName, File apkFile, DexInfoTrans
139139
break;
140140
}
141141
}
142+
143+
// TODO add here login for custom dex loading
142144
}
143145
zipFile.close();
144146
} catch (Exception e) {

ClassySharkWS/src/com/google/classyshark/silverghost/translator/java/dex/Multidex.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ private Multidex() {
2929
}
3030

3131
public static File extractClassesDexWithClass(String className, File apkFile) {
32+
33+
// TODO need to delete this file
3234
File file = new File("classes.dex");
3335
ZipInputStream zipFile;
3436
try {
@@ -66,6 +68,57 @@ public static File extractClassesDexWithClass(String className, File apkFile) {
6668
break;
6769
}
6870
}
71+
72+
if (zipEntry.getName().endsWith("jar") || zipEntry.getName().endsWith("zip")) {
73+
74+
File innerZip = File.createTempFile("inner_zip", "zip");
75+
innerZip.deleteOnExit();
76+
77+
FileOutputStream fos =
78+
new FileOutputStream(innerZip);
79+
byte[] bytes = new byte[1024];
80+
int length;
81+
while ((length = zipFile.read(bytes)) >= 0) {
82+
fos.write(bytes, 0, length);
83+
}
84+
85+
fos.close();
86+
87+
// so far we have a zip file
88+
ZipInputStream fromInnerZip = new ZipInputStream(new FileInputStream(
89+
innerZip));
90+
91+
ZipEntry innerZipEntry;
92+
93+
while (true) {
94+
innerZipEntry = fromInnerZip.getNextEntry();
95+
96+
if (innerZipEntry == null) {
97+
fromInnerZip.close();
98+
break;
99+
}
100+
101+
if (innerZipEntry.getName().endsWith(".dex")) {
102+
file = File.createTempFile("classes_innerzip", "dex");
103+
FileOutputStream fos1 = new FileOutputStream(file);
104+
byte[] bytes1 = new byte[1024];
105+
106+
while ((length = fromInnerZip.read(bytes1)) >= 0) {
107+
fos1.write(bytes1, 0, length);
108+
}
109+
110+
fos1.close();
111+
112+
List<String> classNamesInDex =
113+
DexReader.readClassNamesFromDex(file);
114+
if (classNamesInDex.contains(className)) {
115+
fromInnerZip.close();
116+
zipFile.close();
117+
return file;
118+
}
119+
}
120+
}
121+
}
69122
}
70123
zipFile.close();
71124
} catch (Exception e) {

0 commit comments

Comments
 (0)