Search in sources :

Example 46 with InsnNode

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

the class ModVisitor method removeStep.

/**
	 * Remove unnecessary instructions
	 */
private static void removeStep(MethodNode mth, InstructionRemover remover) {
    for (BlockNode block : mth.getBasicBlocks()) {
        remover.setBlock(block);
        for (InsnNode insn : block.getInstructions()) {
            switch(insn.getType()) {
                case NOP:
                case GOTO:
                case NEW_INSTANCE:
                    remover.add(insn);
                    break;
                default:
                    break;
            }
        }
        remover.perform();
    }
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode)

Example 47 with InsnNode

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

the class ModVisitor method getParentInsnSkipMove.

private static InsnNode getParentInsnSkipMove(RegisterArg arg) {
    SSAVar sVar = arg.getSVar();
    if (sVar.getUseCount() != 1) {
        return null;
    }
    RegisterArg useArg = sVar.getUseList().get(0);
    InsnNode parentInsn = useArg.getParentInsn();
    if (parentInsn == null) {
        return null;
    }
    if (parentInsn.getType() == InsnType.MOVE) {
        return getParentInsnSkipMove(parentInsn.getResult());
    }
    return parentInsn;
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) SSAVar(jadx.core.dex.instructions.args.SSAVar)

Example 48 with InsnNode

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

the class PrepareForCodeGen method checkInsn.

/**
	 * Remove parenthesis for wrapped insn  in arith '+' or '-'
	 * ('(a + b) +c' => 'a + b + c')
	 */
private static void checkInsn(InsnNode insn) {
    if (insn.getType() == InsnType.ARITH) {
        ArithNode arith = (ArithNode) insn;
        ArithOp op = arith.getOp();
        if (op == ArithOp.ADD || op == ArithOp.SUB) {
            for (int i = 0; i < 2; i++) {
                InsnArg arg = arith.getArg(i);
                if (arg.isInsnWrap()) {
                    InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
                    wrapInsn.add(AFlag.DONT_WRAP);
                    checkInsn(wrapInsn);
                }
            }
        }
    } else {
        for (InsnArg arg : insn.getArguments()) {
            if (arg.isInsnWrap()) {
                InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
                checkInsn(wrapInsn);
            }
        }
    }
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) ArithOp(jadx.core.dex.instructions.ArithOp) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg) ArithNode(jadx.core.dex.instructions.ArithNode)

Example 49 with InsnNode

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

the class PrepareForCodeGen method modifyArith.

/**
	 * Replace arithmetic operation with short form
	 * ('a = a + 2' => 'a += 2')
	 */
private static void modifyArith(BlockNode block) {
    List<InsnNode> list = block.getInstructions();
    for (InsnNode insn : list) {
        if (insn.getType() == InsnType.ARITH) {
            RegisterArg res = insn.getResult();
            InsnArg arg = insn.getArg(0);
            boolean replace = false;
            if (res.equals(arg)) {
                replace = true;
            } else if (arg.isRegister()) {
                RegisterArg regArg = (RegisterArg) arg;
                replace = res.equalRegisterAndType(regArg);
            }
            if (replace) {
                insn.add(AFlag.ARITH_ONEARG);
            }
        }
    }
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) InsnArg(jadx.core.dex.instructions.args.InsnArg)

Example 50 with InsnNode

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

the class PrepareForCodeGen method checkInline.

private static void checkInline(BlockNode block) {
    List<InsnNode> list = block.getInstructions();
    for (int i = 0; i < list.size(); i++) {
        InsnNode insn = list.get(i);
        // replace 'move' with inner wrapped instruction
        if (insn.getType() == InsnType.MOVE && insn.getArg(0).isInsnWrap()) {
            InsnNode wrapInsn = ((InsnWrapArg) insn.getArg(0)).getWrapInsn();
            wrapInsn.setResult(insn.getResult());
            wrapInsn.copyAttributesFrom(insn);
            list.set(i, wrapInsn);
        }
    }
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) InsnWrapArg(jadx.core.dex.instructions.args.InsnWrapArg)

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