Implement dex entry for non classes.dex files

Conflicts:
	brut.apktool.smali/dexlib2/src/main/java/org/jf/dexlib2/DexFileFactory.java
This commit is contained in:
Connor Tumbleson 2014-09-13 11:50:19 -05:00
parent 6b6c2c09b6
commit 89e6b06521
3 changed files with 16 additions and 5 deletions

View File

@ -56,6 +56,7 @@ public class baksmaliOptions {
public int apiLevel = 15; public int apiLevel = 15;
public String outputDirectory = "out"; public String outputDirectory = "out";
public String dexEntry = "classes.dex";
public List<String> bootClassPathDirs = Lists.newArrayList(); public List<String> bootClassPathDirs = Lists.newArrayList();
public List<String> bootClassPathEntries = Lists.newArrayList(); public List<String> bootClassPathEntries = Lists.newArrayList();

View File

@ -208,6 +208,9 @@ public class main {
case 't': case 't':
options.useImplicitReferences = false; options.useImplicitReferences = false;
break; break;
case 'e':
options.dexEntry = commandLine.getOptionValue("e");
break;
case 'N': case 'N':
disassemble = false; disassemble = false;
break; break;
@ -251,7 +254,7 @@ public class main {
} }
//Read in and parse the dex file //Read in and parse the dex file
DexBackedDexFile dexFile = DexFileFactory.loadDexFile(dexFileFile, options.apiLevel); DexBackedDexFile dexFile = DexFileFactory.loadDexFile(dexFileFile, options.dexEntry, options.apiLevel);
if (dexFile.isOdexFile()) { if (dexFile.isOdexFile()) {
if (!options.deodex) { if (!options.deodex) {
@ -450,6 +453,12 @@ public class main {
.withArgName("FILE") .withArgName("FILE")
.create("T"); .create("T");
Option dexEntryOption = OptionBuilder.withLongOpt("dex-file")
.withDescription("looks for dex file named DEX_FILE, defaults to classes.dex")
.withArgName("DEX_FILE")
.hasArg()
.create("e");
basicOptions.addOption(versionOption); basicOptions.addOption(versionOption);
basicOptions.addOption(helpOption); basicOptions.addOption(helpOption);
basicOptions.addOption(outputDirOption); basicOptions.addOption(outputDirOption);
@ -467,6 +476,7 @@ public class main {
basicOptions.addOption(jobsOption); basicOptions.addOption(jobsOption);
basicOptions.addOption(resourceIdFilesOption); basicOptions.addOption(resourceIdFilesOption);
basicOptions.addOption(noImplicitReferencesOption); basicOptions.addOption(noImplicitReferencesOption);
basicOptions.addOption(dexEntryOption);
debugOptions.addOption(dumpOption); debugOptions.addOption(dumpOption);
debugOptions.addOption(ignoreErrorsOption); debugOptions.addOption(ignoreErrorsOption);

View File

@ -60,7 +60,7 @@ public final class DexFileFactory {
} }
@Nonnull @Nonnull
public static DexBackedDexFile loadDexFile(File dexFile, String filename, @Nonnull Opcodes opcodes) throws IOException { public static DexBackedDexFile loadDexFile(File dexFile, String dexEntry, @Nonnull Opcodes opcodes) throws IOException {
ZipFile zipFile = null; ZipFile zipFile = null;
boolean isZipFile = false; boolean isZipFile = false;
try { try {
@ -68,16 +68,16 @@ public final class DexFileFactory {
// if we get here, it's safe to assume we have a zip file // if we get here, it's safe to assume we have a zip file
isZipFile = true; isZipFile = true;
ZipEntry zipEntry = zipFile.getEntry(filename); ZipEntry zipEntry = zipFile.getEntry(dexEntry);
if (zipEntry == null) { if (zipEntry == null) {
throw new NoClassesDexException("zip file %s does not contain a classes.dex file", dexFile.getName()); throw new NoClassesDexException("zip file %s does not contain a classes.dex file", dexFile.getName());
} }
long fileLength = zipEntry.getSize(); long fileLength = zipEntry.getSize();
if (fileLength < 40) { if (fileLength < 40) {
throw new ExceptionWithContext( throw new ExceptionWithContext(
"The " + filename + " file in %s is too small to be a valid dex file", dexFile.getName()); "The " + dexEntry + " file in %s is too small to be a valid dex file", dexFile.getName());
} else if (fileLength > Integer.MAX_VALUE) { } else if (fileLength > Integer.MAX_VALUE) {
throw new ExceptionWithContext("The " + filename + " file in %s is too large to read in", dexFile.getName()); throw new ExceptionWithContext("The " + dexEntry + " file in %s is too large to read in", dexFile.getName());
} }
byte[] dexBytes = new byte[(int)fileLength]; byte[] dexBytes = new byte[(int)fileLength];
ByteStreams.readFully(zipFile.getInputStream(zipEntry), dexBytes); ByteStreams.readFully(zipFile.getInputStream(zipEntry), dexBytes);