Search in sources :

Example 86 with InsnNode

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

the class TryCatchBlock method removeBlock.

public void removeBlock(MethodNode mth, BlockNode block) {
    for (InsnNode insn : block.getInstructions()) {
        insns.remove(insn);
        insn.remove(AType.CATCH_BLOCK);
    }
    if (insns.isEmpty()) {
        removeWholeBlock(mth);
    }
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode)

Example 87 with InsnNode

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

the class ClassModifier method removeSyntheticMethods.

private static void removeSyntheticMethods(ClassNode cls) {
    for (MethodNode mth : cls.getMethods()) {
        if (mth.isNoCode()) {
            continue;
        }
        AccessInfo af = mth.getAccessFlags();
        // remove bridge methods
        if (af.isBridge() && af.isSynthetic() && !isMethodUniq(cls, mth)) {
            // TODO add more checks before method deletion
            mth.add(AFlag.DONT_GENERATE);
            continue;
        }
        // remove synthetic constructor for inner classes
        if (af.isSynthetic() && af.isConstructor() && mth.getBasicBlocks().size() == 2) {
            List<InsnNode> insns = mth.getBasicBlocks().get(0).getInstructions();
            if (insns.size() == 1 && insns.get(0).getType() == InsnType.CONSTRUCTOR) {
                ConstructorInsn constr = (ConstructorInsn) insns.get(0);
                List<RegisterArg> args = mth.getArguments(false);
                if (constr.isThis() && !args.isEmpty()) {
                    // remove first arg for non-static class (references to outer class)
                    if (args.get(0).getType().equals(cls.getParentClass().getClassInfo().getType())) {
                        args.get(0).add(AFlag.SKIP_ARG);
                    }
                    // remove unused args
                    for (RegisterArg arg : args) {
                        SSAVar sVar = arg.getSVar();
                        if (sVar != null && sVar.getUseCount() == 0) {
                            arg.add(AFlag.SKIP_ARG);
                        }
                    }
                    mth.add(AFlag.DONT_GENERATE);
                }
            }
        }
    }
}
Also used : IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) MethodNode(jadx.core.dex.nodes.MethodNode) SSAVar(jadx.core.dex.instructions.args.SSAVar) AccessInfo(jadx.core.dex.info.AccessInfo) ConstructorInsn(jadx.core.dex.instructions.mods.ConstructorInsn)

Example 88 with InsnNode

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

the class ClassModifier method removeFieldUsageFromConstructor.

private static boolean removeFieldUsageFromConstructor(MethodNode mth, FieldNode field, ClassNode fieldsCls) {
    if (mth.isNoCode() || !mth.getAccessFlags().isConstructor()) {
        return false;
    }
    List<RegisterArg> args = mth.getArguments(false);
    if (args.isEmpty() || mth.contains(AFlag.SKIP_FIRST_ARG)) {
        return false;
    }
    RegisterArg arg = args.get(0);
    if (!arg.getType().equals(fieldsCls.getClassInfo().getType())) {
        return false;
    }
    BlockNode block = mth.getBasicBlocks().get(0);
    List<InsnNode> instructions = block.getInstructions();
    if (instructions.isEmpty()) {
        return false;
    }
    InsnNode insn = instructions.get(0);
    if (insn.getType() != InsnType.IPUT) {
        return false;
    }
    IndexInsnNode putInsn = (IndexInsnNode) insn;
    FieldInfo fieldInfo = (FieldInfo) putInsn.getIndex();
    if (!fieldInfo.equals(field.getFieldInfo()) || !putInsn.getArg(0).equals(arg)) {
        return false;
    }
    mth.removeFirstArgument();
    InstructionRemover.remove(mth, block, insn);
    // other arg usage -> wrap with IGET insn
    if (arg.getSVar().getUseCount() != 0) {
        InsnNode iget = new IndexInsnNode(InsnType.IGET, fieldInfo, 1);
        iget.addArg(insn.getArg(1));
        for (InsnArg insnArg : arg.getSVar().getUseList()) {
            insnArg.wrapInstruction(iget);
        }
    }
    return true;
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) InsnArg(jadx.core.dex.instructions.args.InsnArg) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) FieldInfo(jadx.core.dex.info.FieldInfo)

Example 89 with InsnNode

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

the class CodeShrinker method canMoveBetweenBlocks.

private static boolean canMoveBetweenBlocks(InsnNode assignInsn, BlockNode assignBlock, BlockNode useBlock, InsnNode useInsn) {
    if (!BlockUtils.isPathExists(assignBlock, useBlock)) {
        return false;
    }
    List<RegisterArg> argsList = ArgsInfo.getArgs(assignInsn);
    BitSet args = new BitSet();
    for (RegisterArg arg : argsList) {
        args.set(arg.getRegNum());
    }
    boolean startCheck = false;
    for (InsnNode insn : assignBlock.getInstructions()) {
        if (startCheck && (!insn.canReorder() || ArgsInfo.usedArgAssign(insn, args))) {
            return false;
        }
        if (insn == assignInsn) {
            startCheck = true;
        }
    }
    Set<BlockNode> pathsBlocks = BlockUtils.getAllPathsBlocks(assignBlock, useBlock);
    pathsBlocks.remove(assignBlock);
    pathsBlocks.remove(useBlock);
    for (BlockNode block : pathsBlocks) {
        for (InsnNode insn : block.getInstructions()) {
            if (!insn.canReorder() || ArgsInfo.usedArgAssign(insn, args)) {
                return false;
            }
        }
    }
    for (InsnNode insn : useBlock.getInstructions()) {
        if (insn == useInsn) {
            return true;
        }
        if (!insn.canReorder() || ArgsInfo.usedArgAssign(insn, args)) {
            return false;
        }
    }
    throw new JadxRuntimeException("Can't process instruction move : " + assignBlock);
}
Also used : BlockNode(jadx.core.dex.nodes.BlockNode) InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) EmptyBitSet(jadx.core.utils.EmptyBitSet) BitSet(java.util.BitSet) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Example 90 with InsnNode

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

the class InsnWrapArg method equals.

@Override
public boolean equals(Object o) {
    if (this == o) {
        return true;
    }
    if (!(o instanceof InsnWrapArg)) {
        return false;
    }
    InsnWrapArg that = (InsnWrapArg) o;
    InsnNode thisInsn = wrappedInsn;
    InsnNode thatInsn = that.wrappedInsn;
    if (!thisInsn.isSame(thatInsn)) {
        return false;
    }
    int count = thisInsn.getArgsCount();
    for (int i = 0; i < count; i++) {
        if (!thisInsn.getArg(i).equals(thatInsn.getArg(i))) {
            return false;
        }
    }
    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