use of jadx.core.dex.trycatch.ExceptionHandler in project jadx by skylot.
the class RegionUtils method getExcHandlersForRegion.
public static List<IContainer> getExcHandlersForRegion(IContainer region) {
CatchAttr cb = region.get(AType.CATCH_BLOCK);
if (cb != null) {
TryCatchBlock tb = cb.getTryBlock();
List<IContainer> list = new ArrayList<IContainer>(tb.getHandlersCount());
for (ExceptionHandler eh : tb.getHandlers()) {
list.add(eh.getHandlerRegion());
}
return list;
}
return Collections.emptyList();
}
use of jadx.core.dex.trycatch.ExceptionHandler in project jadx by skylot.
the class RegionGen method makeTryCatch.
private void makeTryCatch(TryCatchRegion region, CodeWriter code) throws CodegenException {
code.startLine("try {");
makeRegionIndent(code, region.getTryRegion());
// TODO: move search of 'allHandler' to 'TryCatchRegion'
ExceptionHandler allHandler = null;
for (Map.Entry<ExceptionHandler, IContainer> entry : region.getCatchRegions().entrySet()) {
ExceptionHandler handler = entry.getKey();
if (handler.isCatchAll()) {
if (allHandler != null) {
LOG.warn("Several 'all' handlers in try/catch block in {}", mth);
}
allHandler = handler;
} else {
makeCatchBlock(code, handler);
}
}
if (allHandler != null) {
makeCatchBlock(code, allHandler);
}
IContainer finallyRegion = region.getFinallyRegion();
if (finallyRegion != null) {
code.startLine("} finally {");
makeRegionIndent(code, finallyRegion);
}
code.startLine('}');
}
use of jadx.core.dex.trycatch.ExceptionHandler in project jadx by skylot.
the class DepthRegionTraversal method traverseIncludingExcHandlers.
public static void traverseIncludingExcHandlers(MethodNode mth, IRegionIterativeVisitor visitor) {
boolean repeat;
int k = 0;
do {
repeat = traverseIterativeStepInternal(mth, visitor, mth.getRegion());
if (!repeat) {
for (ExceptionHandler h : mth.getExceptionHandlers()) {
repeat = traverseIterativeStepInternal(mth, visitor, h.getHandlerRegion());
if (repeat) {
break;
}
}
}
if (k++ > ITERATIVE_LIMIT) {
throw new JadxOverflowException("Iterative traversal limit reached, method: " + mth);
}
} while (repeat);
}
use of jadx.core.dex.trycatch.ExceptionHandler in project jadx by skylot.
the class BlockExceptionHandler method processExceptionHandlers.
private static void processExceptionHandlers(MethodNode mth, BlockNode block) {
ExcHandlerAttr handlerAttr = block.get(AType.EXC_HANDLER);
if (handlerAttr == null) {
return;
}
ExceptionHandler excHandler = handlerAttr.getHandler();
excHandler.addBlock(block);
for (BlockNode node : BlockUtils.collectBlocksDominatedBy(block, block)) {
excHandler.addBlock(node);
}
for (BlockNode excBlock : excHandler.getBlocks()) {
// remove 'monitor-exit' from exception handler blocks
InstructionRemover remover = new InstructionRemover(mth, excBlock);
for (InsnNode insn : excBlock.getInstructions()) {
if (insn.getType() == InsnType.MONITOR_ENTER) {
break;
}
if (insn.getType() == InsnType.MONITOR_EXIT) {
remover.add(insn);
}
}
remover.perform();
// if 'throw' in exception handler block have 'catch' - merge these catch blocks
for (InsnNode insn : excBlock.getInstructions()) {
CatchAttr catchAttr = insn.get(AType.CATCH_BLOCK);
if (catchAttr == null) {
continue;
}
if (insn.getType() == InsnType.THROW || onlyAllHandler(catchAttr.getTryBlock())) {
TryCatchBlock handlerBlock = handlerAttr.getTryBlock();
TryCatchBlock catchBlock = catchAttr.getTryBlock();
handlerBlock.merge(mth, catchBlock);
}
}
}
}
Aggregations