diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/InstructionMethodItemFactory.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/InstructionMethodItemFactory.java index c1f2665a..429cb692 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/InstructionMethodItemFactory.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/InstructionMethodItemFactory.java @@ -29,6 +29,7 @@ package org.jf.baksmali.Adaptors.Format; import org.jf.baksmali.Adaptors.MethodDefinition; +import org.jf.dexlib2.analysis.UnresolvedOdexInstruction; import org.jf.dexlib2.iface.instruction.Instruction; import org.jf.dexlib2.iface.instruction.OffsetInstruction; import org.jf.dexlib2.iface.instruction.formats.ArrayPayload; @@ -47,6 +48,11 @@ public class InstructionMethodItemFactory { (OffsetInstruction)instruction); } + if (instruction instanceof UnresolvedOdexInstruction) { + return new UnresolvedOdexInstructionMethodItem(methodDef, codeAddress, + (UnresolvedOdexInstruction)instruction); + } + switch (instruction.getOpcode().format) { case ArrayPayload: return new ArrayDataMethodItem(methodDef, codeAddress, (ArrayPayload)instruction); @@ -54,10 +60,6 @@ public class InstructionMethodItemFactory { return new PackedSwitchMethodItem(methodDef, codeAddress, (PackedSwitchPayload)instruction); case SparseSwitchPayload: return new SparseSwitchMethodItem(methodDef, codeAddress, (SparseSwitchPayload)instruction); - //TODO: uncomment - /*case UnresolvedOdexInstruction: - return new UnresolvedOdexInstructionMethodItem(codeItem, codeAddress, - (UnresolvedOdexInstruction)instruction);*/ default: return new InstructionMethodItem(methodDef, codeAddress, instruction); } diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/UnresolvedOdexInstructionMethodItem.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/UnresolvedOdexInstructionMethodItem.java index ad805880..a7768817 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/UnresolvedOdexInstructionMethodItem.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/Format/UnresolvedOdexInstructionMethodItem.java @@ -28,10 +28,17 @@ package org.jf.baksmali.Adaptors.Format; -//TODO: uncomment -/*public class UnresolvedOdexInstructionMethodItem extends InstructionMethodItem { - public UnresolvedOdexInstructionMethodItem(CodeItem codeItem, int codeAddress, UnresolvedOdexInstruction instruction) { - super(codeItem, codeAddress, instruction); +import org.jf.baksmali.Adaptors.MethodDefinition; +import org.jf.dexlib2.analysis.UnresolvedOdexInstruction; +import org.jf.util.IndentingWriter; + +import javax.annotation.Nonnull; +import java.io.IOException; + +public class UnresolvedOdexInstructionMethodItem extends InstructionMethodItem { + public UnresolvedOdexInstructionMethodItem(@Nonnull MethodDefinition methodDef, int codeAddress, + @Nonnull UnresolvedOdexInstruction instruction) { + super(methodDef, codeAddress, instruction); } public boolean writeTo(IndentingWriter writer) throws IOException { @@ -42,6 +49,6 @@ package org.jf.baksmali.Adaptors.Format; private void writeThrowTo(IndentingWriter writer) throws IOException { writer.write("#Replaced unresolvable odex instruction with a throw\n"); writer.write("throw "); - writeRegister(writer, instruction.ObjectRegisterNum); + writeRegister(writer, instruction.objectRegisterNum); } -}*/ +} diff --git a/baksmali/src/main/java/org/jf/baksmali/Adaptors/MethodDefinition.java b/baksmali/src/main/java/org/jf/baksmali/Adaptors/MethodDefinition.java index a09c8671..4fb1f871 100644 --- a/baksmali/src/main/java/org/jf/baksmali/Adaptors/MethodDefinition.java +++ b/baksmali/src/main/java/org/jf/baksmali/Adaptors/MethodDefinition.java @@ -359,9 +359,11 @@ public class MethodDefinition { AnalysisException analysisException = methodAnalyzer.getAnalysisException(); if (analysisException != null) { + // TODO: need to keep track of whether any errors occurred, so we can exit with a non-zero result methodItems.add(new CommentMethodItem( - String.format("AnalysisException: %s" ,analysisException.getMessage()), + String.format("AnalysisException: %s", analysisException.getMessage()), analysisException.codeAddress, Integer.MIN_VALUE)); + analysisException.printStackTrace(System.err); } List instructions = methodAnalyzer.getAnalyzedInstructions(); diff --git a/baksmali/src/main/java/org/jf/baksmali/baksmali.java b/baksmali/src/main/java/org/jf/baksmali/baksmali.java index cc4a0ab6..dbc26485 100644 --- a/baksmali/src/main/java/org/jf/baksmali/baksmali.java +++ b/baksmali/src/main/java/org/jf/baksmali/baksmali.java @@ -33,6 +33,7 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.Iterables; import org.jf.baksmali.Adaptors.ClassDefinition; import org.jf.dexlib2.analysis.ClassPath; +import org.jf.dexlib2.dexbacked.DexBackedOdexFile; import org.jf.dexlib2.iface.ClassDef; import org.jf.dexlib2.iface.DexFile; import org.jf.dexlib2.util.SyntheticAccessorResolver; @@ -77,6 +78,10 @@ public class baksmali { Iterable bootClassPaths = null; if (bootClassPath != null) { bootClassPaths = Splitter.on(':').split(bootClassPath); + } else if (dexFile instanceof DexBackedOdexFile) { + bootClassPaths = ((DexBackedOdexFile)dexFile).getDependencies(); + }else { + bootClassPaths = ImmutableList.of(); } options.classPath = ClassPath.fromClassPath(Arrays.asList(classPathDirs), diff --git a/baksmali/src/main/java/org/jf/baksmali/main.java b/baksmali/src/main/java/org/jf/baksmali/main.java index beb7debb..eb278193 100644 --- a/baksmali/src/main/java/org/jf/baksmali/main.java +++ b/baksmali/src/main/java/org/jf/baksmali/main.java @@ -248,26 +248,19 @@ public class main { //TODO: add "fix registers" functionality? DexBackedDexFile dexFile = DexFileFactory.loadDexFile(dexFileFile); - //TODO: uncomment - /*if (dexFile.isOdex()) { - if (doDump) { - System.err.println("-D cannot be used with on odex file. Ignoring -D"); - } - if (write) { - System.err.println("-W cannot be used with an odex file. Ignoring -W"); - } + if (dexFile.isOdexFile()) { if (!deodex) { System.err.println("Warning: You are disassembling an odex file without deodexing it. You"); System.err.println("won't be able to re-assemble the results unless you deodex it with the -x"); System.err.println("option"); } - } else {*/ + } else { deodex = false; if (bootClassPath == null) { bootClassPath = "core.jar:ext.jar:framework.jar:android.policy.jar:services.jar"; } - //} + } if (disassemble) { String[] bootClassPathDirsArray = new String[bootClassPathDirs.size()]; @@ -281,12 +274,8 @@ public class main { noAccessorComments, registerInfo, ignoreErrors, inlineTable, checkPackagePrivateAccess); } - // TODO: implement rewrite + optional sort functionality - - // TODO: need to check if odex file if (doDump) { - try - { + try { dump.dump(dexFile, dumpFileName); }catch (IOException ex) { System.err.println("Error occured while writing dump file");