Java Code Examples for org.jf.dexlib2.iface.TryBlock#getStartCodeAddress()

The following examples show how to use org.jf.dexlib2.iface.TryBlock#getStartCodeAddress() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImmutableTryBlock.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public static ImmutableTryBlock of(TryBlock<? extends ExceptionHandler> tryBlock) {
    if (tryBlock instanceof ImmutableTryBlock) {
        return (ImmutableTryBlock)tryBlock;
    }
    return new ImmutableTryBlock(
            tryBlock.getStartCodeAddress(),
            tryBlock.getCodeUnitCount(),
            tryBlock.getExceptionHandlers());
}
 
Example 2
Source File: BaseTryBlock.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Override public boolean equals(Object o) {
    if (o instanceof TryBlock) {
        TryBlock other = (TryBlock)o;
        return getStartCodeAddress() == other.getStartCodeAddress() &&
                getCodeUnitCount() == other.getCodeUnitCount() &&
                getExceptionHandlers().equals(other.getExceptionHandlers());
    }
    return false;
}
 
Example 3
Source File: TryListBuilder.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public static <EH extends ExceptionHandler> List<TryBlock<EH>> massageTryBlocks(
        List<? extends TryBlock<? extends EH>> tryBlocks) {
    TryListBuilder<EH> tlb = new TryListBuilder<EH>();

    for (TryBlock<? extends EH> tryBlock: tryBlocks) {
        int startAddress = tryBlock.getStartCodeAddress();
        int endAddress = startAddress + tryBlock.getCodeUnitCount();

        for (EH exceptionHandler: tryBlock.getExceptionHandlers()) {
            tlb.addHandler(startAddress, endAddress, exceptionHandler);
        }
    }
    return tlb.getTryBlocks();
}
 
Example 4
Source File: ImmutableTryBlock.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
public static ImmutableTryBlock of(TryBlock<? extends ExceptionHandler> tryBlock) {
    if (tryBlock instanceof ImmutableTryBlock) {
        return (ImmutableTryBlock)tryBlock;
    }
    return new ImmutableTryBlock(
            tryBlock.getStartCodeAddress(),
            tryBlock.getCodeUnitCount(),
            tryBlock.getExceptionHandlers());
}
 
Example 5
Source File: BaseTryBlock.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
@Override public boolean equals(Object o) {
    if (o instanceof TryBlock) {
        TryBlock other = (TryBlock)o;
        return getStartCodeAddress() == other.getStartCodeAddress() &&
                getCodeUnitCount() == other.getCodeUnitCount() &&
                getExceptionHandlers().equals(other.getExceptionHandlers());
    }
    return false;
}
 
Example 6
Source File: TryListBuilder.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
public static <EH extends ExceptionHandler> List<TryBlock<EH>> massageTryBlocks(
        List<? extends TryBlock<? extends EH>> tryBlocks) {
    TryListBuilder<EH> tlb = new TryListBuilder<EH>();

    for (TryBlock<? extends EH> tryBlock: tryBlocks) {
        int startAddress = tryBlock.getStartCodeAddress();
        int endAddress = startAddress + tryBlock.getCodeUnitCount();

        for (EH exceptionHandler: tryBlock.getExceptionHandlers()) {
            tlb.addHandler(startAddress, endAddress, exceptionHandler);
        }
    }
    return tlb.getTryBlocks();
}
 
Example 7
Source File: ImmutableTryBlock.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
public static ImmutableTryBlock of(TryBlock<? extends ExceptionHandler> tryBlock) {
    if (tryBlock instanceof ImmutableTryBlock) {
        return (ImmutableTryBlock)tryBlock;
    }
    return new ImmutableTryBlock(
            tryBlock.getStartCodeAddress(),
            tryBlock.getCodeUnitCount(),
            tryBlock.getExceptionHandlers());
}
 
Example 8
Source File: BaseTryBlock.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
@Override public boolean equals(Object o) {
    if (o instanceof TryBlock) {
        TryBlock other = (TryBlock)o;
        return getStartCodeAddress() == other.getStartCodeAddress() &&
                getCodeUnitCount() == other.getCodeUnitCount() &&
                getExceptionHandlers().equals(other.getExceptionHandlers());
    }
    return false;
}
 
Example 9
Source File: TryListBuilder.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
public static <EH extends ExceptionHandler> List<TryBlock<EH>> massageTryBlocks(
        List<? extends TryBlock<? extends EH>> tryBlocks) {
    TryListBuilder<EH> tlb = new TryListBuilder<EH>();

    for (TryBlock<? extends EH> tryBlock: tryBlocks) {
        int startAddress = tryBlock.getStartCodeAddress();
        int endAddress = startAddress + tryBlock.getCodeUnitCount();

        for (EH exceptionHandler: tryBlock.getExceptionHandlers()) {
            tlb.addHandler(startAddress, endAddress, exceptionHandler);
        }
    }
    return tlb.getTryBlocks();
}
 
