Search in sources :

Example 6 with IContainer

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

the class TryCatchRegion method setTryCatchBlock.

public void setTryCatchBlock(TryCatchBlock tryCatchBlock) {
    this.tryCatchBlock = tryCatchBlock;
    int count = tryCatchBlock.getHandlersCount();
    this.catchRegions = new LinkedHashMap<ExceptionHandler, IContainer>(count);
    for (ExceptionHandler handler : tryCatchBlock.getHandlers()) {
        IContainer handlerRegion = handler.getHandlerRegion();
        if (handlerRegion != null) {
            if (handler.isFinally()) {
                finallyRegion = handlerRegion;
            } else {
                catchRegions.put(handler, handlerRegion);
            }
        }
    }
}
Also used : ExceptionHandler(jadx.core.dex.trycatch.ExceptionHandler) IContainer(jadx.core.dex.nodes.IContainer)

Example 7 with IContainer

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

the class RegionGen method makeIf.

private void makeIf(IfRegion region, CodeWriter code, boolean newLine) throws CodegenException {
    if (newLine) {
        code.startLineWithNum(region.getSourceLine());
    } else {
        code.attachSourceLine(region.getSourceLine());
    }
    code.add("if (");
    new ConditionGen(this).add(code, region.getCondition());
    code.add(") {");
    makeRegionIndent(code, region.getThenRegion());
    code.startLine('}');
    IContainer els = region.getElseRegion();
    if (els != null && RegionUtils.notEmpty(els)) {
        code.add(" else ");
        if (connectElseIf(code, els)) {
            return;
        }
        code.add('{');
        makeRegionIndent(code, els);
        code.startLine('}');
    }
}
Also used : IContainer(jadx.core.dex.nodes.IContainer)

Example 8 with IContainer

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

the class RegionMaker method processHandlersOutBlocks.

/**
	 * Search handlers successor blocks not included in any region.
	 */
protected IRegion processHandlersOutBlocks(MethodNode mth, Set<TryCatchBlock> tcs) {
    Set<IBlock> allRegionBlocks = new HashSet<IBlock>();
    RegionUtils.getAllRegionBlocks(mth.getRegion(), allRegionBlocks);
    Set<IBlock> succBlocks = new HashSet<IBlock>();
    for (TryCatchBlock tc : tcs) {
        for (ExceptionHandler handler : tc.getHandlers()) {
            IContainer region = handler.getHandlerRegion();
            if (region != null) {
                IBlock lastBlock = RegionUtils.getLastBlock(region);
                if (lastBlock instanceof BlockNode) {
                    succBlocks.addAll(((BlockNode) lastBlock).getSuccessors());
                }
                RegionUtils.getAllRegionBlocks(region, allRegionBlocks);
            }
        }
    }
    succBlocks.removeAll(allRegionBlocks);
    if (succBlocks.isEmpty()) {
        return null;
    }
    Region excOutRegion = new Region(mth.getRegion());
    for (IBlock block : succBlocks) {
        if (block instanceof BlockNode) {
            excOutRegion.add(makeRegion((BlockNode) block, new RegionStack(mth)));
        }
    }
    return excOutRegion;
}
Also used : ExceptionHandler(jadx.core.dex.trycatch.ExceptionHandler) BlockNode(jadx.core.dex.nodes.BlockNode) IBlock(jadx.core.dex.nodes.IBlock) Region(jadx.core.dex.regions.Region) IRegion(jadx.core.dex.nodes.IRegion) SwitchRegion(jadx.core.dex.regions.SwitchRegion) SynchronizedRegion(jadx.core.dex.regions.SynchronizedRegion) LoopRegion(jadx.core.dex.regions.loops.LoopRegion) IfRegion(jadx.core.dex.regions.conditions.IfRegion) TryCatchBlock(jadx.core.dex.trycatch.TryCatchBlock) IContainer(jadx.core.dex.nodes.IContainer) HashSet(java.util.HashSet)

Example 9 with IContainer

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

the class RegionMakerVisitor method removeSynchronized.

