String className = currentExceptionClass.getName(); for (TryBlock<? extends ExceptionHandler> tryBlock : tryBlocks) { int startAddress = tryBlock.getStartCodeAddress(); int endAddress = tryBlock.getStartCodeAddress() + tryBlock.getCodeUnitCount(); boolean inTryBlock = (address >= startAddress && address < endAddress); if (!inTryBlock) { List<? extends ExceptionHandler> handlers = tryBlock.getExceptionHandlers(); if (catchAll) {
if (currentTry.getStartCodeAddress() + currentTry.getCodeUnitCount() <= currentCodeAddress) { currentTry = null; triesIndex++; if (tryBlock.getStartCodeAddress() <= currentCodeAddress) { assert(tryBlock.getStartCodeAddress() + tryBlock.getCodeUnitCount() > currentCodeAddress);
@Nonnull private AnalyzedInstruction[] buildExceptionHandlerArray(@Nonnull TryBlock<? extends ExceptionHandler> tryBlock) { List<? extends ExceptionHandler> exceptionHandlers = tryBlock.getExceptionHandlers(); AnalyzedInstruction[] handlerInstructions = new AnalyzedInstruction[exceptionHandlers.size()]; for (int i=0; i<exceptionHandlers.size(); i++) { handlerInstructions[i] = analyzedInstructions.get(exceptionHandlers.get(i).getHandlerCodeAddress()); } return handlerInstructions; }
@Override public int getStartCodeAddress() { return tryBlock.getStartCodeAddress(); }
@Override public int getCodeUnitCount() { return tryBlock.getCodeUnitCount(); }
if (currentTry.getStartCodeAddress() + currentTry.getCodeUnitCount() <= currentCodeAddress) { currentTry = null; triesIndex++; if (tryBlock.getStartCodeAddress() <= currentCodeAddress) { assert(tryBlock.getStartCodeAddress() + tryBlock.getCodeUnitCount() > currentCodeAddress);
/** * Return the types that are used in this body. */ public Set<Type> usedTypes() { Set<Type> types = new HashSet<Type>(); for (DexlibAbstractInstruction i : instructions) { types.addAll(i.introducedTypes()); } if (tries != null) { for (TryBlock<? extends ExceptionHandler> tryItem : tries) { List<? extends ExceptionHandler> hList = tryItem.getExceptionHandlers(); for (ExceptionHandler handler : hList) { String exType = handler.getExceptionType(); if (exType == null) { // Exceptions continue; } types.add(DexType.toSoot(exType)); } } } return types; }
@Override public int getStartCodeAddress() { return tryBlock.getStartCodeAddress(); }
@Override public int getCodeUnitCount() { return tryBlock.getCodeUnitCount(); }
int startAddress = tryBlock.getStartCodeAddress(); int endAddress = startAddress + tryBlock.getCodeUnitCount(); int lastCoveredAddress = instructionOffsetMap.getInstructionCodeOffset(lastCoveredIndex); for (ExceptionHandler handler: tryBlock.getExceptionHandlers()) { int handlerAddress = handler.getHandlerCodeAddress(); if (handlerAddress >= codeSize) {
if (currentTry.getStartCodeAddress() + currentTry.getCodeUnitCount() <= currentCodeAddress) { currentTry = null; triesIndex++; if (tryBlock.getStartCodeAddress() <= currentCodeAddress) { assert(tryBlock.getStartCodeAddress() + tryBlock.getCodeUnitCount() > currentCodeAddress);
private String[] buildExceptions(Method method) { if (method.getImplementation() == null) { return null; } Set<String> exceptionTypes = new HashSet<>(); for (TryBlock<? extends ExceptionHandler> tryBlock : method.getImplementation() .getTryBlocks()) { for (ExceptionHandler handler : tryBlock.getExceptionHandlers()) { String type = handler.getExceptionType(); if (type == null) { // Type is null if it's a catchall continue; } exceptionTypes.add(stripName(type)); } } return exceptionTypes.toArray(new String[0]); }
@Override public int getStartCodeAddress() { return tryBlock.getStartCodeAddress(); }
@Override public int getCodeUnitCount() { return tryBlock.getCodeUnitCount(); }
Label startLabel = newLabel(codeAddressToIndex, tryBlock.getStartCodeAddress()); Label endLabel = newLabel(codeAddressToIndex, tryBlock.getStartCodeAddress() + tryBlock.getCodeUnitCount()); for (ExceptionHandler exceptionHandler : tryBlock.getExceptionHandlers()) { tryBlocks.add(new BuilderTryBlock(startLabel, endLabel, (TypeReference) convertReference(exceptionHandler.getExceptionTypeReference()),
@Test public void testTryEndAtEndOfMethod() { MethodImplementationBuilder builder = new MethodImplementationBuilder(10); Label startLabel = builder.addLabel("start"); builder.addInstruction(new BuilderInstruction10x(Opcode.NOP)); builder.addInstruction(new BuilderInstruction10x(Opcode.NOP)); builder.addInstruction(new BuilderInstruction10x(Opcode.NOP)); builder.addInstruction(new BuilderInstruction10x(Opcode.NOP)); builder.addInstruction(new BuilderInstruction10x(Opcode.NOP)); builder.addInstruction(new BuilderInstruction32x(Opcode.MOVE_16, 0, 0)); Label endLabel = builder.addLabel("end"); builder.addCatch(startLabel, endLabel, startLabel); MethodImplementation methodImplementation = builder.getMethodImplementation(); Assert.assertEquals(0, methodImplementation.getTryBlocks().get(0).getStartCodeAddress()); Assert.assertEquals(8, methodImplementation.getTryBlocks().get(0).getCodeUnitCount()); methodImplementation = new MutableMethodImplementation(methodImplementation); Assert.assertEquals(0, methodImplementation.getTryBlocks().get(0).getStartCodeAddress()); Assert.assertEquals(8, methodImplementation.getTryBlocks().get(0).getCodeUnitCount()); }
private void analyzeMoveException(@Nonnull AnalyzedInstruction analyzedInstruction) { int instructionAddress = getInstructionAddress(analyzedInstruction); RegisterType exceptionType = RegisterType.UNKNOWN_TYPE; for (TryBlock<? extends ExceptionHandler> tryBlock: methodImpl.getTryBlocks()) { for (ExceptionHandler handler: tryBlock.getExceptionHandlers()) { if (handler.getHandlerCodeAddress() == instructionAddress) { String type = handler.getExceptionType(); if (type == null) { exceptionType = RegisterType.getRegisterType(RegisterType.REFERENCE, classPath.getClass("Ljava/lang/Throwable;")); } else { exceptionType = RegisterType.getRegisterType(RegisterType.REFERENCE, classPath.getClass(type)) .merge(exceptionType); } } } } if (exceptionType.category == RegisterType.UNKNOWN) { throw new AnalysisException("move-exception must be the first instruction in an exception handler block"); } setDestinationRegisterTypeAndPropagateChanges(analyzedInstruction, exceptionType); }
final Jimple jimple = Jimple.v(); for (TryBlock<? extends ExceptionHandler> tryItem : tries) { int startAddress = tryItem.getStartCodeAddress(); int length = tryItem.getCodeUnitCount();// .getTryLength(); int endAddress = startAddress + length;// - 1; Unit beginStmt = instructionAtAddress(startAddress).getUnit(); List<? extends ExceptionHandler> hList = tryItem.getExceptionHandlers(); for (ExceptionHandler handler : hList) { String exceptionType = handler.getExceptionType();
for (ExceptionHandler handler: tryBlock.getExceptionHandlers()) { dexPool.typeSection.internNullable(handler.getExceptionType());
exceptionHandlerOffsetMap.put(tryBlock.getExceptionHandlers(), 0); int startAddress = tryBlock.getStartCodeAddress(); int endAddress = startAddress + tryBlock.getCodeUnitCount(); writer.writeUshort(tbCodeUnitCount); if (tryBlock.getExceptionHandlers().size() == 0) { throw new ExceptionWithContext("No exception handlers for the try block!"); Integer offset = exceptionHandlerOffsetMap.get(tryBlock.getExceptionHandlers()); if (offset != 0) { exceptionHandlerOffsetMap.put(tryBlock.getExceptionHandlers(), offset); int ehSize = tryBlock.getExceptionHandlers().size(); ExceptionHandler ehLast = tryBlock.getExceptionHandlers().get(ehSize-1); if (ehLast.getExceptionType() == null) { ehSize = ehSize * (-1) + 1; for (ExceptionHandler eh : tryBlock.getExceptionHandlers()) { TypeKey exceptionTypeKey = classSection.getExceptionType(eh);