org.jf.dexlib2.iface.ExceptionHandler Java Examples

The following examples show how to use org.jf.dexlib2.iface.ExceptionHandler. 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: TryListBuilder.java    From HeyGirl with Apache License 2.0 6 votes vote down vote up
public void addHandler(@Nonnull EH handler) {
    for (ExceptionHandler existingHandler: exceptionHandlers) {
        String existingType = existingHandler.getExceptionType();
        String newType = handler.getExceptionType();

        // Don't add it if we already have a handler of the same type
        if (existingType == null) {
            if (newType == null) {
                if (existingHandler.getHandlerCodeAddress() != handler.getHandlerCodeAddress()) {
                    throw new InvalidTryException(
                            "Multiple overlapping catch all handlers with different handlers");
                }
                return;
            }
        } else if (existingType.equals(newType)) {
            if (existingHandler.getHandlerCodeAddress() != handler.getHandlerCodeAddress()) {
                throw new InvalidTryException(
                        "Multiple overlapping catches for %s with different handlers", existingType);
            }
            return;
        }
    }

    exceptionHandlers.add(handler);
}
 
Example #3
Source File: BaseExceptionHandler.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
@Override
public int compareTo(@Nonnull ExceptionHandler o) {
    int res;
    String exceptionType = getExceptionType();
    if (exceptionType == null) {
        if (o.getExceptionType() != null) {
            return 1;
        }
    } else {
        String otherExceptionType = o.getExceptionType();
        if (otherExceptionType == null) {
            return -1;
        }
        res = exceptionType.compareTo(o.getExceptionType());
        if (res != 0) return res;
    }
    return Ints.compare(getHandlerCodeAddress(), o.getHandlerCodeAddress());
}
 
Example #4
Source File: BaseExceptionHandler.java    From HeyGirl with Apache License 2.0 6 votes vote down vote up
@Override
public int compareTo(@Nonnull ExceptionHandler o) {
    int res;
    String exceptionType = getExceptionType();
    if (exceptionType == null) {
        if (o.getExceptionType() != null) {
            return 1;
        }
    } else {
        String otherExceptionType = o.getExceptionType();
        if (otherExceptionType == null) {
            return -1;
        }
        res = exceptionType.compareTo(o.getExceptionType());
        if (res != 0) return res;
    }
    return Ints.compare(getHandlerCodeAddress(), o.getHandlerCodeAddress());
}
 
Example #5
Source File: BaseExceptionHandler.java    From zjdroid with Apache License 2.0 6 votes vote down vote up
@Override
public int compareTo(@Nonnull ExceptionHandler o) {
    int res;
    String exceptionType = getExceptionType();
    if (exceptionType == null) {
        if (o.getExceptionType() != null) {
            return 1;
        }
    } else {
        String otherExceptionType = o.getExceptionType();
        if (otherExceptionType == null) {
            return -1;
        }
        res = exceptionType.compareTo(o.getExceptionType());
        if (res != 0) return res;
    }
    return Ints.compare(getHandlerCodeAddress(), o.getHandlerCodeAddress());
}
 
Example #6
Source File: BaseExceptionHandler.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
@Override
public int compareTo(@Nonnull ExceptionHandler o) {
    int res;
    String exceptionType = getExceptionType();
    if (exceptionType == null) {
        if (o.getExceptionType() != null) {
            return 1;
        }
    } else {
        String otherExceptionType = o.getExceptionType();
        if (otherExceptionType == null) {
            return -1;
        }
        res = exceptionType.compareTo(o.getExceptionType());
        if (res != 0) return res;
    }
    return Ints.compare(getHandlerCodeAddress(), o.getHandlerCodeAddress());
}
 
Example #7
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 #8
Source File: ImmutableExceptionHandler.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public static ImmutableExceptionHandler of(ExceptionHandler exceptionHandler) {
    if (exceptionHandler instanceof ImmutableExceptionHandler) {
        return (ImmutableExceptionHandler)exceptionHandler;
    }
    return new ImmutableExceptionHandler(
            exceptionHandler.getExceptionType(),
            exceptionHandler.getHandlerCodeAddress());
}
 
Example #9
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 #10
Source File: ImmutableTryBlock.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public ImmutableTryBlock(int startCodeAddress,
                         int codeUnitCount,
                         @Nullable List<? extends ExceptionHandler> exceptionHandlers) {
    this.startCodeAddress = startCodeAddress;
    this.codeUnitCount = codeUnitCount;
    this.exceptionHandlers = ImmutableExceptionHandler.immutableListOf(exceptionHandlers);
}
 
