public static List<TryCatchBlock> copyTryCatches(BasicBlockReader block, Program target) { List<TryCatchBlock> result = new ArrayList<>(); for (TryCatchBlockReader tryCatch : block.readTryCatchBlocks()) { TryCatchBlock tryCatchCopy = new TryCatchBlock(); tryCatchCopy.setExceptionType(tryCatch.getExceptionType()); tryCatchCopy.setHandler(target.basicBlockAt(tryCatch.getHandler().getIndex())); result.add(tryCatchCopy); } return result; }
private void createNewBookmarks(List<TryCatchBlock> tryCatchBlocks) { // Add new bookmarks for (int i = tryCatchBookmarks.size(); i < tryCatchBlocks.size(); ++i) { TryCatchBlock tryCatch = tryCatchBlocks.get(tryCatchBlocks.size() - 1 - i); TryCatchBookmark bookmark = new TryCatchBookmark(); bookmark.block = stack.peek(); bookmark.offset = bookmark.block.body.size(); bookmark.exceptionHandler = tryCatch.getHandler().getIndex(); bookmark.exceptionType = tryCatch.getExceptionType(); bookmark.exceptionVariable = tryCatch.getHandler().getExceptionVariable() != null ? tryCatch.getHandler().getExceptionVariable().getIndex() : null; bookmark.block.tryCatches.add(bookmark); tryCatchBookmarks.add(bookmark); } }
public void rename(Program program) { for (int i = 0; i < program.basicBlockCount(); ++i) { BasicBlock basicBlock = program.basicBlockAt(i); for (Instruction insn : basicBlock) { insn.acceptVisitor(this); } for (TryCatchBlock tryCatch : basicBlock.getTryCatchBlocks()) { if (tryCatch.getExceptionType() != null) { tryCatch.setExceptionType(classNameMapper.map(tryCatch.getExceptionType())); } } } }
BasicBlock block = basicBlocks.get(i); if (block != null) { TryCatchBlock tryCatch = new TryCatchBlock(); if (tryCatchNode.type != null) { tryCatch.setExceptionType(referenceCache.getCached(tryCatchNode.type.replace('/', '.'))); tryCatch.setHandler(getBasicBlock(labelIndexes.get(tryCatchNode.handler.getLabel()))); tryCatch.getHandler().setExceptionVariable(program.variableAt(minLocal + method.maxLocals)); block.getTryCatchBlocks().add(tryCatch);
public void transform(BasicBlock block) { Instruction lastInsn = block.getLastInstruction(); if (lastInsn != null) { lastInsn.acceptVisitor(this); } for (Phi phi : block.getPhis()) { for (Incoming incoming : phi.getIncomings()) { incoming.setSource(map(incoming.getSource())); } } for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) { tryCatch.setHandler(map(tryCatch.getHandler())); } }
private void markAssignment(Variable var) { Deque<BasicBlock> worklist = new ArrayDeque<>(); worklist.push(currentBlock); if (variableDefined[var.getIndex()]) { for (TryCatchBlock tryCatch : currentBlock.getTryCatchBlocks()) { placePhi(tryCatch.getHandler().getIndex(), var, currentBlock, worklist); } } else { variableDefined[var.getIndex()] = true; } while (!worklist.isEmpty()) { BasicBlock block = worklist.pop(); int[] frontiers = domFrontiers[block.getIndex()]; if (frontiers != null) { for (int frontier : frontiers) { placePhi(frontier, var, block, worklist); } } } }
for (Phi phi : tryCatch.getHandler().getPhis()) { List<Variable> sourceVariables = phi.getIncomings().stream() .filter(incoming -> incoming.getSource() == tryCatch.getProtectedBlock()) .map(incoming -> incoming.getValue()) .collect(Collectors.toList());
public void processMethod(MethodReference method, Program program) { this.methodRef = method; this.program = program; boolean wasModified = false; for (int i = 0; i < program.basicBlockCount(); ++i) { BasicBlock block = program.basicBlockAt(i); instructionsToAdd.clear(); boolean missing = false; for (Instruction insn : block) { insn.acceptVisitor(instructionProcessor); if (!instructionsToAdd.isEmpty()) { wasModified = true; truncateBlock(insn); missing = true; break; } } if (!missing) { for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) { checkClass(null, tryCatch.getExceptionType()); } } } if (wasModified) { new UnreachableBasicBlockEliminator().optimize(program); } }
TryCatchBlock tryCatchCopy = new TryCatchBlock(); int handler = tryCatch.getHandler().getIndex(); tryCatchCopy.setExceptionType(tryCatch.getExceptionType()); tryCatchCopy.setHandler(program.basicBlockAt(copiedNodes.getOrDefault(handler, handler))); targetBlock.getTryCatchBlocks().add(tryCatchCopy);
public void rename(Program program) { for (int i = 0; i < program.basicBlockCount(); ++i) { BasicBlock basicBlock = program.basicBlockAt(i); for (Instruction insn : basicBlock) { insn.acceptVisitor(this); } for (TryCatchBlock tryCatch : basicBlock.getTryCatchBlocks()) { if (tryCatch.getExceptionType() != null) { tryCatch.setExceptionType(classNameMapper.map(tryCatch.getExceptionType())); } } } }
public void transform(BasicBlock block) { Instruction lastInsn = block.getLastInstruction(); if (lastInsn != null) { lastInsn.acceptVisitor(this); } for (Phi phi : block.getPhis()) { for (Incoming incoming : phi.getIncomings()) { incoming.setSource(map(incoming.getSource())); } } for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) { tryCatch.setHandler(map(tryCatch.getHandler())); } }
private void fillExceptionHandlers(Program program) { exceptionHandlers = new boolean[program.basicBlockCount()]; for (int i = 0; i < exceptionHandlers.length; ++i) { BasicBlock block = program.basicBlockAt(i); for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) { exceptionHandlers[tryCatch.getHandler().getIndex()] = true; } } }
for (Phi phi : tryCatch.getHandler().getPhis()) { List<Variable> sourceVariables = phi.getIncomings().stream() .filter(incoming -> incoming.getSource() == tryCatch.getProtectedBlock()) .map(incoming -> incoming.getValue()) .collect(Collectors.toList());
public void processMethod(MethodHolder method) { this.methodHolder = method; this.program = method.getProgram(); boolean wasModified = false; for (int i = 0; i < program.basicBlockCount(); ++i) { BasicBlock block = program.basicBlockAt(i); instructionsToAdd.clear(); boolean missing = false; for (Instruction insn : block) { insn.acceptVisitor(instructionProcessor); if (!instructionsToAdd.isEmpty()) { wasModified = true; truncateBlock(insn); missing = true; break; } } if (!missing) { for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) { checkClass(null, tryCatch.getExceptionType()); } } } if (wasModified) { new UnreachableBasicBlockEliminator().optimize(program); } }
private void parseCatch() throws IOException, ListingParseException { TryCatchBlock tryCatch = new TryCatchBlock(); if (lexer.getToken() == ListingToken.IDENTIFIER && !lexer.getTokenValue().equals("goto")) { tryCatch.setExceptionType((String) lexer.getTokenValue()); lexer.nextToken(); } expectKeyword("goto"); tryCatch.setHandler(expectBlock()); currentBlock.getTryCatchBlocks().add(tryCatch); }
BasicBlock block = basicBlocks.get(i); if (block != null) { TryCatchBlock tryCatch = new TryCatchBlock(); if (tryCatchNode.type != null) { tryCatch.setExceptionType(tryCatchNode.type.replace('/', '.')); tryCatch.setHandler(getBasicBlock(labelIndexes.get(tryCatchNode.handler.getLabel()))); tryCatch.getHandler().setExceptionVariable(program.variableAt(minLocal + method.maxLocals)); block.getTryCatchBlocks().add(tryCatch);
TryCatchBlock tryCatch = tryCatchBlocks.get(start); TryCatchBookmark bookmark = tryCatchBookmarks.get(start); if (tryCatch.getHandler().getIndex() != bookmark.exceptionHandler) { break; if (!Objects.equals(tryCatch.getExceptionType(), bookmark.exceptionType)) { break;
private BitSet getUsedVarsInBlock(LivenessAnalyzer liveness, BasicBlock block) { BitSet usedVars = new BitSet(); TransitionExtractor transitionExtractor = new TransitionExtractor(); block.getLastInstruction().acceptVisitor(transitionExtractor); for (BasicBlock successor : transitionExtractor.getTargets()) { usedVars.or(liveness.liveIn(successor.getIndex())); } for (TryCatchBlock tryCatch : block.getTryCatchBlocks()) { usedVars.or(liveness.liveIn(tryCatch.getHandler().getIndex())); } return usedVars; }
TryCatchBlock tryCatch = new TryCatchBlock(); int typeIndex = data.readInt(); if (typeIndex >= 0) { tryCatch.setExceptionType(symbolTable.at(typeIndex)); tryCatch.setHandler(program.basicBlockAt(data.readShort()));
TryCatchBlock tryCatchCopy = new TryCatchBlock(); int handler = tryCatch.getHandler().getIndex(); tryCatchCopy.setExceptionType(tryCatch.getExceptionType()); tryCatchCopy.setHandler(program.basicBlockAt(copiedNodes.getOrDefault(handler, handler))); targetBlock.getTryCatchBlocks().add(tryCatchCopy);