use of org.jf.dexlib2.analysis.ClassProto in project smali by JesusFreke.
the class ListVtablesCommand method run.
@Override
public void run() {
if (help || inputList == null || inputList.isEmpty()) {
usage();
return;
}
if (inputList.size() > 1) {
System.err.println("Too many files specified");
usage();
return;
}
String input = inputList.get(0);
loadDexFile(input);
BaksmaliOptions options = getOptions();
if (options == null) {
return;
}
try {
if (classes != null && !classes.isEmpty()) {
for (String cls : classes) {
listClassVtable((ClassProto) options.classPath.getClass(cls));
}
return;
}
for (ClassDef classDef : dexFile.getClasses()) {
if (!AccessFlags.INTERFACE.isSet(classDef.getAccessFlags())) {
listClassVtable((ClassProto) options.classPath.getClass(classDef));
}
}
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
use of org.jf.dexlib2.analysis.ClassProto in project smali by JesusFreke.
the class ListVtablesCommand method listClassVtable.
private void listClassVtable(ClassProto classProto) throws IOException {
List<Method> methods = classProto.getVtable();
String className = "Class " + classProto.getType() + " extends " + classProto.getSuperclass() + " : " + methods.size() + " methods\n";
System.out.write(className.getBytes());
for (int i = 0; i < methods.size(); i++) {
Method method = methods.get(i);
String methodString = i + ":" + method.getDefiningClass() + "->" + method.getName() + "(";
for (CharSequence parameter : method.getParameterTypes()) {
methodString += parameter;
}
methodString += ")" + method.getReturnType() + "\n";
System.out.write(methodString.getBytes());
}
System.out.write("\n".getBytes());
}
use of org.jf.dexlib2.analysis.ClassProto in project smali by JesusFreke.
the class CustomInlineMethodResolver method parseAndResolveInlineMethod.
@Nonnull
private Method parseAndResolveInlineMethod(@Nonnull String inlineMethod) {
Matcher m = longMethodPattern.matcher(inlineMethod);
if (!m.matches()) {
assert false;
throw new RuntimeException("Invalid method descriptor: " + inlineMethod);
}
String className = m.group(1);
String methodName = m.group(2);
Iterable<ImmutableMethodParameter> methodParams = ParamUtil.parseParamString(m.group(3));
String methodRet = m.group(4);
ImmutableMethodReference methodRef = new ImmutableMethodReference(className, methodName, methodParams, methodRet);
int accessFlags = 0;
boolean resolved = false;
TypeProto typeProto = classPath.getClass(className);
if (typeProto instanceof ClassProto) {
ClassDef classDef = ((ClassProto) typeProto).getClassDef();
for (Method method : classDef.getMethods()) {
if (method.equals(methodRef)) {
resolved = true;
accessFlags = method.getAccessFlags();
break;
}
}
}
if (!resolved) {
throw new RuntimeException("Cannot resolve inline method: " + inlineMethod);
}
return new ImmutableMethod(className, methodName, methodParams, methodRet, accessFlags, null, null);
}
use of org.jf.dexlib2.analysis.ClassProto in project smali by JesusFreke.
the class ListFieldOffsetsCommand method run.
@Override
public void run() {
if (help || inputList == null || inputList.isEmpty()) {
usage();
return;
}
if (inputList.size() > 1) {
System.err.println("Too many files specified");
usage();
return;
}
String input = inputList.get(0);
loadDexFile(input);
BaksmaliOptions options = getOptions();
try {
for (ClassDef classDef : dexFile.getClasses()) {
ClassProto classProto = (ClassProto) options.classPath.getClass(classDef);
SparseArray<FieldReference> fields = classProto.getInstanceFields();
String className = "Class " + classDef.getType() + " : " + fields.size() + " instance fields\n";
System.out.write(className.getBytes());
for (int i = 0; i < fields.size(); i++) {
String field = fields.keyAt(i) + ":" + fields.valueAt(i).getType() + " " + fields.valueAt(i).getName() + "\n";
System.out.write(field.getBytes());
}
System.out.write("\n".getBytes());
}
System.out.close();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
use of org.jf.dexlib2.analysis.ClassProto in project smali by JesusFreke.
the class FieldGapOrderTest method testNewOrder.
@Test
public void testNewOrder() {
DexFile dexFile = getInputDexFile("FieldGapOrder", new BaksmaliOptions());
Assert.assertEquals(3, dexFile.getClasses().size());
ClassPath classPath = new ClassPath(Lists.newArrayList(new DexClassProvider(dexFile)), false, 67);
ClassProto classProto = (ClassProto) classPath.getClass("LGapOrder;");
Assert.assertEquals("s", classProto.getFieldByOffset(10).getName());
Assert.assertEquals("r1", classProto.getFieldByOffset(12).getName());
Assert.assertEquals("r2", classProto.getFieldByOffset(16).getName());
Assert.assertEquals("i", classProto.getFieldByOffset(20).getName());
Assert.assertEquals("d", classProto.getFieldByOffset(24).getName());
}
Aggregations