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

Commit 3ce4de5

Browse files
committed
Merge pull request #69 from google/dex-in-dex
Dex in dex
2 parents 042be64 + 953f523 commit 3ce4de5

File tree

6 files changed

+159
-5
lines changed

6 files changed

+159
-5
lines changed

ClassySharkWS/src/com/google/classyshark/gui/panel/displayarea/doodles/Doodle.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818

1919
public class Doodle {
2020
public static String get() {
21-
return SanFranBG.SHARKEY;
21+
return SharkBG.SHARKEY;
2222
}
2323
}

ClassySharkWS/src/com/google/classyshark/gui/panel/displayarea/doodles/SharkBG.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@ class SharkBG {
4646
+ " ii! '*YMWM, \n"
4747
+ " I' \"YM\n"
4848
+ "\n\n\n\thttp://www.retrojunkie.com/asciiart/animals/sharks.htm"
49-
+ "\n\n\n\tClassyShark ver. 6.0 powered by SilverGhost";
49+
+ "\n\n\n\tClassyShark ver. 6.1 powered by SilverGhost";
5050

5151
}

ClassySharkWS/src/com/google/classyshark/gui/panel/tree/FilesTree.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ public void valueChanged(TreeSelectionEvent e) {
200200

201201
DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode) selection;
202202

203-
if (selection.toString().startsWith("classes") &&
204-
selection.toString().endsWith(".dex")) {
203+
if (selection.toString().endsWith(".dex")) {
205204
FilesTree.this.viewerController.onSelectedClassName(
206205
(String) defaultMutableTreeNode.getUserObject());
207206
return;

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

+54-1
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

+49
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,55 @@ private static File extractClassesDex(String dexName, File apkFile, DexInfoTrans
139139
break;
140140
}
141141
}
142+
143+
if (zipEntry.getName().endsWith("jar") || zipEntry.getName().endsWith("zip")) {
144+
145+
File innerZip = File.createTempFile("inner_zip", "zip");
146+
innerZip.deleteOnExit();
147+
148+
FileOutputStream fos =
149+
new FileOutputStream(innerZip);
150+
byte[] bytes = new byte[1024];
151+
int length;
152+
while ((length = zipFile.read(bytes)) >= 0) {
153+
fos.write(bytes, 0, length);
154+
}
155+
156+
fos.close();
157+
158+
// so far we have a zip file
159+
ZipInputStream fromInnerZip = new ZipInputStream(new FileInputStream(
160+
innerZip));
161+
162+
ZipEntry innerZipEntry;
163+
164+
while (true) {
165+
innerZipEntry = fromInnerZip.getNextEntry();
166+
167+
if (innerZipEntry == null) {
168+
fromInnerZip.close();
169+
break;
170+
}
171+
172+
if (innerZipEntry.getName().endsWith(".dex")) {
173+
file = File.createTempFile("classes_innerzip", "dex");
174+
FileOutputStream fos1 = new FileOutputStream(file);
175+
byte[] bytes1 = new byte[1024];
176+
177+
while ((length = fromInnerZip.read(bytes1)) >= 0) {
178+
fos1.write(bytes1, 0, length);
179+
}
180+
181+
fos1.close();
182+
183+
if (dexName.startsWith(zipEntry.getName())) {
184+
diTranslator.index = 99;
185+
zipFile.close();
186+
return file;
187+
}
188+
}
189+
}
190+
}
142191
}
143192
zipFile.close();
144193
} catch (Exception e) {

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

+53
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)