Search in sources :

Example 1 with NamedArg

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

the class ModVisitor method processMoveException.

private static void processMoveException(MethodNode mth, BlockNode block, InsnNode insn, InstructionRemover remover) {
    ExcHandlerAttr excHandlerAttr = block.get(AType.EXC_HANDLER);
    if (excHandlerAttr == null) {
        return;
    }
    ExceptionHandler excHandler = excHandlerAttr.getHandler();
    // result arg used both in this insn and exception handler,
    RegisterArg resArg = insn.getResult();
    ArgType type = excHandler.isCatchAll() ? ArgType.THROWABLE : excHandler.getCatchType().getType();
    String name = excHandler.isCatchAll() ? "th" : "e";
    if (resArg.getName() == null) {
        resArg.setName(name);
    }
    SSAVar sVar = insn.getResult().getSVar();
    if (sVar.getUseCount() == 0) {
        excHandler.setArg(new NamedArg(name, type));
        remover.add(insn);
    } else if (sVar.isUsedInPhi()) {
        // exception var moved to external variable => replace with 'move' insn
        InsnNode moveInsn = new InsnNode(InsnType.MOVE, 1);
        moveInsn.setResult(insn.getResult());
        NamedArg namedArg = new NamedArg(name, type);
        moveInsn.addArg(namedArg);
        excHandler.setArg(namedArg);
        replaceInsn(block, 0, moveInsn);
    }
}
Also used : ExceptionHandler(jadx.core.dex.trycatch.ExceptionHandler) ArgType(jadx.core.dex.instructions.args.ArgType) IndexInsnNode(jadx.core.dex.instructions.IndexInsnNode) InsnNode(jadx.core.dex.nodes.InsnNode) RegisterArg(jadx.core.dex.instructions.args.RegisterArg) ExcHandlerAttr(jadx.core.dex.trycatch.ExcHandlerAttr) SSAVar(jadx.core.dex.instructions.args.SSAVar) NamedArg(jadx.core.dex.instructions.args.NamedArg)

Example 2 with NamedArg

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

the class RegionGen method makeCatchBlock.

private void makeCatchBlock(CodeWriter code, ExceptionHandler handler) throws CodegenException {
    IContainer region = handler.getHandlerRegion();
    if (region == null) {
        return;
    }
    code.startLine("} catch (");
    InsnArg arg = handler.getArg();
    if (arg instanceof RegisterArg) {
        declareVar(code, (RegisterArg) arg);
    } else if (arg instanceof NamedArg) {
        if (handler.isCatchAll()) {
            code.add("Throwable");
        } else {
            useClass(code, handler.getCatchType());
        }
        code.add(' ');
        code.add(mgen.getNameGen().assignNamedArg((NamedArg) arg));
    }
    code.add(") {");
    makeRegionIndent(code, region);
}
Also used : RegisterArg(jadx.core.dex.instructions.args.RegisterArg) InsnArg(jadx.core.dex.instructions.args.InsnArg) NamedArg(jadx.core.dex.instructions.args.NamedArg) IContainer(jadx.core.dex.nodes.IContainer)

Aggregations

NamedArg (jadx.core.dex.instructions.args.NamedArg)2 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)2 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)1 ArgType (jadx.core.dex.instructions.args.ArgType)1 InsnArg (jadx.core.dex.instructions.args.InsnArg)1 SSAVar (jadx.core.dex.instructions.args.SSAVar)1 IContainer (jadx.core.dex.nodes.IContainer)1 InsnNode (jadx.core.dex.nodes.InsnNode)1 ExcHandlerAttr (jadx.core.dex.trycatch.ExcHandlerAttr)1 ExceptionHandler (jadx.core.dex.trycatch.ExceptionHandler)1