Search in sources :

Example 11 with FieldInfo

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

the class DebugController method markNextToBeUpdated.

// when single stepping we can detect which reg need to be updated.
private void markNextToBeUpdated(long codeOffset) {
    if (codeOffset != -1) {
        Object rst = cur.smali.getResultRegOrField(cur.mthFullID, codeOffset);
        toBeUpdatedTreeNode = null;
        if (cur.frame != null) {
            if (rst instanceof Integer) {
                int regNum = (int) rst;
                if (cur.frame.getRegNodes().size() > regNum) {
                    toBeUpdatedTreeNode = cur.frame.getRegNodes().get(regNum);
                }
                return;
            }
            if (rst instanceof FieldInfo) {
                FieldInfo info = (FieldInfo) rst;
                toBeUpdatedTreeNode = cur.frame.getFieldNodes().stream().filter(f -> f.getName().equals(info.getName())).findFirst().orElse(null);
            }
        }
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) Smali(jadx.gui.device.debugger.smali.Smali) RuntimeType(jadx.gui.device.debugger.SmaliDebugger.RuntimeType) JDebuggerPanel(jadx.gui.ui.panel.JDebuggerPanel) RuntimeDebugInfo(jadx.gui.device.debugger.SmaliDebugger.RuntimeDebugInfo) RuntimeBreakpoint(jadx.gui.device.debugger.SmaliDebugger.RuntimeBreakpoint) LoggerFactory(org.slf4j.LoggerFactory) FileBreakpoint(jadx.gui.device.debugger.BreakpointManager.FileBreakpoint) HashMap(java.util.HashMap) FieldInfo(jadx.core.dex.info.FieldInfo) ArrayList(java.util.ArrayList) RuntimeField(jadx.gui.device.debugger.SmaliDebugger.RuntimeField) ClassNode(jadx.core.dex.nodes.ClassNode) RuntimeRegister(jadx.gui.device.debugger.SmaliDebugger.RuntimeRegister) Map(java.util.Map) FieldNode(jadx.core.dex.nodes.FieldNode) JClass(jadx.gui.treemodel.JClass) ExecutorService(java.util.concurrent.ExecutorService) Nullable(io.reactivex.annotations.Nullable) SmaliRegister(jadx.gui.device.debugger.smali.SmaliRegister) IDebugController(jadx.gui.ui.panel.IDebugController) Logger(org.slf4j.Logger) NonNull(io.reactivex.annotations.NonNull) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StringUtils(jadx.core.utils.StringUtils) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) RuntimeVarInfo(jadx.gui.device.debugger.SmaliDebugger.RuntimeVarInfo) IListElement(jadx.gui.ui.panel.JDebuggerPanel.IListElement) Executors(java.util.concurrent.Executors) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) RuntimeValue(jadx.gui.device.debugger.SmaliDebugger.RuntimeValue) SmaliDebuggerException(jadx.gui.device.debugger.SmaliDebugger.SmaliDebuggerException) List(java.util.List) ValueTreeNode(jadx.gui.ui.panel.JDebuggerPanel.ValueTreeNode) Entry(java.util.Map.Entry) Comparator(java.util.Comparator) Collections(java.util.Collections) Frame(jadx.gui.device.debugger.SmaliDebugger.Frame) RuntimeBreakpoint(jadx.gui.device.debugger.SmaliDebugger.RuntimeBreakpoint) FileBreakpoint(jadx.gui.device.debugger.BreakpointManager.FileBreakpoint) FieldInfo(jadx.core.dex.info.FieldInfo)

Example 12 with FieldInfo

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

the class ExtractFieldInit method filterFieldsInit.

private static void filterFieldsInit(List<FieldInitInfo> inits) {
    // exclude fields initialized several times
    Set<FieldInfo> excludedFields = inits.stream().collect(Collectors.toMap(fi -> fi.fieldNode, fi -> 1, Integer::sum)).entrySet().stream().filter(v -> v.getValue() > 1).map(v -> v.getKey().getFieldInfo()).collect(Collectors.toSet());
    for (FieldInitInfo initInfo : inits) {
        if (!checkInsn(initInfo)) {
            excludedFields.add(initInfo.fieldNode.getFieldInfo());
        }
    }
    if (!excludedFields.isEmpty()) {
        boolean changed;
        do {
            changed = false;
            for (FieldInitInfo initInfo : inits) {
                FieldInfo fieldInfo = initInfo.fieldNode.getFieldInfo();
                if (excludedFields.contains(fieldInfo)) {
                    continue;
                }
                if (insnUseExcludedField(initInfo, excludedFields)) {
                    excludedFields.add(fieldInfo);
                    changed = true;
                }
            }
        } while (changed);
    }
    // apply
    if (!excludedFields.isEmpty()) {
        inits.removeIf(fi -> excludedFields.contains(fi.fieldNode.getFieldInfo()));
    }
}
Also used : MethodNode(jadx.core.dex.nodes.MethodNode) AType(jadx.core.dex.attributes.AType) AFlag(jadx.core.dex.attributes.AFlag) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnType(jadx.core.dex.instructions.InsnType) JadxException(jadx.core.utils.exceptions.JadxException) HashMap(java.util.HashMap) FieldInfo(jadx.core.dex.info.FieldInfo) BlockUtils(jadx.core.utils.BlockUtils) AccessInfo(jadx.core.dex.info.AccessInfo) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ClassNode(jadx.core.dex.nodes.ClassNode) Map(java.util.Map) InsnNode(jadx.core.dex.nodes.InsnNode) FieldNode(jadx.core.dex.nodes.FieldNode) CodeShrinkVisitor(jadx.core.dex.visitors.shrink.CodeShrinkVisitor) InsnArg(jadx.core.dex.instructions.args.InsnArg) FieldInitInsnAttr(jadx.core.dex.attributes.FieldInitInsnAttr) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg) JadxAttrType(jadx.api.plugins.input.data.attributes.JadxAttrType) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) Set(java.util.Set) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) BlockNode(jadx.core.dex.nodes.BlockNode) InsnRemover(jadx.core.utils.InsnRemover) Collections(java.util.Collections) Utils(jadx.core.utils.Utils) FieldInfo(jadx.core.dex.info.FieldInfo)

