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

Commit

Permalink
Merge pull request #69 from google/dex-in-dex
Browse files Browse the repository at this point in the history
Dex in dex
  • Loading branch information
borisf committed Apr 4, 2016
2 parents 042be64 + 953f523 commit 3ce4de5
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@

public class Doodle {
public static String get() {
return SanFranBG.SHARKEY;
return SharkBG.SHARKEY;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ class SharkBG {
+ " ii! '*YMWM, \n"
+ " I' \"YM\n"
+ "\n\n\n\thttp://www.retrojunkie.com/asciiart/animals/sharks.htm"
+ "\n\n\n\tClassyShark ver. 6.0 powered by SilverGhost";
+ "\n\n\n\tClassyShark ver. 6.1 powered by SilverGhost";

}
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ public void valueChanged(TreeSelectionEvent e) {

DefaultMutableTreeNode defaultMutableTreeNode = (DefaultMutableTreeNode) selection;

if (selection.toString().startsWith("classes") &&
selection.toString().endsWith(".dex")) {
if (selection.toString().endsWith(".dex")) {
FilesTree.this.viewerController.onSelectedClassName(
(String) defaultMutableTreeNode.getUserObject());
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ private static void readClassNamesFromMultidex(File binaryArchiveFile,
}

if (zipEntry.getName().endsWith(".dex")) {

File file = File.createTempFile("classes" + dexIndex, "dex");
file.deleteOnExit();

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

List<String> classesAtDex =
DexReader.readClassNamesFromDex(binaryArchiveFile);
DexReader.readClassNamesFromDex(file);

classNames.add("classes" + dexIndex + ".dex");
classNames.addAll(classesAtDex);
Expand All @@ -100,6 +101,58 @@ private static void readClassNamesFromMultidex(File binaryArchiveFile,
new ContentReader.Component(zipEntry.getName(),
ContentReader.ARCHIVE_COMPONENT.NATIVE_LIBRARY));
}

// Dynamic dex loading
if (zipEntry.getName().endsWith("jar") || zipEntry.getName().endsWith("zip")) {
File innerZip = File.createTempFile("inner_zip", "zip");
innerZip.deleteOnExit();

FileOutputStream fos =
new FileOutputStream(innerZip);
byte[] bytes = new byte[1024];
int length;
while ((length = zipFile.read(bytes)) >= 0) {
fos.write(bytes, 0, length);
}

fos.close();

// so far we have a zip file
ZipInputStream fromInnerZip = new ZipInputStream(new FileInputStream(
innerZip));

ZipEntry innerZipEntry;

while (true) {
innerZipEntry = fromInnerZip.getNextEntry();

if (innerZipEntry == null) {
break;
}

if (innerZipEntry.getName().endsWith(".dex")) {
File tempDexFile = File.createTempFile("inner_zip_classes" + dexIndex, "dex");
tempDexFile.deleteOnExit();

FileOutputStream fos1 = new FileOutputStream(tempDexFile);
byte[] bytes1 = new byte[1024];

while ((length = fromInnerZip.read(bytes1)) >= 0) {
fos1.write(bytes1, 0, length);
}

fos1.close();

List<String> classesAtDex =
DexReader.readClassNamesFromDex(tempDexFile);

String name = zipEntry.getName() + "###" + innerZipEntry.getName();

classNames.add(name);
classNames.addAll(classesAtDex);
}
}
}
}
zipFile.close();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,55 @@ private static File extractClassesDex(String dexName, File apkFile, DexInfoTrans
break;
}
}

if (zipEntry.getName().endsWith("jar") || zipEntry.getName().endsWith("zip")) {

File innerZip = File.createTempFile("inner_zip", "zip");
innerZip.deleteOnExit();

FileOutputStream fos =
new FileOutputStream(innerZip);
byte[] bytes = new byte[1024];
int length;
while ((length = zipFile.read(bytes)) >= 0) {
fos.write(bytes, 0, length);
}

fos.close();

// so far we have a zip file
ZipInputStream fromInnerZip = new ZipInputStream(new FileInputStream(
innerZip));

ZipEntry innerZipEntry;

while (true) {
innerZipEntry = fromInnerZip.getNextEntry();

if (innerZipEntry == null) {
fromInnerZip.close();
break;
}

if (innerZipEntry.getName().endsWith(".dex")) {
file = File.createTempFile("classes_innerzip", "dex");
FileOutputStream fos1 = new FileOutputStream(file);
byte[] bytes1 = new byte[1024];

while ((length = fromInnerZip.read(bytes1)) >= 0) {
fos1.write(bytes1, 0, length);
}

fos1.close();

if (dexName.startsWith(zipEntry.getName())) {
diTranslator.index = 99;
zipFile.close();
return file;
}
}
}
}
}
zipFile.close();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ private Multidex() {
}

public static File extractClassesDexWithClass(String className, File apkFile) {

// TODO need to delete this file
File file = new File("classes.dex");
ZipInputStream zipFile;
try {
Expand Down Expand Up @@ -66,6 +68,57 @@ public static File extractClassesDexWithClass(String className, File apkFile) {
break;
}
}

if (zipEntry.getName().endsWith("jar") || zipEntry.getName().endsWith("zip")) {

File innerZip = File.createTempFile("inner_zip", "zip");
innerZip.deleteOnExit();

FileOutputStream fos =
new FileOutputStream(innerZip);
byte[] bytes = new byte[1024];
int length;
while ((length = zipFile.read(bytes)) >= 0) {
fos.write(bytes, 0, length);
}

fos.close();

// so far we have a zip file
ZipInputStream fromInnerZip = new ZipInputStream(new FileInputStream(
innerZip));

ZipEntry innerZipEntry;

while (true) {
innerZipEntry = fromInnerZip.getNextEntry();

if (innerZipEntry == null) {
fromInnerZip.close();
break;
}

if (innerZipEntry.getName().endsWith(".dex")) {
file = File.createTempFile("classes_innerzip", "dex");
FileOutputStream fos1 = new FileOutputStream(file);
byte[] bytes1 = new byte[1024];

while ((length = fromInnerZip.read(bytes1)) >= 0) {
fos1.write(bytes1, 0, length);
}

fos1.close();

List<String> classNamesInDex =
DexReader.readClassNamesFromDex(file);
if (classNamesInDex.contains(className)) {
fromInnerZip.close();
zipFile.close();
return file;
}
}
}
}
}
zipFile.close();
} catch (Exception e) {
Expand Down

0 comments on commit 3ce4de5

Please sign in to comment.