org.jf.dexlib2.iface.TryBlock Java Examples

The following examples show how to use org.jf.dexlib2.iface.TryBlock. 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: DexBody.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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) // for handler which capture all Exceptions
              continue;
          types.add(DexType.toSoot(exType));
      }
     }
    }

    return types;
}
 
Example #2
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 #3
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 #4
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 #5
Source File: ImmutableMethodImplementation.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
public ImmutableMethodImplementation(int registerCount,
                                     @Nullable Iterable<? extends Instruction> instructions,
                                     @Nullable List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks,
                                     @Nullable Iterable<? extends DebugItem> debugItems) {
    this.registerCount = registerCount;
    this.instructions = ImmutableInstruction.immutableListOf(instructions);
    this.tryBlocks = ImmutableTryBlock.immutableListOf(tryBlocks);
    this.debugItems = ImmutableDebugItem.immutableListOf(debugItems);
}
 
Example #6
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 #7
Source File: BuilderClassPool.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
@Nonnull @Override
public List<? extends TryBlock<? extends ExceptionHandler>> getTryBlocks(@Nonnull BuilderMethod builderMethod) {
    MethodImplementation impl = builderMethod.getImplementation();
    if (impl == null) {
        return ImmutableList.of();
    }
    return impl.getTryBlocks();
}
 
Example #8
Source File: BuilderClassPool.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
@Nonnull @Override
public List<? extends TryBlock<? extends ExceptionHandler>> getTryBlocks(@Nonnull BuilderMethod builderMethod) {
    MethodImplementation impl = builderMethod.getImplementation();
    if (impl == null) {
        return ImmutableList.of();
    }
    return impl.getTryBlocks();
}
 
Example #9
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 #10
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 #11
Source File: ImmutableMethodImplementation.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public ImmutableMethodImplementation(int registerCount,
                                     @Nullable Iterable<? extends Instruction> instructions,
                                     @Nullable List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks,
                                     @Nullable Iterable<? extends DebugItem> debugItems) {
    this.registerCount = registerCount;
    this.instructions = ImmutableInstruction.immutableListOf(instructions);
    this.tryBlocks = ImmutableTryBlock.immutableListOf(tryBlocks);
    this.debugItems = ImmutableDebugItem.immutableListOf(debugItems);
}
 
Example #12
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 #13
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 #14
Source File: ImmutableMethodImplementation.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
public ImmutableMethodImplementation(int registerCount,
                                     @Nullable Iterable<? extends Instruction> instructions,
                                     @Nullable List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks,
                                     @Nullable Iterable<? extends DebugItem> debugItems) {
    this.registerCount = registerCount;
    this.instructions = ImmutableInstruction.immutableListOf(instructions);
    this.tryBlocks = ImmutableTryBlock.immutableListOf(tryBlocks);
    this.debugItems = ImmutableDebugItem.immutableListOf(debugItems);
}
 
Example #15
Source File: InsTructionsReIClassDef.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
protected List<? extends TryBlock<? extends ExceptionHandler>> reTryCatchBlock(List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks) {
    if (tryBlocks == null || tryBlocks.size() == 0) {
        return null;
    }
    List<ImmutableTryBlock> newTryCatchBlocks = new ArrayList<ImmutableTryBlock>();
    for (TryBlock<? extends ExceptionHandler> tryBlock : tryBlocks) {
        newTryCatchBlocks.add(ImmutableTryBlock.of(tryBlock));
    }
    return newTryCatchBlocks;
}
 
Example #16
Source File: MethodImplReIClassDef.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
protected MethodImplementation reMethodImpl(MethodImplementation methodImplementation) {
    if (methodImplementation == null){
        return null;
    }
    Iterable<? extends Instruction> instructions = methodImplementation.getInstructions();
    Iterable<? extends DebugItem> debugItems = methodImplementation.getDebugItems();
    List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks = methodImplementation.getTryBlocks();
    return new ImmutableMethodImplementation(methodImplementation.getRegisterCount(), reInstructions(instructions), reTryCatchBlock(methodImplementation.getTryBlocks()), reDebugItem(methodImplementation.getDebugItems()));

}
 
Example #17
Source File: ImmutableMethodImplementation.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public ImmutableMethodImplementation(int registerCount,
                                     @Nullable Iterable<? extends Instruction> instructions,
                                     @Nullable List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks,
                                     @Nullable Iterable<? extends DebugItem> debugItems) {
    this.registerCount = registerCount;
    this.instructions = ImmutableInstruction.immutableListOf(instructions);
    this.tryBlocks = ImmutableTryBlock.immutableListOf(tryBlocks);
    this.debugItems = ImmutableDebugItem.immutableListOf(debugItems);
}
 
Example #18
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 #19
Source File: BuilderClassPool.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Nonnull @Override
public List<? extends TryBlock<? extends ExceptionHandler>> getTryBlocks(@Nonnull BuilderMethod builderMethod) {
    MethodImplementation impl = builderMethod.getImplementation();
    if (impl == null) {
        return ImmutableList.of();
    }
    return impl.getTryBlocks();
}
 
