org.jf.util.ExceptionWithContext Java Examples
The following examples show how to use
org.jf.util.ExceptionWithContext.
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: DebugMethodItem.java From ZjDroid with Apache License 2.0 | 6 votes |
public static DebugMethodItem build(RegisterFormatter registerFormatter, DebugItem debugItem) { int codeAddress = debugItem.getCodeAddress(); switch (debugItem.getDebugItemType()) { case DebugItemType.START_LOCAL: return new StartLocalMethodItem(codeAddress, -1, registerFormatter, (StartLocal)debugItem); case DebugItemType.END_LOCAL: return new EndLocalMethodItem(codeAddress, -1, registerFormatter, (EndLocal)debugItem); case DebugItemType.RESTART_LOCAL: return new RestartLocalMethodItem(codeAddress, -1, registerFormatter, (RestartLocal)debugItem); case DebugItemType.EPILOGUE_BEGIN: return new BeginEpilogueMethodItem(codeAddress, -4); case DebugItemType.PROLOGUE_END: return new EndPrologueMethodItem(codeAddress, -4); case DebugItemType.SET_SOURCE_FILE: return new SetSourceFileMethodItem(codeAddress, -3, (SetSourceFile)debugItem); case DebugItemType.LINE_NUMBER: return new LineNumberMethodItem(codeAddress, -2, (LineNumber)debugItem); default: throw new ExceptionWithContext("Invalid debug item type: %d", debugItem.getDebugItemType()); } }
Example #2
Source File: RegisterType.java From zjdroid with Apache License 2.0 | 6 votes |
@Nonnull public static RegisterType getRegisterType(@Nonnull ClassPath classPath, @Nonnull CharSequence type) { switch (type.charAt(0)) { case 'Z': return BOOLEAN_TYPE; case 'B': return BYTE_TYPE; case 'S': return SHORT_TYPE; case 'C': return CHAR_TYPE; case 'I': return INTEGER_TYPE; case 'F': return FLOAT_TYPE; case 'J': return LONG_LO_TYPE; case 'D': return DOUBLE_LO_TYPE; case 'L': case '[': return getRegisterType(REFERENCE, classPath.getClass(type)); default: throw new ExceptionWithContext("Invalid type: " + type); } }
Example #3
Source File: RegisterType.java From HeyGirl with Apache License 2.0 | 6 votes |
@Nonnull public static RegisterType getWideRegisterType(@Nonnull CharSequence type, boolean firstRegister) { switch (type.charAt(0)) { case 'J': if (firstRegister) { return getRegisterType(LONG_LO, null); } else { return getRegisterType(LONG_HI, null); } case 'D': if (firstRegister) { return getRegisterType(DOUBLE_LO, null); } else { return getRegisterType(DOUBLE_HI, null); } default: throw new ExceptionWithContext("Cannot use this method for narrow register type: %s", type); } }
Example #4
Source File: ArrayProto.java From HeyGirl with Apache License 2.0 | 6 votes |
public ArrayProto(@Nonnull ClassPath classPath, @Nonnull String type) { this.classPath = classPath; int i=0; while (type.charAt(i) == '[') { i++; if (i == type.length()) { throw new ExceptionWithContext("Invalid array type: %s", type); } } if (i == 0) { throw new ExceptionWithContext("Invalid array type: %s", type); } dimensions = i; elementType = type.substring(i); }
Example #5
Source File: ImmutableReferenceFactory.java From ZjDroid with Apache License 2.0 | 6 votes |
@Nonnull public static ImmutableReference of(Reference reference) { if (reference instanceof StringReference) { return ImmutableStringReference.of((StringReference)reference); } if (reference instanceof TypeReference) { return ImmutableTypeReference.of((TypeReference)reference); } if (reference instanceof FieldReference) { return ImmutableFieldReference.of((FieldReference)reference); } if (reference instanceof MethodReference) { return ImmutableMethodReference.of((MethodReference)reference); } throw new ExceptionWithContext("Invalid reference type"); }
Example #6
Source File: ImmutableReferenceFactory.java From HeyGirl with Apache License 2.0 | 6 votes |
@Nonnull public static ImmutableReference of(Reference reference) { if (reference instanceof StringReference) { return ImmutableStringReference.of((StringReference)reference); } if (reference instanceof TypeReference) { return ImmutableTypeReference.of((TypeReference)reference); } if (reference instanceof FieldReference) { return ImmutableFieldReference.of((FieldReference)reference); } if (reference instanceof MethodReference) { return ImmutableMethodReference.of((MethodReference)reference); } throw new ExceptionWithContext("Invalid reference type"); }
Example #7
Source File: ImmutableDebugItem.java From ZjDroid with Apache License 2.0 | 6 votes |
@Nonnull public static ImmutableDebugItem of(DebugItem debugItem) { if (debugItem instanceof ImmutableDebugItem) { return (ImmutableDebugItem)debugItem; } switch (debugItem.getDebugItemType()) { case DebugItemType.START_LOCAL: return ImmutableStartLocal.of((StartLocal)debugItem); case DebugItemType.END_LOCAL: return ImmutableEndLocal.of((EndLocal)debugItem); case DebugItemType.RESTART_LOCAL: return ImmutableRestartLocal.of((RestartLocal)debugItem); case DebugItemType.PROLOGUE_END: return ImmutablePrologueEnd.of((PrologueEnd)debugItem); case DebugItemType.EPILOGUE_BEGIN: return ImmutableEpilogueBegin.of((EpilogueBegin)debugItem); case DebugItemType.SET_SOURCE_FILE: return ImmutableSetSourceFile.of((SetSourceFile)debugItem); case DebugItemType.LINE_NUMBER: return ImmutableLineNumber.of((LineNumber)debugItem); default: throw new ExceptionWithContext("Invalid debug item type: %d", debugItem.getDebugItemType()); } }
Example #8
Source File: ImmutableDebugItem.java From HeyGirl with Apache License 2.0 | 6 votes |
@Nonnull public static ImmutableDebugItem of(DebugItem debugItem) { if (debugItem instanceof ImmutableDebugItem) { return (ImmutableDebugItem)debugItem; } switch (debugItem.getDebugItemType()) { case DebugItemType.START_LOCAL: return ImmutableStartLocal.of((StartLocal)debugItem); case DebugItemType.END_LOCAL: return ImmutableEndLocal.of((EndLocal)debugItem); case DebugItemType.RESTART_LOCAL: return ImmutableRestartLocal.of((RestartLocal)debugItem); case DebugItemType.PROLOGUE_END: return ImmutablePrologueEnd.of((PrologueEnd)debugItem); case DebugItemType.EPILOGUE_BEGIN: return ImmutableEpilogueBegin.of((EpilogueBegin)debugItem); case DebugItemType.SET_SOURCE_FILE: return ImmutableSetSourceFile.of((SetSourceFile)debugItem); case DebugItemType.LINE_NUMBER: return ImmutableLineNumber.of((LineNumber)debugItem); default: throw new ExceptionWithContext("Invalid debug item type: %d", debugItem.getDebugItemType()); } }
Example #9
Source File: BuilderEncodedValues.java From zjdroid with Apache License 2.0 | 6 votes |
@Nonnull public static BuilderEncodedValue defaultValueForType(String type) { switch (type.charAt(0)) { case 'Z': return BuilderBooleanEncodedValue.FALSE_VALUE; case 'B': return new BuilderByteEncodedValue((byte)0); case 'S': return new BuilderShortEncodedValue((short)0); case 'C': return new BuilderCharEncodedValue((char)0); case 'I': return new BuilderIntEncodedValue(0); case 'J': return new BuilderLongEncodedValue(0); case 'F': return new BuilderFloatEncodedValue(0); case 'D': return new BuilderDoubleEncodedValue(0); case 'L': case '[': return BuilderNullEncodedValue.INSTANCE; default: throw new ExceptionWithContext("Unrecognized type: %s", type); } }
Example #10
Source File: RegisterType.java From HeyGirl with Apache License 2.0 | 6 votes |
@Nonnull public static RegisterType getRegisterType(@Nonnull ClassPath classPath, @Nonnull CharSequence type) { switch (type.charAt(0)) { case 'Z': return BOOLEAN_TYPE; case 'B': return BYTE_TYPE; case 'S': return SHORT_TYPE; case 'C': return CHAR_TYPE; case 'I': return INTEGER_TYPE; case 'F': return FLOAT_TYPE; case 'J': return LONG_LO_TYPE; case 'D': return DOUBLE_LO_TYPE; case 'L': case '[': return getRegisterType(REFERENCE, classPath.getClass(type)); default: throw new ExceptionWithContext("Invalid type: " + type); } }
Example #11
Source File: DexBackedDexFile.java From HeyGirl with Apache License 2.0 | 6 votes |
private static void verifyMagicAndByteOrder(@Nonnull byte[] buf, int offset) { if (!HeaderItem.verifyMagic(buf, offset)) { StringBuilder sb = new StringBuilder("Invalid magic value:"); for (int i=0; i<8; i++) { sb.append(String.format(" %02x", buf[i])); } throw new NotADexFile(sb.toString()); } int endian = HeaderItem.getEndian(buf, offset); if (endian == HeaderItem.BIG_ENDIAN_TAG) { throw new ExceptionWithContext("Big endian dex files are not currently supported"); } if (endian != HeaderItem.LITTLE_ENDIAN_TAG) { throw new ExceptionWithContext("Invalid endian tag: 0x%x", endian); } }
Example #12
Source File: ImmutableEncodedValueFactory.java From HeyGirl with Apache License 2.0 | 6 votes |
@Nonnull public static EncodedValue defaultValueForType(String type) { switch (type.charAt(0)) { case 'Z': return ImmutableBooleanEncodedValue.FALSE_VALUE; case 'B': return new ImmutableByteEncodedValue((byte)0); case 'S': return new ImmutableShortEncodedValue((short)0); case 'C': return new ImmutableCharEncodedValue((char)0); case 'I': return new ImmutableIntEncodedValue(0); case 'J': return new ImmutableLongEncodedValue(0); case 'F': return new ImmutableFloatEncodedValue(0); case 'D': return new ImmutableDoubleEncodedValue(0); case 'L': case '[': return ImmutableNullEncodedValue.INSTANCE; default: throw new ExceptionWithContext("Unrecognized type: %s", type); } }
Example #13
Source File: DebugWriter.java From zjdroid with Apache License 2.0 | 6 votes |
public void writeLineNumber(int codeAddress, int lineNumber) throws IOException { int lineDelta = lineNumber - currentLine; int addressDelta = codeAddress - currentAddress; if (addressDelta < 0) { throw new ExceptionWithContext("debug info items must have non-decreasing code addresses"); } if (lineDelta < -4 || lineDelta > 10) { writeAdvanceLine(lineNumber); lineDelta = 0; } // no else is intentional here. we might need to advance the PC as well as the line if ((lineDelta < 2 && addressDelta > 16) || (lineDelta > 1 && addressDelta > 15)) { writeAdvancePC(codeAddress); addressDelta = 0; } // we need to emit the special opcode even if both lineDelta and addressDelta are 0, otherwise a positions // entry isn't generated writeSpecialOpcode(lineDelta, addressDelta); }
Example #14
Source File: ImmutableReferenceFactory.java From zjdroid with Apache License 2.0 | 6 votes |
@Nonnull public static ImmutableReference of(Reference reference) { if (reference instanceof StringReference) { return ImmutableStringReference.of((StringReference)reference); } if (reference instanceof TypeReference) { return ImmutableTypeReference.of((TypeReference)reference); } if (reference instanceof FieldReference) { return ImmutableFieldReference.of((FieldReference)reference); } if (reference instanceof MethodReference) { return ImmutableMethodReference.of((MethodReference)reference); } throw new ExceptionWithContext("Invalid reference type"); }
Example #15
Source File: ImmutableEncodedValueFactory.java From zjdroid with Apache License 2.0 | 6 votes |
@Nonnull public static EncodedValue defaultValueForType(String type) { switch (type.charAt(0)) { case 'Z': return ImmutableBooleanEncodedValue.FALSE_VALUE; case 'B': return new ImmutableByteEncodedValue((byte)0); case 'S': return new ImmutableShortEncodedValue((short)0); case 'C': return new ImmutableCharEncodedValue((char)0); case 'I': return new ImmutableIntEncodedValue(0); case 'J': return new ImmutableLongEncodedValue(0); case 'F': return new ImmutableFloatEncodedValue(0); case 'D': return new ImmutableDoubleEncodedValue(0); case 'L': case '[': return ImmutableNullEncodedValue.INSTANCE; default: throw new ExceptionWithContext("Unrecognized type: %s", type); } }
Example #16
Source File: RegisterType.java From ZjDroid with Apache License 2.0 | 6 votes |
@Nonnull public static RegisterType getRegisterType(@Nonnull ClassPath classPath, @Nonnull CharSequence type) { switch (type.charAt(0)) { case 'Z': return BOOLEAN_TYPE; case 'B': return BYTE_TYPE; case 'S': return SHORT_TYPE; case 'C': return CHAR_TYPE; case 'I': return INTEGER_TYPE; case 'F': return FLOAT_TYPE; case 'J': return LONG_LO_TYPE; case 'D': return DOUBLE_LO_TYPE; case 'L': case '[': return getRegisterType(REFERENCE, classPath.getClass(type)); default: throw new ExceptionWithContext("Invalid type: " + type); } }
Example #17
Source File: DexBackedDexFile.java From ZjDroid with Apache License 2.0 | 6 votes |
private static void verifyMagicAndByteOrder(@Nonnull byte[] buf, int offset) { if (!HeaderItem.verifyMagic(buf, offset)) { StringBuilder sb = new StringBuilder("Invalid magic value:"); for (int i=0; i<8; i++) { sb.append(String.format(" %02x", buf[i])); } throw new NotADexFile(sb.toString()); } int endian = HeaderItem.getEndian(buf, offset); if (endian == HeaderItem.BIG_ENDIAN_TAG) { throw new ExceptionWithContext("Big endian dex files are not currently supported"); } if (endian != HeaderItem.LITTLE_ENDIAN_TAG) { throw new ExceptionWithContext("Invalid endian tag: 0x%x", endian); } }
Example #18
Source File: ImmutableEncodedValueFactory.java From ZjDroid with Apache License 2.0 | 6 votes |
@Nonnull public static EncodedValue defaultValueForType(String type) { switch (type.charAt(0)) { case 'Z': return ImmutableBooleanEncodedValue.FALSE_VALUE; case 'B': return new ImmutableByteEncodedValue((byte)0); case 'S': return new ImmutableShortEncodedValue((short)0); case 'C': return new ImmutableCharEncodedValue((char)0); case 'I': return new ImmutableIntEncodedValue(0); case 'J': return new ImmutableLongEncodedValue(0); case 'F': return new ImmutableFloatEncodedValue(0); case 'D': return new ImmutableDoubleEncodedValue(0); case 'L': case '[': return ImmutableNullEncodedValue.INSTANCE; default: throw new ExceptionWithContext("Unrecognized type: %s", type); } }
Example #19
Source File: DebugMethodItem.java From atlas with Apache License 2.0 | 6 votes |
public static DebugMethodItem build(RegisterFormatter registerFormatter, DebugItem debugItem) { int codeAddress = debugItem.getCodeAddress(); switch (debugItem.getDebugItemType()) { case DebugItemType.START_LOCAL: return new StartLocalMethodItem(codeAddress, -1, registerFormatter, (StartLocal)debugItem); case DebugItemType.END_LOCAL: return new EndLocalMethodItem(codeAddress, -1, registerFormatter, (EndLocal)debugItem); case DebugItemType.RESTART_LOCAL: return new RestartLocalMethodItem(codeAddress, -1, registerFormatter, (RestartLocal)debugItem); case DebugItemType.EPILOGUE_BEGIN: return new BeginEpilogueMethodItem(codeAddress, -4); case DebugItemType.PROLOGUE_END: return new EndPrologueMethodItem(codeAddress, -4); case DebugItemType.SET_SOURCE_FILE: return new SetSourceFileMethodItem(codeAddress, -3, (SetSourceFile)debugItem); case DebugItemType.LINE_NUMBER: return new LineNumberMethodItem(codeAddress, -2, (LineNumber)debugItem); default: throw new ExceptionWithContext("Invalid debug item type: %d", debugItem.getDebugItemType()); } }
Example #20
Source File: DexBackedDexFile.java From ZjDroid with Apache License 2.0 | 6 votes |
private static void verifyMagicAndByteOrder(@Nonnull byte[] buf, int offset) { if (!HeaderItem.verifyMagic(buf, offset)) { StringBuilder sb = new StringBuilder("Invalid magic value:"); for (int i=0; i<8; i++) { sb.append(String.format(" %02x", buf[i])); } throw new NotADexFile(sb.toString()); } int endian = HeaderItem.getEndian(buf, offset); if (endian == HeaderItem.BIG_ENDIAN_TAG) { throw new ExceptionWithContext("Big endian dex files are not currently supported"); } if (endian != HeaderItem.LITTLE_ENDIAN_TAG) { throw new ExceptionWithContext("Invalid endian tag: 0x%x", endian); } }
Example #21
Source File: ImmutableReferenceFactory.java From HeyGirl with Apache License 2.0 | 5 votes |
@Nonnull public static ImmutableReference of(int referenceType, Reference reference) { switch (referenceType) { case ReferenceType.STRING: return ImmutableStringReference.of((StringReference)reference); case ReferenceType.TYPE: return ImmutableTypeReference.of((TypeReference)reference); case ReferenceType.FIELD: return ImmutableFieldReference.of((FieldReference)reference); case ReferenceType.METHOD: return ImmutableMethodReference.of((MethodReference)reference); } throw new ExceptionWithContext("Invalid reference type: %d", referenceType); }
Example #22
Source File: StringPool.java From zjdroid with Apache License 2.0 | 5 votes |
@Override public int getItemIndex(@Nonnull StringReference key) { Integer index = internedItems.get(key.toString()); if (index == null) { throw new ExceptionWithContext("Item not found.: %s", key.toString()); } return index; }
Example #23
Source File: StringTypeBasePool.java From zjdroid with Apache License 2.0 | 5 votes |
@Override public int getItemIndex(@Nonnull CharSequence key) { Integer index = internedItems.get(key.toString()); if (index == null) { throw new ExceptionWithContext("Item not found.: %s", key.toString()); } return index; }
Example #24
Source File: DexDataWriter.java From zjdroid with Apache License 2.0 | 5 votes |
public void writeUshort(int value) throws IOException { if (value < 0 || value > 0xFFFF) { throw new ExceptionWithContext("Unsigned short value out of range: %d", value); } write(value); write(value >> 8); }
Example #25
Source File: BaseOffsetPool.java From HeyGirl with Apache License 2.0 | 5 votes |
@Override public int getItemOffset(@Nonnull Key key) { Integer offset = internedItems.get(key); if (offset == null) { throw new ExceptionWithContext("Item not found.: %s", getItemString(key)); } return offset; }
Example #26
Source File: StringPool.java From ZjDroid with Apache License 2.0 | 5 votes |
@Override public int getItemIndex(@Nonnull StringReference key) { Integer index = internedItems.get(key.toString()); if (index == null) { throw new ExceptionWithContext("Item not found.: %s", key.toString()); } return index; }
Example #27
Source File: DexBackedReference.java From zjdroid with Apache License 2.0 | 5 votes |
public static Reference makeReference(@Nonnull DexBackedDexFile dexFile, int referenceType, int referenceIndex) { switch (referenceType) { case ReferenceType.STRING: return new DexBackedStringReference(dexFile, referenceIndex); case ReferenceType.TYPE: return new DexBackedTypeReference(dexFile, referenceIndex); case ReferenceType.METHOD: return new DexBackedMethodReference(dexFile, referenceIndex); case ReferenceType.FIELD: return new DexBackedFieldReference(dexFile, referenceIndex); default: throw new ExceptionWithContext("Invalid reference type: %d", referenceType); } }
Example #28
Source File: VerificationError.java From ZjDroid with Apache License 2.0 | 5 votes |
public static int getVerificationError(String verificationError) { Integer ret = verificationErrorNames.get(verificationError); if (ret == null) { throw new ExceptionWithContext("Invalid verification error: %s", verificationError); } return ret; }
Example #29
Source File: BuilderContext.java From zjdroid with Apache License 2.0 | 5 votes |
@Nonnull private BuilderEncodedValue internEncodedValue(@Nonnull EncodedValue encodedValue) { switch (encodedValue.getValueType()) { case ValueType.ANNOTATION: return internAnnotationEncodedValue((AnnotationEncodedValue)encodedValue); case ValueType.ARRAY: return internArrayEncodedValue((ArrayEncodedValue)encodedValue); case ValueType.BOOLEAN: boolean value = ((BooleanEncodedValue)encodedValue).getValue(); return value?BuilderBooleanEncodedValue.TRUE_VALUE:BuilderBooleanEncodedValue.FALSE_VALUE; case ValueType.BYTE: return new BuilderByteEncodedValue(((ByteEncodedValue)encodedValue).getValue()); case ValueType.CHAR: return new BuilderCharEncodedValue(((CharEncodedValue)encodedValue).getValue()); case ValueType.DOUBLE: return new BuilderDoubleEncodedValue(((DoubleEncodedValue)encodedValue).getValue()); case ValueType.ENUM: return internEnumEncodedValue((EnumEncodedValue)encodedValue); case ValueType.FIELD: return internFieldEncodedValue((FieldEncodedValue)encodedValue); case ValueType.FLOAT: return new BuilderFloatEncodedValue(((FloatEncodedValue)encodedValue).getValue()); case ValueType.INT: return new BuilderIntEncodedValue(((IntEncodedValue)encodedValue).getValue()); case ValueType.LONG: return new BuilderLongEncodedValue(((LongEncodedValue)encodedValue).getValue()); case ValueType.METHOD: return internMethodEncodedValue((MethodEncodedValue)encodedValue); case ValueType.NULL: return BuilderNullEncodedValue.INSTANCE; case ValueType.SHORT: return new BuilderShortEncodedValue(((ShortEncodedValue)encodedValue).getValue()); case ValueType.STRING: return internStringEncodedValue((StringEncodedValue)encodedValue); case ValueType.TYPE: return internTypeEncodedValue((TypeEncodedValue)encodedValue); default: throw new ExceptionWithContext("Unexpected encoded value type: %d", encodedValue.getValueType()); } }
Example #30
Source File: AnnotationVisibility.java From ZjDroid with Apache License 2.0 | 5 votes |
public static int getVisibility(String visibility) { visibility = visibility.toLowerCase(); if (visibility.equals("build")) { return BUILD; } if (visibility.equals("runtime")) { return RUNTIME; } if (visibility.equals("system")) { return SYSTEM; } throw new ExceptionWithContext("Invalid annotation visibility: %s", visibility); }