Re-enable deodexing in baksmali

It's not quite working yet.
This commit is contained in:
Ben Gruver 2013-04-09 23:45:48 -07:00
parent fd258ad543
commit a55990c876
5 changed files with 31 additions and 26 deletions

View File

@ -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<Instruction>(methodDef, codeAddress, instruction);
}

View File

@ -28,10 +28,17 @@
package org.jf.baksmali.Adaptors.Format;
//TODO: uncomment
/*public class UnresolvedOdexInstructionMethodItem extends InstructionMethodItem<UnresolvedOdexInstruction> {
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<UnresolvedOdexInstruction> {
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);
}
}
}*/

View File

@ -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()),
analysisException.codeAddress, Integer.MIN_VALUE));
analysisException.printStackTrace(System.err);
}
List<AnalyzedInstruction> instructions = methodAnalyzer.getAnalyzedInstructions();

View File

@ -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<String> 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),

View File

@ -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");