Search in sources :

Example 56 with ClassNode

use of jadx.core.dex.nodes.ClassNode in project jadx by skylot.

the class ClassModifier method removeSyntheticFields.

private static void removeSyntheticFields(ClassNode cls) {
    if (!cls.getClassInfo().isInner() || cls.getAccessFlags().isStatic()) {
        return;
    }
    // remove fields if it is synthetic and type is a outer class
    for (FieldNode field : cls.getFields()) {
        if (field.getAccessFlags().isSynthetic() && field.getType().isObject()) {
            ClassInfo clsInfo = ClassInfo.fromType(cls.dex(), field.getType());
            ClassNode fieldsCls = cls.dex().resolveClass(clsInfo);
            ClassInfo parentClass = cls.getClassInfo().getParentClass();
            if (fieldsCls != null && parentClass.equals(fieldsCls.getClassInfo()) && field.getName().startsWith("this$")) /* TODO: don't check name */
            {
                int found = 0;
                for (MethodNode mth : cls.getMethods()) {
                    if (removeFieldUsageFromConstructor(mth, field, fieldsCls)) {
                        found++;
                    }
                }
                if (found != 0) {
                    field.addAttr(new FieldReplaceAttr(parentClass));
                    field.add(AFlag.DONT_GENERATE);
                }
            }
        }
    }
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) FieldNode(jadx.core.dex.nodes.FieldNode) MethodNode(jadx.core.dex.nodes.MethodNode) FieldReplaceAttr(jadx.core.dex.attributes.nodes.FieldReplaceAttr) ClassInfo(jadx.core.dex.info.ClassInfo)

Example 57 with ClassNode

use of jadx.core.dex.nodes.ClassNode in project jadx by skylot.

the class ConstStorage method getConstField.

@Nullable
public FieldNode getConstField(ClassNode cls, Object value, boolean searchGlobal) {
    DexNode dex = cls.dex();
    if (value instanceof Integer) {
        String str = resourcesNames.get(value);
        if (str != null) {
            return new ResRefField(dex, str.replace('/', '.'));
        }
    }
    if (!replaceEnabled) {
        return null;
    }
    boolean foundInGlobal = globalValues.contains(value);
    if (foundInGlobal && !searchGlobal) {
        return null;
    }
    ClassNode current = cls;
    while (current != null) {
        Values classValues = classes.get(current);
        if (classValues != null) {
            FieldNode field = classValues.get(value);
            if (field != null) {
                if (foundInGlobal) {
                    return null;
                }
                return field;
            }
        }
        ClassInfo parentClass = current.getClassInfo().getParentClass();
        if (parentClass == null) {
            break;
        }
        current = dex.resolveClass(parentClass);
    }
    if (searchGlobal) {
        return globalValues.get(value);
    }
    return null;
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) FieldNode(jadx.core.dex.nodes.FieldNode) DexNode(jadx.core.dex.nodes.DexNode) ResRefField(jadx.core.dex.nodes.ResRefField) Nullable(org.jetbrains.annotations.Nullable)

Example 58 with ClassNode

use of jadx.core.dex.nodes.ClassNode in project jadx by skylot.

the class DeobfClsInfo method makeNameWithoutPkg.

public String makeNameWithoutPkg() {
    String prefix;
    ClassNode parentClass = cls.getParentClass();
    if (parentClass != cls) {
        DeobfClsInfo parentDeobfClsInfo = deobfuscator.getClsMap().get(parentClass.getClassInfo());
        if (parentDeobfClsInfo != null) {
            prefix = parentDeobfClsInfo.makeNameWithoutPkg();
        } else {
            prefix = deobfuscator.getNameWithoutPackage(parentClass.getClassInfo());
        }
        prefix += Deobfuscator.INNER_CLASS_SEPARATOR;
    } else {
        prefix = "";
    }
    return prefix + (this.alias != null ? this.alias : this.cls.getShortName());
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode)

Example 59 with ClassNode

use of jadx.core.dex.nodes.ClassNode in project jadx by skylot.

the class ClspGraph method addApp.

public void addApp(List<ClassNode> classes) {
    if (nameMap == null) {
        throw new JadxRuntimeException("Classpath must be loaded first");
    }
    int size = classes.size();
    NClass[] nClasses = new NClass[size];
    int k = 0;
    for (ClassNode cls : classes) {
        nClasses[k++] = addClass(cls);
    }
    for (int i = 0; i < size; i++) {
        nClasses[i].setParents(ClsSet.makeParentsArray(classes.get(i), nameMap));
    }
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Example 60 with ClassNode

use of jadx.core.dex.nodes.ClassNode in project jadx by skylot.

the class JadxDecompiler method getClasses.

public List<JavaClass> getClasses() {
    if (root == null) {
        return Collections.emptyList();
    }
    if (classes == null) {
        List<ClassNode> classNodeList = root.getClasses(false);
        List<JavaClass> clsList = new ArrayList<JavaClass>(classNodeList.size());
        classesMap.clear();
        for (ClassNode classNode : classNodeList) {
            JavaClass javaClass = new JavaClass(classNode, this);
            clsList.add(javaClass);
            classesMap.put(classNode, javaClass);
        }
        classes = Collections.unmodifiableList(clsList);
    }
    return classes;
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) ArrayList(java.util.ArrayList)

Aggregations

ClassNode (jadx.core.dex.nodes.ClassNode)236 Test (org.junit.Test)201 IntegrationTest (jadx.tests.api.IntegrationTest)197 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)93 JadxMatchers.countString (jadx.tests.api.utils.JadxMatchers.countString)17 MethodNode (jadx.core.dex.nodes.MethodNode)12 FieldNode (jadx.core.dex.nodes.FieldNode)10 Matchers.containsString (org.hamcrest.Matchers.containsString)10 ConstClassNode (jadx.core.dex.instructions.ConstClassNode)7 InsnNode (jadx.core.dex.nodes.InsnNode)7 ClassInfo (jadx.core.dex.info.ClassInfo)6 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)6 DexNode (jadx.core.dex.nodes.DexNode)5 InsnArg (jadx.core.dex.instructions.args.InsnArg)4 ConstructorInsn (jadx.core.dex.instructions.mods.ConstructorInsn)4 SmaliTest (jadx.tests.api.SmaliTest)4 ArrayList (java.util.ArrayList)4 FieldReplaceAttr (jadx.core.dex.attributes.nodes.FieldReplaceAttr)3 FieldInfo (jadx.core.dex.info.FieldInfo)3 MethodInfo (jadx.core.dex.info.MethodInfo)3