Example #20
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 #21
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 #22
Source File: BuilderClassPool.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Nonnull @Override
public List<? extends TryBlock<? extends ExceptionHandler>> getTryBlocks(@Nonnull BuilderMethod builderMethod) {
    MethodImplementation impl = builderMethod.getImplementation();
    if (impl == null) {
        return ImmutableList.of();
    }
    return impl.getTryBlocks();
}
 
Example #23
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 #24
Source File: MethodImplementationRewriter.java    From HeyGirl with Apache License 2.0 4 votes vote down vote up
@Override @Nonnull public List<? extends TryBlock<? extends ExceptionHandler>> getTryBlocks() {
    return RewriterUtils.rewriteList(rewriters.getTryBlockRewriter(),
            methodImplementation.getTryBlocks());
}
 
Example #25
Source File: TryBlockRewriter.java    From HeyGirl with Apache License 2.0 4 votes vote down vote up
public RewrittenTryBlock(@Nonnull TryBlock<? extends ExceptionHandler> tryBlock) {
    this.tryBlock = tryBlock;
}
 
Example #26
Source File: DexWriter.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
private void writeDebugAndCodeItems(@Nonnull DexDataWriter offsetWriter,
                                    @Nonnull DeferredOutputStream temp) throws IOException {
    ByteArrayOutputStream ehBuf = new ByteArrayOutputStream();
    debugSectionOffset = offsetWriter.getPosition();
    DebugWriter<StringKey, TypeKey> debugWriter =
            new DebugWriter<StringKey, TypeKey>(stringSection, typeSection, offsetWriter);

    DexDataWriter codeWriter = new DexDataWriter(temp, 0);

    List<CodeItemOffset<MethodKey>> codeOffsets = Lists.newArrayList();

    for (ClassKey classKey: classSection.getSortedClasses()) {
        Collection<? extends MethodKey> directMethods = classSection.getSortedDirectMethods(classKey);
        Collection<? extends MethodKey> virtualMethods = classSection.getSortedVirtualMethods(classKey);

        Iterable<MethodKey> methods = Iterables.concat(directMethods, virtualMethods);

        for (MethodKey methodKey: methods) {
            List<? extends TryBlock<? extends ExceptionHandler>> tryBlocks =
                    classSection.getTryBlocks(methodKey);
            Iterable<? extends Instruction> instructions = classSection.getInstructions(methodKey);
            Iterable<? extends DebugItem> debugItems = classSection.getDebugItems(methodKey);

            if (instructions != null && stringSection.hasJumboIndexes()) {
                boolean needsFix = false;
                for (Instruction instruction: instructions) {
                    if (instruction.getOpcode() == Opcode.CONST_STRING) {
                        if (stringSection.getItemIndex(
                                (StringRef)((ReferenceInstruction)instruction).getReference()) >= 65536) {
                            needsFix = true;
                            break;
                        }
                    }
                }

                if (needsFix) {
                    MutableMethodImplementation mutableMethodImplementation =
                            classSection.makeMutableMethodImplementation(methodKey);
                    fixInstructions(mutableMethodImplementation);

                    instructions = mutableMethodImplementation.getInstructions();
                    tryBlocks = mutableMethodImplementation.getTryBlocks();
                    debugItems = mutableMethodImplementation.getDebugItems();
                }
            }

            int debugItemOffset = writeDebugItem(offsetWriter, debugWriter,
                    classSection.getParameterNames(methodKey), debugItems);
            int codeItemOffset = writeCodeItem(codeWriter, ehBuf, methodKey, tryBlocks, instructions, debugItemOffset);

            if (codeItemOffset != -1) {
                codeOffsets.add(new CodeItemOffset<MethodKey>(methodKey, codeItemOffset));
            }
        }
    }

    offsetWriter.align();
    codeSectionOffset = offsetWriter.getPosition();

    codeWriter.close();
    temp.writeTo(offsetWriter);
    temp.close();

    for (CodeItemOffset<MethodKey> codeOffset: codeOffsets) {
        classSection.setCodeItemOffset(codeOffset.method, codeSectionOffset + codeOffset.codeOffset);
    }
}
 
Example #27
Source File: TryBlockRewriter.java    From HeyGirl with Apache License 2.0 4 votes vote down vote up
@Nonnull @Override public TryBlock<? extends ExceptionHandler> rewrite(
        @Nonnull TryBlock<? extends ExceptionHandler> tryBlock) {
    return new RewrittenTryBlock(tryBlock);
}
 
Example #28
Source File: ImmutableTryBlock.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static ImmutableList<ImmutableTryBlock> immutableListOf(
        @Nullable List<? extends TryBlock<? extends ExceptionHandler>> list) {
    return CONVERTER.toList(list);
}
 
Example #29
Source File: ImmutableTryBlock.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
protected ImmutableTryBlock makeImmutable(@Nonnull TryBlock<? extends ExceptionHandler> item) {
    return ImmutableTryBlock.of(item);
}
 
Example #30
Source File: TryBlockRewriter.java    From ZjDroid with Apache License 2.0 4 votes vote down vote up
@Nonnull @Override public TryBlock<? extends ExceptionHandler> rewrite(
        @Nonnull TryBlock<? extends ExceptionHandler> tryBlock) {
    return new RewrittenTryBlock(tryBlock);
}