use of org.jf.dexlib2.util.SyntheticAccessorResolver in project smali by JesusFreke.
the class DisassembleCommand method getOptions.
protected BaksmaliOptions getOptions() {
if (dexFile == null) {
throw new IllegalStateException("You must call loadDexFile first");
}
final BaksmaliOptions options = new BaksmaliOptions();
if (needsClassPath()) {
try {
options.classPath = analysisArguments.loadClassPathForDexFile(inputFile.getAbsoluteFile().getParentFile(), dexFile, shouldCheckPackagePrivateAccess());
} catch (Exception ex) {
System.err.println("\n\nError occurred while loading class path files. Aborting.");
ex.printStackTrace(System.err);
System.exit(-1);
}
}
if (!resourceIdFiles.isEmpty()) {
Map<String, File> resourceFiles = Maps.newHashMap();
assert (resourceIdFiles.size() % 2) == 0;
for (int i = 0; i < resourceIdFiles.size(); i += 2) {
String resourcePrefix = resourceIdFiles.get(i);
String publicXml = resourceIdFiles.get(i + 1);
File publicXmlFile = new File(publicXml);
if (!publicXmlFile.exists()) {
System.err.println(String.format("Can't find file: %s", publicXmlFile));
System.exit(-1);
}
resourceFiles.put(resourcePrefix, publicXmlFile);
}
try {
options.loadResourceIds(resourceFiles);
} catch (IOException ex) {
System.err.println("Error while loading resource files:");
ex.printStackTrace(System.err);
System.exit(-1);
} catch (SAXException ex) {
System.err.println("Error while loading resource files:");
ex.printStackTrace(System.err);
System.exit(-1);
}
}
options.parameterRegisters = parameterRegisters;
options.localsDirective = localsDirective;
options.sequentialLabels = sequentialLabels;
options.debugInfo = debugInfo;
options.codeOffsets = codeOffsets;
options.accessorComments = accessorComments;
options.implicitReferences = implicitReferences;
options.normalizeVirtualMethods = normalizeVirtualMethods;
options.registerInfo = 0;
for (String registerInfoType : registerInfoTypes) {
if (registerInfoType.equalsIgnoreCase("ALL")) {
options.registerInfo |= BaksmaliOptions.ALL;
} else if (registerInfoType.equalsIgnoreCase("ALLPRE")) {
options.registerInfo |= BaksmaliOptions.ALLPRE;
} else if (registerInfoType.equalsIgnoreCase("ALLPOST")) {
options.registerInfo |= BaksmaliOptions.ALLPOST;
} else if (registerInfoType.equalsIgnoreCase("ARGS")) {
options.registerInfo |= BaksmaliOptions.ARGS;
} else if (registerInfoType.equalsIgnoreCase("DEST")) {
options.registerInfo |= BaksmaliOptions.DEST;
} else if (registerInfoType.equalsIgnoreCase("MERGE")) {
options.registerInfo |= BaksmaliOptions.MERGE;
} else if (registerInfoType.equalsIgnoreCase("FULLMERGE")) {
options.registerInfo |= BaksmaliOptions.FULLMERGE;
} else {
System.err.println(String.format("Invalid register info type: %s", registerInfoType));
usage();
System.exit(-1);
}
if ((options.registerInfo & BaksmaliOptions.FULLMERGE) != 0) {
options.registerInfo &= ~BaksmaliOptions.MERGE;
}
}
if (accessorComments) {
options.syntheticAccessorResolver = new SyntheticAccessorResolver(dexFile.getOpcodes(), dexFile.getClasses());
}
return options;
}
use of org.jf.dexlib2.util.SyntheticAccessorResolver in project smali by JesusFreke.
the class AccessorTest method testAccessors.
@Test
public void testAccessors() throws IOException {
URL url = AccessorTest.class.getClassLoader().getResource("accessorTest.dex");
Assert.assertNotNull(url);
DexFile f = DexFileFactory.loadDexFile(url.getFile(), Opcodes.getDefault());
SyntheticAccessorResolver sar = new SyntheticAccessorResolver(f.getOpcodes(), f.getClasses());
ClassDef accessorTypesClass = null;
ClassDef accessorsClass = null;
for (ClassDef classDef : f.getClasses()) {
String className = classDef.getType();
if (className.equals("Lorg/jf/dexlib2/AccessorTypes;")) {
accessorTypesClass = classDef;
} else if (className.equals("Lorg/jf/dexlib2/AccessorTypes$Accessors;")) {
accessorsClass = classDef;
}
}
Assert.assertNotNull(accessorTypesClass);
Assert.assertNotNull(accessorsClass);
for (Method method : accessorsClass.getMethods()) {
Matcher m = accessorMethodPattern.matcher(method.getName());
if (!m.matches()) {
continue;
}
String type = m.group(1);
String operation = m.group(2);
MethodImplementation methodImpl = method.getImplementation();
Assert.assertNotNull(methodImpl);
for (Instruction instruction : methodImpl.getInstructions()) {
Opcode opcode = instruction.getOpcode();
if (opcode == Opcode.INVOKE_STATIC || opcode == Opcode.INVOKE_STATIC_RANGE) {
MethodReference accessorMethod = (MethodReference) ((ReferenceInstruction) instruction).getReference();
SyntheticAccessorResolver.AccessedMember accessedMember = sar.getAccessedMember(accessorMethod);
Assert.assertNotNull(String.format("Could not resolve accessor for %s_%s", type, operation), accessedMember);
int operationType = operationTypes.get(operation);
Assert.assertEquals(operationType, accessedMember.accessedMemberType);
Assert.assertEquals(String.format("%s_val", type), ((FieldReference) accessedMember.accessedMember).getName());
}
}
}
}
Aggregations