Example 10
Source File: ImmutableTryBlock.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public static ImmutableTryBlock of(TryBlock<? extends ExceptionHandler> tryBlock) {
    if (tryBlock instanceof ImmutableTryBlock) {
        return (ImmutableTryBlock)tryBlock;
    }
    return new ImmutableTryBlock(
            tryBlock.getStartCodeAddress(),
            tryBlock.getCodeUnitCount(),
            tryBlock.getExceptionHandlers());
}
 
Example 11
Source File: BaseTryBlock.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Override public boolean equals(Object o) {
    if (o instanceof TryBlock) {
        TryBlock other = (TryBlock)o;
        return getStartCodeAddress() == other.getStartCodeAddress() &&
                getCodeUnitCount() == other.getCodeUnitCount() &&
                getExceptionHandlers().equals(other.getExceptionHandlers());
    }
    return false;
}
 
Example 12
Source File: TryListBuilder.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public static <EH extends ExceptionHandler> List<TryBlock<EH>> massageTryBlocks(
        List<? extends TryBlock<? extends EH>> tryBlocks) {
    TryListBuilder<EH> tlb = new TryListBuilder<EH>();

    for (TryBlock<? extends EH> tryBlock: tryBlocks) {
        int startAddress = tryBlock.getStartCodeAddress();
        int endAddress = startAddress + tryBlock.getCodeUnitCount();

        for (EH exceptionHandler: tryBlock.getExceptionHandlers()) {
            tlb.addHandler(startAddress, endAddress, exceptionHandler);
        }
    }
    return tlb.getTryBlocks();
}
 
Example 13
Source File: DexBody.java    From JAADAS with GNU General Public License v3.0 4 votes vote down vote up
/**
  * Add the traps of this body.
  *
  * Should only be called at the end jimplify.
  */
 private void addTraps() {
   for (TryBlock<? extends ExceptionHandler> tryItem : tries) {
         int startAddress = tryItem.getStartCodeAddress();
         Debug.printDbg(" start : 0x", Integer.toHexString(startAddress));
         int length = tryItem.getCodeUnitCount();//.getTryLength();
         Debug.printDbg(" length: 0x", Integer.toHexString(length));
         Debug.printDbg(" end   : 0x", Integer.toHexString(startAddress + length));
         int endAddress = startAddress + length;// - 1;
         Unit beginStmt = instructionAtAddress(startAddress).getUnit();
         // (startAddress + length) typically points to the first byte of the first instruction after the try block
         // except if there is no instruction after the try block in which case it points to the last byte of the last
         // instruction of the try block. Removing 1 from (startAddress + length) always points to "somewhere" in
         // the last instruction of the try block since the smallest instruction is on two bytes (nop = 0x0000).
         Unit endStmt =  instructionAtAddress (endAddress).getUnit();
// if the try block ends on the last instruction of the body, add a
// nop instruction so Soot can include
// the last instruction in the try block.
if (jBody.getUnits().getLast() == endStmt
		&& instructionAtAddress(endAddress - 1).getUnit() == endStmt) {
	Unit nop = Jimple.v().newNopStmt();
	jBody.getUnits().insertAfter(nop, endStmt);
	endStmt = nop;
}
Debug.printDbg("begin instruction (0x",
		Integer.toHexString(startAddress), "): ",
		instructionAtAddress(startAddress).getUnit(), " --- ",
		beginStmt);
Debug.printDbg("end instruction   (0x",
		Integer.toHexString(endAddress), "): ",
		instructionAtAddress(endAddress).getUnit(), " --- ",
		endStmt);


         List<? extends ExceptionHandler> hList = tryItem.getExceptionHandlers();
         for (ExceptionHandler handler: hList) {
           int handlerAddress = handler.getHandlerCodeAddress();
           Debug.printDbg("handler   (0x",
         		  Integer.toHexString(handlerAddress),
         		  "): ",
         		  instructionAtAddress (handlerAddress).getUnit(),
         		  " --- ",
         		  handlerAddress > 0 ? instructionAtAddress (handlerAddress-1).getUnit() : "<unknown>");
           String exceptionType = handler.getExceptionType();
           if (exceptionType == null)
               exceptionType = "Ljava/lang/Throwable;";
           Type t = DexType.toSoot(exceptionType);
             // exceptions can only be of RefType
             if (t instanceof RefType) {
                 SootClass exception = ((RefType) t).getSootClass();
                 DexlibAbstractInstruction instruction = instructionAtAddress(handler.getHandlerCodeAddress());
                 if (! (instruction instanceof MoveExceptionInstruction))
                     Debug.printDbg("First instruction of trap handler unit not MoveException but " , instruction.getClass());
                 else
                   ((MoveExceptionInstruction) instruction).setRealType(this, exception.getType());

                 Trap trap = Jimple.v().newTrap(exception, beginStmt, endStmt, instruction.getUnit());
                 jBody.getTraps().add(trap);
             }
         }
     }
 }