Search in sources :

Example 11 with InsnNode

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

the class DebugUtils method printInsns.

private static void printInsns(MethodNode mth, String indent, IBlock block) {
    for (InsnNode insn : block.getInstructions()) {
        try {
            MethodGen mg = MethodGen.getFallbackMethodGen(mth);
            InsnGen ig = new InsnGen(mg, true);
            CodeWriter code = new CodeWriter();
            ig.makeInsn(insn, code);
            String insnStr = code.toString().substring(CodeWriter.NL.length());
            LOG.debug("{} - {}", indent, insnStr);
        } catch (CodegenException e) {
            LOG.debug("{} - {}", indent, insn);
        }
    }
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) InsnGen(jadx.core.codegen.InsnGen) CodegenException(jadx.core.utils.exceptions.CodegenException) CodeWriter(jadx.core.codegen.CodeWriter) MethodGen(jadx.core.codegen.MethodGen)

Example 12 with InsnNode

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

the class InstructionRemover method remove.

public static void remove(MethodNode mth, BlockNode block, InsnNode insn) {
    unbindInsn(mth, insn);
    // remove by pointer (don't use equals)
    Iterator<InsnNode> it = block.getInstructions().iterator();
    while (it.hasNext()) {
        InsnNode ir = it.next();
        if (ir == insn) {
            it.remove();
            return;
        }
    }
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode)

Example 13 with InsnNode

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

the class RegionUtils method hasExitEdge.

public static boolean hasExitEdge(IContainer container) {
    if (container instanceof IBlock) {
        InsnNode lastInsn = BlockUtils.getLastInsn((IBlock) container);
        if (lastInsn == null) {
            return false;
        }
        InsnType type = lastInsn.getType();
        return type == InsnType.RETURN || type == InsnType.CONTINUE || type == InsnType.BREAK || type == InsnType.THROW;
    } else if (container instanceof IBranchRegion) {
        for (IContainer br : ((IBranchRegion) container).getBranches()) {
            if (br == null || !hasExitEdge(br)) {
                return false;
            }
        }
        return true;
    } else if (container instanceof IRegion) {
        IRegion region = (IRegion) container;
        List<IContainer> blocks = region.getSubBlocks();
        return !blocks.isEmpty() && hasExitEdge(blocks.get(blocks.size() - 1));
    } else {
        throw new JadxRuntimeException(unknownContainerType(container));
    }
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) IBlock(jadx.core.dex.nodes.IBlock) IBranchRegion(jadx.core.dex.nodes.IBranchRegion) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) InsnType(jadx.core.dex.instructions.InsnType) IContainer(jadx.core.dex.nodes.IContainer) IRegion(jadx.core.dex.nodes.IRegion)

Example 14 with InsnNode

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

the class SSATransform method removeBlockerInsns.

private static boolean removeBlockerInsns(MethodNode mth) {
    boolean removed = false;
    for (BlockNode block : mth.getBasicBlocks()) {
        PhiListAttr phiList = block.get(AType.PHI_LIST);
        if (phiList == null) {
            continue;
        }
        // check if args must be removed
        for (PhiInsn phi : phiList.getList()) {
            for (int i = 0; i < phi.getArgsCount(); i++) {
                RegisterArg arg = phi.getArg(i);
                InsnNode parentInsn = arg.getAssignInsn();
                if (parentInsn != null && parentInsn.contains(AFlag.REMOVE)) {
                    phi.removeArg(arg);
                    InstructionRemover.remove(mth, block, parentInsn);
                    removed = true;
                }
            }
        }
    }
    return removed;
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) PhiInsn(jadx.core.dex.instructions.PhiInsn) PhiListAttr(jadx.core.dex.attributes.nodes.PhiListAttr)

Example 15 with InsnNode

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

the class SSATransform method fixUselessPhi.

private static boolean fixUselessPhi(MethodNode mth) {
    boolean changed = false;
    List<PhiInsn> insnToRemove = new ArrayList<PhiInsn>();
    for (SSAVar var : mth.getSVars()) {
        // phi result not used
        if (var.getUseCount() == 0) {
            InsnNode assignInsn = var.getAssign().getParentInsn();
            if (assignInsn != null && assignInsn.getType() == InsnType.PHI) {
                insnToRemove.add((PhiInsn) assignInsn);
                changed = true;
            }
        }
    }
    for (BlockNode block : mth.getBasicBlocks()) {
        PhiListAttr phiList = block.get(AType.PHI_LIST);
        if (phiList == null) {
            continue;
        }
        Iterator<PhiInsn> it = phiList.getList().iterator();
        while (it.hasNext()) {
            PhiInsn phi = it.next();
            if (fixPhiWithSameArgs(mth, block, phi)) {
                it.remove();
                changed = true;
            }
        }
    }
    removePhiList(mth, insnToRemove);
    return changed;
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) InsnNode(jadx.core.dex.nodes.InsnNode) PhiInsn(jadx.core.dex.instructions.PhiInsn) SSAVar(jadx.core.dex.instructions.args.SSAVar) PhiListAttr(jadx.core.dex.attributes.nodes.PhiListAttr) ArrayList(java.util.ArrayList)

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