Search in sources :

Example 36 with RegisterArg

use of jadx.core.dex.instructions.args.RegisterArg 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 37 with RegisterArg

use of jadx.core.dex.instructions.args.RegisterArg in project jadx by skylot.

the class BlockProcessor method duplicateReturnInsn.

private static InsnNode duplicateReturnInsn(InsnNode returnInsn) {
    InsnNode insn = new InsnNode(returnInsn.getType(), returnInsn.getArgsCount());
    if (returnInsn.getArgsCount() == 1) {
        RegisterArg arg = (RegisterArg) returnInsn.getArg(0);
        insn.addArg(InsnArg.reg(arg.getRegNum(), arg.getType()));
    }
    insn.copyAttributesFrom(returnInsn);
    insn.setOffset(returnInsn.getOffset());
    insn.setSourceLine(returnInsn.getSourceLine());
    return insn;
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg)

Example 38 with RegisterArg

use of jadx.core.dex.instructions.args.RegisterArg in project jadx by skylot.

the class BlockProcessor method isReturnArgAssignInPred.

private static boolean isReturnArgAssignInPred(List<BlockNode> preds, InsnNode returnInsn) {
    RegisterArg arg = (RegisterArg) returnInsn.getArg(0);
    int regNum = arg.getRegNum();
    for (BlockNode pred : preds) {
        for (InsnNode insnNode : pred.getInstructions()) {
            RegisterArg result = insnNode.getResult();
            if (result != null && result.getRegNum() == regNum) {
                return true;
            }
        }
    }
    return false;
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg)

Example 39 with RegisterArg

use of jadx.core.dex.instructions.args.RegisterArg in project jadx by skylot.

the class DebugInfoVisitor method visit.

@Override
public void visit(MethodNode mth) throws JadxException {
    int debugOffset = mth.getDebugInfoOffset();
    if (debugOffset > 0) {
        InsnNode[] insnArr = mth.getInstructions();
        DebugInfoParser debugInfoParser = new DebugInfoParser(mth, debugOffset, insnArr);
        debugInfoParser.process();
        // set method source line from first instruction
        if (insnArr.length != 0) {
            for (InsnNode insn : insnArr) {
                if (insn != null) {
                    int line = insn.getSourceLine();
                    if (line != 0) {
                        mth.setSourceLine(line - 1);
                    }
                    break;
                }
            }
        }
        if (!mth.getReturnType().equals(ArgType.VOID)) {
            // fix debug info for splitter 'return' instructions
            for (BlockNode exit : mth.getExitBlocks()) {
                InsnNode ret = BlockUtils.getLastInsn(exit);
                if (ret == null) {
                    continue;
                }
                InsnNode oldRet = insnArr[ret.getOffset()];
                if (oldRet == ret) {
                    continue;
                }
                RegisterArg oldArg = (RegisterArg) oldRet.getArg(0);
                RegisterArg newArg = (RegisterArg) ret.getArg(0);
                newArg.mergeDebugInfo(oldArg.getType(), oldArg.getName());
                ret.setSourceLine(oldRet.getSourceLine());
            }
        }
    }
    mth.unloadInsnArr();
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) DebugInfoParser(jadx.core.dex.nodes.parser.DebugInfoParser)

Example 40 with RegisterArg

use of jadx.core.dex.instructions.args.RegisterArg in project jadx by skylot.

the class DependencyCollector method processInsn.

// TODO: add custom instructions processing
private static void processInsn(DexNode dex, Set<ClassNode> depList, InsnNode insnNode) {
    RegisterArg result = insnNode.getResult();
    if (result != null) {
        addDep(dex, depList, result.getType());
    }
    for (InsnArg arg : insnNode.getArguments()) {
        if (arg.isInsnWrap()) {
            processInsn(dex, depList, ((InsnWrapArg) arg).getWrapInsn());
        } else {
            addDep(dex, depList, arg.getType());
        }
    }
    processCustomInsn(dex, depList, insnNode);
}
Also used : RegisterArg(jadx.core.dex.instructions.args.RegisterArg) InsnArg(jadx.core.dex.instructions.args.InsnArg)

Aggregations

RegisterArg (jadx.core.dex.instructions.args.RegisterArg)67 InsnNode (jadx.core.dex.nodes.InsnNode)39 InsnArg (jadx.core.dex.instructions.args.InsnArg)24 SSAVar (jadx.core.dex.instructions.args.SSAVar)22 BlockNode (jadx.core.dex.nodes.BlockNode)17 PhiInsn (jadx.core.dex.instructions.PhiInsn)11 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)10 ArgType (jadx.core.dex.instructions.args.ArgType)8 ArrayList (java.util.ArrayList)8 PhiListAttr (jadx.core.dex.attributes.nodes.PhiListAttr)6 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)6 MethodNode (jadx.core.dex.nodes.MethodNode)4 MethodInfo (jadx.core.dex.info.MethodInfo)3 ConstClassNode (jadx.core.dex.instructions.ConstClassNode)3 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)3 ConstructorInsn (jadx.core.dex.instructions.mods.ConstructorInsn)3 ClassNode (jadx.core.dex.nodes.ClassNode)3 FieldNode (jadx.core.dex.nodes.FieldNode)3 IContainer (jadx.core.dex.nodes.IContainer)3 ExceptionHandler (jadx.core.dex.trycatch.ExceptionHandler)3