Example #11
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 #12
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 #13
Source File: BaseExceptionHandler.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Override public int compare(ExceptionHandler o1, ExceptionHandler o2) {
    String exceptionType1 = o1.getExceptionType();
    if (exceptionType1 == null) {
        if (o2.getExceptionType() != null) {
            return 1;
        }
        return 0;
    } else {
        String exceptionType2 = o2.getExceptionType();
        if (exceptionType2 == null) {
            return -1;
        }
        return exceptionType1.compareTo(o2.getExceptionType());
    }
}
 
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: ImmutableExceptionHandler.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public static ImmutableExceptionHandler of(ExceptionHandler exceptionHandler) {
    if (exceptionHandler instanceof ImmutableExceptionHandler) {
        return (ImmutableExceptionHandler)exceptionHandler;
    }
    return new ImmutableExceptionHandler(
            exceptionHandler.getExceptionType(),
            exceptionHandler.getHandlerCodeAddress());
}
 
Example #16
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 #17
Source File: BaseExceptionHandler.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Override public int compare(ExceptionHandler o1, ExceptionHandler o2) {
    String exceptionType1 = o1.getExceptionType();
    if (exceptionType1 == null) {
        if (o2.getExceptionType() != null) {
            return 1;
        }
        return 0;
    } else {
        String exceptionType2 = o2.getExceptionType();
        if (exceptionType2 == null) {
            return -1;
        }
        return exceptionType1.compareTo(o2.getExceptionType());
    }
}
 
Example #18
Source File: BaseExceptionHandler.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
@Override public int compare(ExceptionHandler o1, ExceptionHandler o2) {
    String exceptionType1 = o1.getExceptionType();
    if (exceptionType1 == null) {
        if (o2.getExceptionType() != null) {
            return 1;
        }
        return 0;
    } else {
        String exceptionType2 = o2.getExceptionType();
        if (exceptionType2 == null) {
            return -1;
        }
        return exceptionType1.compareTo(o2.getExceptionType());
    }
}
 
Example #19
Source File: BaseExceptionHandler.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(@Nullable Object o) {
    if (o instanceof ExceptionHandler) {
        ExceptionHandler other = (ExceptionHandler)o;
        return Objects.equal(getExceptionType(), other.getExceptionType()) &&
               (getHandlerCodeAddress() == other.getHandlerCodeAddress());
    }
    return false;
}
 
Example #20
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 #21
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 #22
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 #23
Source File: ImmutableExceptionHandler.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
public static ImmutableExceptionHandler of(ExceptionHandler exceptionHandler) {
    if (exceptionHandler instanceof ImmutableExceptionHandler) {
        return (ImmutableExceptionHandler)exceptionHandler;
    }
    return new ImmutableExceptionHandler(
            exceptionHandler.getExceptionType(),
            exceptionHandler.getHandlerCodeAddress());
}
 
Example #24
Source File: ImmutableTryBlock.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
public ImmutableTryBlock(int startCodeAddress,
                         int codeUnitCount,
                         @Nullable List<? extends ExceptionHandler> exceptionHandlers) {
    this.startCodeAddress = startCodeAddress;
    this.codeUnitCount = codeUnitCount;
    this.exceptionHandlers = ImmutableExceptionHandler.immutableListOf(exceptionHandlers);
}
 
Example #25
Source File: BaseExceptionHandler.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(@Nullable Object o) {
    if (o instanceof ExceptionHandler) {
        ExceptionHandler other = (ExceptionHandler)o;
        return Objects.equal(getExceptionType(), other.getExceptionType()) &&
               (getHandlerCodeAddress() == other.getHandlerCodeAddress());
    }
    return false;
}
 
Example #26
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 #27
Source File: ImmutableTryBlock.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public ImmutableTryBlock(int startCodeAddress,
                         int codeUnitCount,
                         @Nullable List<? extends ExceptionHandler> exceptionHandlers) {
    this.startCodeAddress = startCodeAddress;
    this.codeUnitCount = codeUnitCount;
    this.exceptionHandlers = ImmutableExceptionHandler.immutableListOf(exceptionHandlers);
}
 
Example #28
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 #29
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 #30
Source File: ExceptionHandlerRewriter.java    From zjdroid with Apache License 2.0 4 votes vote down vote up
@Nonnull @Override public ExceptionHandler rewrite(@Nonnull ExceptionHandler value) {
    return new RewrittenExceptionHandler(value);
}