private static void removeSynchronized(MethodNode mth) {
    Region startRegion = mth.getRegion();
    List<IContainer> subBlocks = startRegion.getSubBlocks();
    if (!subBlocks.isEmpty() && subBlocks.get(0) instanceof SynchronizedRegion) {
        SynchronizedRegion synchRegion = (SynchronizedRegion) subBlocks.get(0);
        InsnNode synchInsn = synchRegion.getEnterInsn();
        if (!synchInsn.getArg(0).isThis()) {
            LOG.warn("In synchronized method {}, top region not synchronized by 'this' {}", mth, synchInsn);
            return;
        }
        // replace synchronized block with inner region
        startRegion.getSubBlocks().set(0, synchRegion.getRegion());
        // remove 'monitor-enter' instruction
        InstructionRemover.remove(mth, synchInsn);
        // remove 'monitor-exit' instruction
        for (InsnNode exit : synchRegion.getExitInsns()) {
            InstructionRemover.remove(mth, exit);
        }
        // run region cleaner again
        CleanRegions.process(mth);
    // assume that CodeShrinker will be run after this
    }
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) SynchronizedRegion(jadx.core.dex.regions.SynchronizedRegion) IRegion(jadx.core.dex.nodes.IRegion) SwitchRegion(jadx.core.dex.regions.SwitchRegion) SynchronizedRegion(jadx.core.dex.regions.SynchronizedRegion) LoopRegion(jadx.core.dex.regions.loops.LoopRegion) Region(jadx.core.dex.regions.Region) IContainer(jadx.core.dex.nodes.IContainer)

Example 10 with IContainer

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

the class RegionMakerVisitor method insertEdgeInsn.

/**
	 * Insert insn block from edge insn attribute.
	 */
private static void insertEdgeInsn(Region region) {
    List<IContainer> subBlocks = region.getSubBlocks();
    if (subBlocks.isEmpty()) {
        return;
    }
    IContainer last = subBlocks.get(subBlocks.size() - 1);
    List<EdgeInsnAttr> edgeInsnAttrs = last.getAll(AType.EDGE_INSN);
    if (edgeInsnAttrs.isEmpty()) {
        return;
    }
    EdgeInsnAttr insnAttr = edgeInsnAttrs.get(0);
    if (!insnAttr.getStart().equals(last)) {
        return;
    }
    List<InsnNode> insns = Collections.singletonList(insnAttr.getInsn());
    region.add(new InsnContainer(insns));
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) InsnContainer(jadx.core.dex.nodes.InsnContainer) IContainer(jadx.core.dex.nodes.IContainer) EdgeInsnAttr(jadx.core.dex.attributes.nodes.EdgeInsnAttr)

Aggregations

IContainer (jadx.core.dex.nodes.IContainer)22 IRegion (jadx.core.dex.nodes.IRegion)11 InsnNode (jadx.core.dex.nodes.InsnNode)6 Region (jadx.core.dex.regions.Region)6 IBlock (jadx.core.dex.nodes.IBlock)5 BlockNode (jadx.core.dex.nodes.BlockNode)4 IBranchRegion (jadx.core.dex.nodes.IBranchRegion)4 LoopRegion (jadx.core.dex.regions.loops.LoopRegion)4 ExceptionHandler (jadx.core.dex.trycatch.ExceptionHandler)4 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)3 SwitchRegion (jadx.core.dex.regions.SwitchRegion)3 SynchronizedRegion (jadx.core.dex.regions.SynchronizedRegion)3 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)3 InsnArg (jadx.core.dex.instructions.args.InsnArg)2 IfRegion (jadx.core.dex.regions.conditions.IfRegion)2 TryCatchBlock (jadx.core.dex.trycatch.TryCatchBlock)2 HashSet (java.util.HashSet)2 EdgeInsnAttr (jadx.core.dex.attributes.nodes.EdgeInsnAttr)1 InsnType (jadx.core.dex.instructions.InsnType)1 PhiInsn (jadx.core.dex.instructions.PhiInsn)1