Search in sources :

Example 1 with ClassProto

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);
    }
}
Also used : ClassDef(org.jf.dexlib2.iface.ClassDef) IOException(java.io.IOException)

Example 2 with ClassProto

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());
}
Also used : Method(org.jf.dexlib2.iface.Method)

Example 3 with ClassProto

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);
}
Also used : ImmutableMethod(org.jf.dexlib2.immutable.ImmutableMethod) ImmutableMethodReference(org.jf.dexlib2.immutable.reference.ImmutableMethodReference) Matcher(java.util.regex.Matcher) ImmutableMethodParameter(org.jf.dexlib2.immutable.ImmutableMethodParameter) ImmutableMethod(org.jf.dexlib2.immutable.ImmutableMethod) Method(org.jf.dexlib2.iface.Method) ClassDef(org.jf.dexlib2.iface.ClassDef) Nonnull(javax.annotation.Nonnull)

Example 4 with ClassProto

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);
    }
}
Also used : ClassProto(org.jf.dexlib2.analysis.ClassProto) ClassDef(org.jf.dexlib2.iface.ClassDef) FieldReference(org.jf.dexlib2.iface.reference.FieldReference) IOException(java.io.IOException)

Example 5 with ClassProto

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());
}
Also used : ClassProto(org.jf.dexlib2.analysis.ClassProto) ClassPath(org.jf.dexlib2.analysis.ClassPath) DexClassProvider(org.jf.dexlib2.analysis.DexClassProvider) DexFile(org.jf.dexlib2.iface.DexFile) Test(org.junit.Test)

Aggregations

ClassProto (org.jf.dexlib2.analysis.ClassProto)3 ClassDef (org.jf.dexlib2.iface.ClassDef)3 IOException (java.io.IOException)2 ClassPath (org.jf.dexlib2.analysis.ClassPath)2 DexClassProvider (org.jf.dexlib2.analysis.DexClassProvider)2 DexFile (org.jf.dexlib2.iface.DexFile)2 Method (org.jf.dexlib2.iface.Method)2 Test (org.junit.Test)2 Matcher (java.util.regex.Matcher)1 Nonnull (javax.annotation.Nonnull)1 FieldReference (org.jf.dexlib2.iface.reference.FieldReference)1 ImmutableMethod (org.jf.dexlib2.immutable.ImmutableMethod)1 ImmutableMethodParameter (org.jf.dexlib2.immutable.ImmutableMethodParameter)1 ImmutableMethodReference (org.jf.dexlib2.immutable.reference.ImmutableMethodReference)1