Example 13 with FieldInfo

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

the class ExtractFieldInit method collectFieldsInit.

private static List<FieldInitInfo> collectFieldsInit(ClassNode cls, MethodNode mth, InsnType putType) {
    List<FieldInitInfo> fieldsInit = new ArrayList<>();
    Set<BlockNode> singlePathBlocks = new HashSet<>();
    BlockUtils.visitSinglePath(mth.getEnterBlock(), singlePathBlocks::add);
    for (BlockNode block : mth.getBasicBlocks()) {
        for (InsnNode insn : block.getInstructions()) {
            if (insn.getType() == putType) {
                IndexInsnNode putInsn = (IndexInsnNode) insn;
                FieldInfo field = (FieldInfo) putInsn.getIndex();
                if (field.getDeclClass().equals(cls.getClassInfo())) {
                    FieldNode fn = cls.searchField(field);
                    if (fn != null) {
                        boolean singlePath = singlePathBlocks.contains(block);
                        fieldsInit.add(new FieldInitInfo(fn, putInsn, singlePath));
                    }
                }
            }
        }
    }
    return fieldsInit;
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) FieldNode(jadx.core.dex.nodes.FieldNode) ArrayList(java.util.ArrayList) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) FieldInfo(jadx.core.dex.info.FieldInfo) HashSet(java.util.HashSet)

Example 14 with FieldInfo

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

the class InlineMethods method updateUsageInfo.

private void updateUsageInfo(MethodNode mth, MethodNode inlinedMth, InsnNode insn) {
    inlinedMth.getUseIn().remove(mth);
    insn.visitInsns(innerInsn -> {
        // TODO: share code with UsageInfoVisitor
        switch(innerInsn.getType()) {
            case INVOKE:
            case CONSTRUCTOR:
                MethodInfo callMth = ((BaseInvokeNode) innerInsn).getCallMth();
                MethodNode callMthNode = mth.root().resolveMethod(callMth);
                if (callMthNode != null) {
                    callMthNode.setUseIn(ListUtils.safeReplace(callMthNode.getUseIn(), inlinedMth, mth));
                    replaceClsUsage(mth, inlinedMth, callMthNode.getParentClass());
                }
                break;
            case IGET:
            case IPUT:
            case SPUT:
            case SGET:
                FieldInfo fieldInfo = (FieldInfo) ((IndexInsnNode) innerInsn).getIndex();
                FieldNode fieldNode = mth.root().resolveField(fieldInfo);
                if (fieldNode != null) {
                    fieldNode.setUseIn(ListUtils.safeReplace(fieldNode.getUseIn(), inlinedMth, mth));
                    replaceClsUsage(mth, inlinedMth, fieldNode.getParentClass());
                }
                break;
        }
    });
}
Also used : MethodNode(jadx.core.dex.nodes.MethodNode) FieldNode(jadx.core.dex.nodes.FieldNode) BaseInvokeNode(jadx.core.dex.instructions.BaseInvokeNode) MethodInfo(jadx.core.dex.info.MethodInfo) FieldInfo(jadx.core.dex.info.FieldInfo)

Example 15 with FieldInfo

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

the class MarkMethodsForInline method fixVisibilityOfInlineCode.

private static boolean fixVisibilityOfInlineCode(MethodNode mth, InsnNode insn) {
    // TODO: calculate more precisely
    int newVisFlag = AccessFlags.PUBLIC;
    InsnType insnType = insn.getType();
    if (insnType == InsnType.INVOKE) {
        InvokeNode invoke = (InvokeNode) insn;
        MethodNode callMthNode = mth.root().resolveMethod(invoke.getCallMth());
        if (callMthNode != null) {
            FixAccessModifiers.changeVisibility(callMthNode, newVisFlag);
        }
        return true;
    }
    if (insnType == InsnType.ONE_ARG) {
        InsnArg arg = insn.getArg(0);
        if (!arg.isInsnWrap()) {
            return false;
        }
        return fixVisibilityOfInlineCode(mth, ((InsnWrapArg) arg).getWrapInsn());
    }
    if (insn instanceof IndexInsnNode) {
        Object indexObj = ((IndexInsnNode) insn).getIndex();
        if (indexObj instanceof FieldInfo) {
            // field access must be already fixed in ModVisitor.fixFieldUsage method
            return true;
        }
    }
    if (Consts.DEBUG) {
        mth.addDebugComment("can't inline method, not implemented redirect type: " + insn);
    }
    return false;
}
Also used : MethodNode(jadx.core.dex.nodes.MethodNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) InvokeNode(jadx.core.dex.instructions.InvokeNode) InsnType(jadx.core.dex.instructions.InsnType) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) FieldInfo(jadx.core.dex.info.FieldInfo)

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