/** * @see IClassFileReader#isInterface() */ @Override public boolean isInterface() { return (getAccessFlags() & IModifierConstants.ACC_INTERFACE) != 0; } private boolean isModule() {
/** * @see IClassFileReader#isClass() */ public boolean isClass() { return !isInterface(); }
private char[] getConstantClassNameAt(byte[] classFileBytes, int[] constantPoolOffsets, int constantPoolIndex) { int utf8Offset = constantPoolOffsets[u2At(classFileBytes, constantPoolOffsets[constantPoolIndex] + 1, 0)]; return utf8At(classFileBytes, utf8Offset + 3, 0, u2At(classFileBytes, utf8Offset + 1, 0)); }
/** * @see IClassFileReader#isClass() */ @Override public boolean isClass() { return !(isInterface() || isModule()); }
int[] constantPoolOffsets; try { this.magicNumber = (int) u4At(classFileBytes, 0, 0); if (this.magicNumber != 0xCAFEBABE) { throw new ClassFormatException(ClassFormatException.INVALID_MAGIC_NUMBER); this.minorVersion = u2At(classFileBytes, 4, 0); this.majorVersion = u2At(classFileBytes, 6, 0); constantPoolCount = u2At(classFileBytes, 8, 0); int tag = u1At(classFileBytes, readOffset, 0); switch (tag) { case IConstantPoolConstant.CONSTANT_Utf8 : constantPoolOffsets[i] = readOffset; readOffset += u2At(classFileBytes, readOffset + 1, 0); readOffset += IConstantPoolConstant.CONSTANT_Utf8_SIZE; break; this.accessFlags = u2At(classFileBytes, readOffset, 0); readOffset += 2; this.classNameIndex = u2At(classFileBytes, readOffset, 0); this.className = getConstantClassNameAt(classFileBytes, constantPoolOffsets, this.classNameIndex); readOffset += 2; this.superclassNameIndex = u2At(classFileBytes, readOffset, 0); readOffset += 2;
/** * Create a default classfile reader, able to expose the internal representation of a given classfile * according to the decoding flag used to initialize the reader. * Answer null if the input stream contents cannot be retrieved * * The decoding flags are described in IClassFileReader. * * @param stream the given input stream to read * @param decodingFlag the flag used to decode the class file reader. * @return a default classfile reader * * @see IClassFileReader * @since 3.2 */ public static IClassFileReader createDefaultClassFileReader(InputStream stream, int decodingFlag) { try { return new ClassFileReader(Util.getInputStreamAsByteArray(stream, -1), decodingFlag); } catch(ClassFormatException e) { return null; } catch(IOException e) { return null; } }
int[] constantPoolOffsets; try { this.magicNumber = (int) u4At(classFileBytes, 0, 0); if (this.magicNumber != 0xCAFEBABE) { throw new ClassFormatException(ClassFormatException.INVALID_MAGIC_NUMBER); this.minorVersion = u2At(classFileBytes, 4, 0); this.majorVersion = u2At(classFileBytes, 6, 0); constantPoolCount = u2At(classFileBytes, 8, 0); int tag = u1At(classFileBytes, readOffset, 0); switch (tag) { case IConstantPoolConstant.CONSTANT_Utf8 : constantPoolOffsets[i] = readOffset; readOffset += u2At(classFileBytes, readOffset + 1, 0); readOffset += IConstantPoolConstant.CONSTANT_Utf8_SIZE; break; this.accessFlags = u2At(classFileBytes, readOffset, 0); readOffset += 2; this.classNameIndex = u2At(classFileBytes, readOffset, 0); this.className = getConstantClassNameAt(classFileBytes, constantPoolOffsets, this.classNameIndex); readOffset += 2; this.superclassNameIndex = u2At(classFileBytes, readOffset, 0); readOffset += 2;
/** * Create a default classfile reader, able to expose the internal representation of a given classfile * according to the decoding flag used to initialize the reader. * Answer null if the input stream contents cannot be retrieved * * The decoding flags are described in IClassFileReader. * * @param stream the given input stream to read * @param decodingFlag the flag used to decode the class file reader. * @return a default classfile reader * * @see IClassFileReader * @since 3.2 */ public static IClassFileReader createDefaultClassFileReader(InputStream stream, int decodingFlag) { try { return new ClassFileReader(Util.getInputStreamAsByteArray(stream, -1), decodingFlag); } catch(ClassFormatException e) { return null; } catch(IOException e) { return null; } }
/** * @see IClassFileReader#isClass() */ public boolean isClass() { return !(isInterface() || isModule()); }
int[] constantPoolOffsets; try { this.magicNumber = (int) u4At(classFileBytes, 0, 0); if (this.magicNumber != 0xCAFEBABE) { throw new ClassFormatException(ClassFormatException.INVALID_MAGIC_NUMBER); this.minorVersion = u2At(classFileBytes, 4, 0); this.majorVersion = u2At(classFileBytes, 6, 0); constantPoolCount = u2At(classFileBytes, 8, 0); int tag = u1At(classFileBytes, readOffset, 0); switch (tag) { case IConstantPoolConstant.CONSTANT_Utf8 : constantPoolOffsets[i] = readOffset; readOffset += u2At(classFileBytes, readOffset + 1, 0); readOffset += IConstantPoolConstant.CONSTANT_Utf8_SIZE; break; this.accessFlags = u2At(classFileBytes, readOffset, 0); readOffset += 2; this.classNameIndex = u2At(classFileBytes, readOffset, 0); this.className = getConstantClassNameAt(classFileBytes, constantPoolOffsets, this.classNameIndex); readOffset += 2; this.superclassNameIndex = u2At(classFileBytes, readOffset, 0); readOffset += 2;
/** * Create a default classfile reader, able to expose the internal representation of a given classfile * according to the decoding flag used to initialize the reader. * Answer null if the file named fileName doesn't represent a valid .class file. * The fileName has to be an absolute OS path to the given .class file. * * The decoding flags are described in IClassFileReader. * * @param fileName the name of the file to be read * @param decodingFlag the flag used to decode the class file reader. * @return a default classfile reader * * @see IClassFileReader */ public static IClassFileReader createDefaultClassFileReader(String fileName, int decodingFlag){ try { return new ClassFileReader(Util.getFileByteContent(new File(fileName)), decodingFlag); } catch(ClassFormatException e) { return null; } catch(IOException e) { return null; } }
private char[] getConstantClassNameAt(byte[] classFileBytes, int[] constantPoolOffsets, int constantPoolIndex) { int utf8Offset = constantPoolOffsets[u2At(classFileBytes, constantPoolOffsets[constantPoolIndex] + 1, 0)]; return utf8At(classFileBytes, utf8Offset + 3, 0, u2At(classFileBytes, utf8Offset + 1, 0)); }
/** * @see IClassFileReader#isInterface() */ public boolean isInterface() { return (getAccessFlags() & IModifierConstants.ACC_INTERFACE) != 0; } }
/** * @see IClassFileReader#isClass() */ public boolean isClass() { return !isInterface(); }
int[] constantPoolOffsets; try { this.magicNumber = (int) u4At(classFileBytes, 0, 0); if (this.magicNumber != 0xCAFEBABE) { throw new ClassFormatException(ClassFormatException.INVALID_MAGIC_NUMBER); this.minorVersion = u2At(classFileBytes, 4, 0); this.majorVersion = u2At(classFileBytes, 6, 0); constantPoolCount = u2At(classFileBytes, 8, 0); int tag = u1At(classFileBytes, readOffset, 0); switch (tag) { case IConstantPoolConstant.CONSTANT_Utf8 : constantPoolOffsets[i] = readOffset; readOffset += u2At(classFileBytes, readOffset + 1, 0); readOffset += IConstantPoolConstant.CONSTANT_Utf8_SIZE; break; this.accessFlags = u2At(classFileBytes, readOffset, 0); readOffset += 2; this.classNameIndex = u2At(classFileBytes, readOffset, 0); this.className = getConstantClassNameAt(classFileBytes, constantPoolOffsets, this.classNameIndex); readOffset += 2; this.superclassNameIndex = u2At(classFileBytes, readOffset, 0); readOffset += 2;
/** * Create a default classfile reader, able to expose the internal representation of a given classfile * according to the decoding flag used to initialize the reader. * Answer null if the input stream contents cannot be retrieved * * The decoding flags are described in IClassFileReader. * * @param stream the given input stream to read * @param decodingFlag the flag used to decode the class file reader. * @return a default classfile reader * * @see IClassFileReader * @since 3.2 */ public static IClassFileReader createDefaultClassFileReader(InputStream stream, int decodingFlag) { try { return new ClassFileReader(Util.getInputStreamAsByteArray(stream, -1), decodingFlag); } catch(ClassFormatException e) { return null; } catch(IOException e) { return null; } }
private char[] getConstantClassNameAt(byte[] classFileBytes, int[] constantPoolOffsets, int constantPoolIndex) { int utf8Offset = constantPoolOffsets[u2At(classFileBytes, constantPoolOffsets[constantPoolIndex] + 1, 0)]; return utf8At(classFileBytes, utf8Offset + 3, 0, u2At(classFileBytes, utf8Offset + 1, 0)); }
/** * @see IClassFileReader#isInterface() */ public boolean isInterface() { return (getAccessFlags() & IModifierConstants.ACC_INTERFACE) != 0; } private boolean isModule() {
/** * @see IClassFileReader#isClass() */ public boolean isClass() { return !isInterface(); }
int[] constantPoolOffsets; try { this.magicNumber = (int) u4At(classFileBytes, 0, 0); if (this.magicNumber != 0xCAFEBABE) { throw new ClassFormatException(ClassFormatException.INVALID_MAGIC_NUMBER); this.minorVersion = u2At(classFileBytes, 4, 0); this.majorVersion = u2At(classFileBytes, 6, 0); constantPoolCount = u2At(classFileBytes, 8, 0); int tag = u1At(classFileBytes, readOffset, 0); switch (tag) { case IConstantPoolConstant.CONSTANT_Utf8 : constantPoolOffsets[i] = readOffset; readOffset += u2At(classFileBytes, readOffset + 1, 0); readOffset += IConstantPoolConstant.CONSTANT_Utf8_SIZE; break; this.accessFlags = u2At(classFileBytes, readOffset, 0); readOffset += 2; this.classNameIndex = u2At(classFileBytes, readOffset, 0); this.className = getConstantClassNameAt(classFileBytes, constantPoolOffsets, this.classNameIndex); readOffset += 2; this.superclassNameIndex = u2At(classFileBytes, readOffset, 0); readOffset += 2;