Search in sources :

Example 6 with FieldInfo

use of jadx.core.dex.info.FieldInfo in project jadx by skylot.

the class FieldNode method build.

public static FieldNode build(ClassNode cls, IFieldData fieldData) {
    FieldInfo fieldInfo = FieldInfo.fromRef(cls.root(), fieldData);
    FieldNode fieldNode = new FieldNode(cls, fieldInfo, fieldData.getAccessFlags());
    fieldNode.addAttrs(fieldData.getAttributes());
    return fieldNode;
}
Also used : FieldInfo(jadx.core.dex.info.FieldInfo)

Example 7 with FieldInfo

use of jadx.core.dex.info.FieldInfo in project jadx by skylot.

the class Deobfuscator method getFieldAlias.

@Nullable
private String getFieldAlias(FieldNode field) {
    FieldInfo fieldInfo = field.getFieldInfo();
    String alias = fldMap.get(fieldInfo);
    if (alias != null) {
        return alias;
    }
    alias = deobfPresets.getForFld(fieldInfo);
    if (alias != null) {
        fldMap.put(fieldInfo, alias);
        return alias;
    }
    if (shouldRename(field.getName())) {
        return makeFieldAlias(field);
    }
    return null;
}
Also used : FieldInfo(jadx.core.dex.info.FieldInfo) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with FieldInfo

use of jadx.core.dex.info.FieldInfo in project jadx by skylot.

the class Deobfuscator method renameField.

private void renameField(FieldNode field) {
    FieldInfo fieldInfo = field.getFieldInfo();
    String alias = getFieldAlias(field);
    if (alias != null) {
        fieldInfo.setAlias(alias);
    }
}
Also used : FieldInfo(jadx.core.dex.info.FieldInfo)

Example 9 with FieldInfo

use of jadx.core.dex.info.FieldInfo in project jadx by skylot.

the class AndroidResourcesUtils method addResourceFields.

private static void addResourceFields(ClassNode resCls, ResourceStorage resStorage, boolean rClsExists) {
    Map<Integer, FieldNode> resFieldsMap = fillResFieldsMap(resCls);
    Map<String, ResClsInfo> innerClsMap = new TreeMap<>();
    if (rClsExists) {
        for (ClassNode innerClass : resCls.getInnerClasses()) {
            ResClsInfo innerResCls = new ResClsInfo(innerClass);
            innerClass.getFields().forEach(field -> innerResCls.getFieldsMap().put(field.getName(), field));
            innerClsMap.put(innerClass.getShortName(), innerResCls);
        }
    }
    for (ResourceEntry resource : resStorage.getResources()) {
        String resTypeName = resource.getTypeName();
        String resName = resTypeName.equals("style") ? resource.getKeyName().replace('.', '_') : resource.getKeyName();
        ResClsInfo typeClsInfo = innerClsMap.computeIfAbsent(resTypeName, name -> getClassForResType(resCls, rClsExists, name));
        typeClsInfo.getFieldsMap().computeIfAbsent(resName, name -> {
            ClassNode typeCls = typeClsInfo.getTypeCls();
            FieldInfo rFieldInfo = FieldInfo.from(typeCls.root(), typeCls.getClassInfo(), resName, ArgType.INT);
            FieldNode newResField = new FieldNode(typeCls, rFieldInfo, AccessFlags.PUBLIC | AccessFlags.STATIC | AccessFlags.FINAL);
            newResField.addAttr(new EncodedValue(EncodedType.ENCODED_INT, resource.getId()));
            typeCls.getFields().add(newResField);
            if (rClsExists) {
                newResField.addInfoComment("Added by JADX");
            }
            return newResField;
        });
        FieldNode fieldNode = resFieldsMap.get(resource.getId());
        if (fieldNode != null && !fieldNode.getName().equals(resName) && NameMapper.isValidAndPrintable(resName) && resCls.root().getArgs().isRenameValid()) {
            fieldNode.add(AFlag.DONT_RENAME);
            fieldNode.getFieldInfo().setAlias(resName);
        }
    }
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) EncodedValue(jadx.api.plugins.input.data.annotations.EncodedValue) FieldNode(jadx.core.dex.nodes.FieldNode) ResourceEntry(jadx.core.xmlgen.entry.ResourceEntry) TreeMap(java.util.TreeMap) FieldInfo(jadx.core.dex.info.FieldInfo)

Example 10 with FieldInfo

use of jadx.core.dex.info.FieldInfo in project jadx by skylot.

the class InsnUtils method getConstValueByInsn.

/**
 * Return constant value from insn or null if not constant.
 *
 * @return LiteralArg, String, ArgType or null
 */
@Nullable
public static Object getConstValueByInsn(RootNode root, InsnNode insn) {
    switch(insn.getType()) {
        case CONST:
            return insn.getArg(0);
        case CONST_STR:
            return ((ConstStringNode) insn).getString();
        case CONST_CLASS:
            return ((ConstClassNode) insn).getClsType();
        case SGET:
            FieldInfo f = (FieldInfo) ((IndexInsnNode) insn).getIndex();
            FieldNode fieldNode = root.resolveField(f);
            if (fieldNode == null) {
                LOG.warn("Field {} not found", f);
                return null;
            }
            EncodedValue constVal = fieldNode.get(JadxAttrType.CONSTANT_VALUE);
            if (constVal != null) {
                return EncodedValueUtils.convertToConstValue(constVal);
            }
            return null;
        default:
            return null;
    }
}
Also used : EncodedValue(jadx.api.plugins.input.data.annotations.EncodedValue) FieldNode(jadx.core.dex.nodes.FieldNode) ConstStringNode(jadx.core.dex.instructions.ConstStringNode) ConstClassNode(jadx.core.dex.instructions.ConstClassNode) FieldInfo(jadx.core.dex.info.FieldInfo) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

FieldInfo (jadx.core.dex.info.FieldInfo)41 FieldNode (jadx.core.dex.nodes.FieldNode)24 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)20 InsnNode (jadx.core.dex.nodes.InsnNode)16 InsnArg (jadx.core.dex.instructions.args.InsnArg)15 InsnWrapArg (jadx.core.dex.instructions.args.InsnWrapArg)8 ClassNode (jadx.core.dex.nodes.ClassNode)8 ArgType (jadx.core.dex.instructions.args.ArgType)7 ArrayList (java.util.ArrayList)7 InsnType (jadx.core.dex.instructions.InsnType)6 MethodNode (jadx.core.dex.nodes.MethodNode)6 Nullable (org.jetbrains.annotations.Nullable)6 ConstClassNode (jadx.core.dex.instructions.ConstClassNode)5 ConstStringNode (jadx.core.dex.instructions.ConstStringNode)5 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)5 BlockNode (jadx.core.dex.nodes.BlockNode)5 HashMap (java.util.HashMap)5 List (java.util.List)5 EncodedValue (jadx.api.plugins.input.data.annotations.EncodedValue)4 MethodInfo (jadx.core.dex.info.MethodInfo)4