Search in sources :

Example 81 with InsnNode

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

the class ExtractFieldInit method compareInsns.

private static boolean compareInsns(List<InsnNode> base, List<InsnNode> other) {
    if (base.size() != other.size()) {
        return false;
    }
    int count = base.size();
    for (int i = 0; i < count; i++) {
        InsnNode baseInsn = base.get(i);
        InsnNode otherInsn = other.get(i);
        if (!baseInsn.isSame(otherInsn)) {
            return false;
        }
    }
    return true;
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode)

Example 82 with InsnNode

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

the class ExtractFieldInit method moveStaticFieldsInit.

private static void moveStaticFieldsInit(ClassNode cls) {
    MethodNode classInitMth = cls.getClassInitMth();
    if (classInitMth == null) {
        return;
    }
    for (FieldNode field : cls.getFields()) {
        if (field.contains(AFlag.DONT_GENERATE)) {
            continue;
        }
        if (field.getAccessFlags().isStatic()) {
            List<InsnNode> initInsns = getFieldAssigns(classInitMth, field, InsnType.SPUT);
            if (initInsns.size() == 1) {
                InsnNode insn = initInsns.get(0);
                if (checkInsn(insn)) {
                    InstructionRemover.remove(classInitMth, insn);
                    addFieldInitAttr(classInitMth, field, insn);
                }
            }
        }
    }
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) MethodNode(jadx.core.dex.nodes.MethodNode) FieldNode(jadx.core.dex.nodes.FieldNode)

Example 83 with InsnNode

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

the class MethodInlineVisitor method inlineMth.

private static void inlineMth(MethodNode mth, BlockNode firstBlock, BlockNode returnBlock) {
    List<InsnNode> insnList = firstBlock.getInstructions();
    if (insnList.isEmpty()) {
        // synthetic field getter
        BlockNode block = mth.getBasicBlocks().get(1);
        InsnNode insn = block.getInstructions().get(0);
        // set arg from 'return' instruction
        addInlineAttr(mth, InsnNode.wrapArg(insn.getArg(0)));
        return;
    }
    // synthetic field setter or method invoke
    if (insnList.size() == 1) {
        addInlineAttr(mth, insnList.get(0));
        return;
    }
    // other field operations
    if (insnList.size() == 2 && returnBlock.getInstructions().size() == 1 && !mth.getReturnType().equals(ArgType.VOID)) {
        InsnNode get = insnList.get(0);
        InsnNode put = insnList.get(1);
        InsnArg retArg = returnBlock.getInstructions().get(0).getArg(0);
        if (get.getType() == InsnType.IGET && put.getType() == InsnType.IPUT && retArg.isRegister() && get.getResult().equalRegisterAndType((RegisterArg) retArg)) {
            RegisterArg retReg = (RegisterArg) retArg;
            retReg.getSVar().removeUse(retReg);
            CodeShrinker.shrinkMethod(mth);
            insnList = firstBlock.getInstructions();
            if (insnList.size() == 1) {
                addInlineAttr(mth, insnList.get(0));
            }
        }
    }
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) InsnArg(jadx.core.dex.instructions.args.InsnArg)

Example 84 with InsnNode

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

the class LoopRegion method checkPreCondition.

/**
	 * Check if pre-conditions can be inlined into loop condition
	 */
public boolean checkPreCondition() {
    List<InsnNode> insns = preCondition.getInstructions();
    if (insns.isEmpty()) {
        return true;
    }
    IfNode ifInsn = getIfInsn();
    int size = insns.size();
    for (int i = 0; i < size; i++) {
        InsnNode insn = insns.get(i);
        if (insn.getResult() == null) {
            return false;
        }
        RegisterArg res = insn.getResult();
        if (res.getSVar().getUseCount() > 1) {
            return false;
        }
        boolean found = false;
        // search result arg in other insns
        for (int j = i + 1; j < size; j++) {
            if (insns.get(i).containsArg(res)) {
                found = true;
            }
        }
        // or in if insn
        if (!found && ifInsn.containsArg(res)) {
            found = true;
        }
        if (!found) {
            return false;
        }
    }
    return true;
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) IfNode(jadx.core.dex.instructions.IfNode)

Example 85 with InsnNode

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

the class TryCatchBlock method merge.

public boolean merge(MethodNode mth, TryCatchBlock tryBlock) {
    if (tryBlock == this) {
        return false;
    }
    for (InsnNode insn : tryBlock.getInsns()) {
        this.addInsn(insn);
    }
    this.handlers.addAll(tryBlock.handlers);
    for (ExceptionHandler eh : handlers) {
        eh.setTryBlock(this);
    }
    // clear
    tryBlock.handlers.clear();
    tryBlock.removeWholeBlock(mth);
    return true;
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode)

Aggregations

InsnNode (jadx.core.dex.nodes.InsnNode)123 BlockNode (jadx.core.dex.nodes.BlockNode)41 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)39 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)35 InsnArg (jadx.core.dex.instructions.args.InsnArg)32 InsnWrapArg (jadx.core.dex.instructions.args.InsnWrapArg)19 SSAVar (jadx.core.dex.instructions.args.SSAVar)16 ArrayList (java.util.ArrayList)14 ArgType (jadx.core.dex.instructions.args.ArgType)11 PhiInsn (jadx.core.dex.instructions.PhiInsn)10 FieldNode (jadx.core.dex.nodes.FieldNode)10 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)8 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)7 ClassNode (jadx.core.dex.nodes.ClassNode)7 MethodNode (jadx.core.dex.nodes.MethodNode)7 FieldInfo (jadx.core.dex.info.FieldInfo)6 ArithNode (jadx.core.dex.instructions.ArithNode)6 ConstructorInsn (jadx.core.dex.instructions.mods.ConstructorInsn)6 InsnType (jadx.core.dex.instructions.InsnType)5 IContainer (jadx.core.dex.nodes.IContainer)5