Refine search
private void readTimeDelta() throws IOException { int millisSinceLastSample = dataIn.readUnsignedShort(); if (millisSinceLastSample == INT_TIMESTAMP_TOKEN) { millisSinceLastSample = dataIn.readInt(); } this.currentDuration += millisSinceLastSample; this.startTimeStamp += millisSinceLastSample; }
private int readTimeDelta() throws IOException { int result = dataIn.readUnsignedShort(); if (result == INT_TIMESTAMP_TOKEN) { result = dataIn.readInt(); } return result; }
private int readResourceInstId() throws IOException { int token = dataIn.readUnsignedByte(); if (token <= MAX_BYTE_RESOURCE_INST_ID) { return token; } else if (token == ILLEGAL_RESOURCE_INST_ID_TOKEN) { return ILLEGAL_RESOURCE_INST_ID; } else if (token == SHORT_RESOURCE_INST_ID_TOKEN) { return dataIn.readUnsignedShort(); } else { /* token == INT_RESOURCE_INST_ID_TOKEN */ return dataIn.readInt(); } }
CompiledAttribute(DataInputStream source) throws IOException { int idx; attribute_name_index = source.readUnsignedShort(); attribute_length = source.readInt(); info = new byte[(int) attribute_length]; for (idx = 0; idx < attribute_length; idx++) { info[idx] = (byte) source.readUnsignedByte(); } }
private int readResourceInstId() throws IOException { int token = dataIn.readUnsignedByte(); if (token <= MAX_BYTE_RESOURCE_INST_ID) { return token; } else if (token == ILLEGAL_RESOURCE_INST_ID_TOKEN) { return ILLEGAL_RESOURCE_INST_ID; } else if (token == SHORT_RESOURCE_INST_ID_TOKEN) { return dataIn.readUnsignedShort(); } else { /* token == INT_RESOURCE_INST_ID_TOKEN */ return dataIn.readInt(); } }
CodeAttribute(ConstPool cp, int name_id, DataInputStream in) throws IOException { super(cp, name_id, (byte[])null); int attr_len = in.readInt(); maxStack = in.readUnsignedShort(); maxLocals = in.readUnsignedShort(); int code_len = in.readInt(); info = new byte[code_len]; in.readFully(info); exceptions = new ExceptionTable(cp, in); attributes = new ArrayList(); int num = in.readUnsignedShort(); for (int i = 0; i < num; ++i) attributes.add(AttributeInfo.read(cp, in)); }
/** get the major version of klass by loading the bytecode from source */ public static int getVersion(ClassLoader source,Class klass) { String cname = WeavingClassLoader.makeResourceName(klass.getName()); DataInputStream in = new DataInputStream(source.getResourceAsStream(cname)); try { int magic = in.readInt(); int minor = in.readUnsignedShort(); int major = in.readUnsignedShort(); in.close(); return major; } catch (IOException ex) { throw new RuntimeException(ex); } }
CodeAttribute(ConstPool cp, int name_id, DataInputStream in) throws IOException { super(cp, name_id, (byte[])null); @SuppressWarnings("unused") int attr_len = in.readInt(); maxStack = in.readUnsignedShort(); maxLocals = in.readUnsignedShort(); int code_len = in.readInt(); info = new byte[code_len]; in.readFully(info); exceptions = new ExceptionTable(cp, in); attributes = new ArrayList<AttributeInfo>(); int num = in.readUnsignedShort(); for (int i = 0; i < num; ++i) attributes.add(AttributeInfo.read(cp, in)); }
CompiledCode(byte[] code_block) throws IOException { int idx; ByteArrayInputStream bis = new ByteArrayInputStream(code_block); DataInputStream source = new DataInputStream(bis); max_stack = source.readUnsignedShort(); max_locals = source.readUnsignedShort(); code_length = source.readInt(); code = new byte[code_length]; source.read(code); exception_table_length = source.readUnsignedShort(); exceptionTable = new ExceptionTableEntry[exception_table_length]; for (int i = 0; i < exception_table_length; i++) { exceptionTable[i] = new ExceptionTableEntry(source); } attributes_count = source.readUnsignedShort(); attributes_info = new CompiledAttribute[attributes_count]; for (idx = 0; idx < attributes_count; idx++) { attributes_info[idx] = new CompiledAttribute(source); } }
CodeAttribute(ConstPool cp, int name_id, DataInputStream in) throws IOException { super(cp, name_id, (byte[])null); int attr_len = in.readInt(); maxStack = in.readUnsignedShort(); maxLocals = in.readUnsignedShort(); int code_len = in.readInt(); info = new byte[code_len]; in.readFully(info); exceptions = new ExceptionTable(cp, in); attributes = new ArrayList(); int num = in.readUnsignedShort(); for (int i = 0; i < num; ++i) attributes.add(AttributeInfo.read(cp, in)); }
CodeAttribute(ConstPool cp, int name_id, DataInputStream in) throws IOException { super(cp, name_id, (byte[])null); @SuppressWarnings("unused") int attr_len = in.readInt(); maxStack = in.readUnsignedShort(); maxLocals = in.readUnsignedShort(); int code_len = in.readInt(); info = new byte[code_len]; in.readFully(info); exceptions = new ExceptionTable(cp, in); attributes = new ArrayList<AttributeInfo>(); int num = in.readUnsignedShort(); for (int i = 0; i < num; ++i) attributes.add(AttributeInfo.read(cp, in)); }
import java.io.*; public class ClassVersionChecker { public static void main(String[] args) throws IOException { for (int i = 0; i < args.length; i++) checkClassVersion(args[i]); } private static void checkClassVersion(String filename) throws IOException { DataInputStream in = new DataInputStream (new FileInputStream(filename)); int magic = in.readInt(); if(magic != 0xcafebabe) { System.out.println(filename + " is not a valid class!");; } int minor = in.readUnsignedShort(); int major = in.readUnsignedShort(); System.out.println(filename + ": " + major + " . " + minor); in.close(); } }
minor = in.readUnsignedShort(); major = in.readUnsignedShort(); constPool = new ConstPool(in); accessFlags = in.readUnsignedShort(); thisClass = in.readUnsignedShort(); constPool.setThisClassInfo(thisClass); superClass = in.readUnsignedShort(); n = in.readUnsignedShort(); if (n == 0) interfaces = null; interfaces = new int[n]; for (i = 0; i < n; ++i) interfaces[i] = in.readUnsignedShort(); n = in.readUnsignedShort(); fields = new ArrayList(); for (i = 0; i < n; ++i) addField2(new FieldInfo(cp, in)); n = in.readUnsignedShort(); methods = new ArrayList(); for (i = 0; i < n; ++i) n = in.readUnsignedShort(); for (i = 0; i < n; ++i) addAttribute(AttributeInfo.read(cp, in));
/** * Get the class name of a class in an input stream. * * @param input an <code>InputStream</code> value * @return the name of the class * @exception IOException if an error occurs */ public static String getClassName(InputStream input) throws IOException { DataInputStream data = new DataInputStream(input); // verify this is a valid class file. int cookie = data.readInt(); if (cookie != CLASS_MAGIC_NUMBER) { return null; } /* int version = */ data.readInt(); // read the constant pool. ConstantPool constants = new ConstantPool(data); Object[] values = constants.values; // read access flags and class index. /* int accessFlags = */ data.readUnsignedShort(); int classIndex = data.readUnsignedShort(); Integer stringIndex = (Integer) values[classIndex]; return (String) values[stringIndex]; }
int idx; magic = (long) source.readInt(); minor_version = source.readUnsignedShort(); major_version = source.readUnsignedShort(); constant_pool_count = source.readUnsignedShort(); idx++; access_flags = source.readUnsignedShort(); this_class = source.readUnsignedShort(); super_class = source.readUnsignedShort(); interfaces_count = source.readUnsignedShort(); interfaces[idx] = source.readUnsignedShort(); fields_count = source.readUnsignedShort(); fields[idx] = new CompiledField(source, this); methods_count = source.readUnsignedShort(); methods[idx] = new CompiledMethod(source, this); attributes_count = source.readUnsignedShort();
minor = in.readUnsignedShort(); major = in.readUnsignedShort(); constPool = new ConstPool(in); accessFlags = in.readUnsignedShort(); thisClass = in.readUnsignedShort(); constPool.setThisClassInfo(thisClass); superClass = in.readUnsignedShort(); n = in.readUnsignedShort(); if (n == 0) interfaces = null; interfaces = new int[n]; for (i = 0; i < n; ++i) interfaces[i] = in.readUnsignedShort(); n = in.readUnsignedShort(); fields = new ArrayList<FieldInfo>(); for (i = 0; i < n; ++i) addField2(new FieldInfo(cp, in)); n = in.readUnsignedShort(); methods = new ArrayList<MethodInfo>(); for (i = 0; i < n; ++i) n = in.readUnsignedShort(); for (i = 0; i < n; ++i) addAttribute(AttributeInfo.read(cp, in));
minor = in.readUnsignedShort(); major = in.readUnsignedShort(); constPool = new ConstPool(in); accessFlags = in.readUnsignedShort(); thisClass = in.readUnsignedShort(); constPool.setThisClassInfo(thisClass); superClass = in.readUnsignedShort(); n = in.readUnsignedShort(); if (n == 0) interfaces = null; interfaces = new int[n]; for (i = 0; i < n; ++i) interfaces[i] = in.readUnsignedShort(); n = in.readUnsignedShort(); fields = new ArrayList<FieldInfo>(); for (i = 0; i < n; ++i) addField2(new FieldInfo(cp, in)); n = in.readUnsignedShort(); methods = new ArrayList<MethodInfo>(); for (i = 0; i < n; ++i) n = in.readUnsignedShort(); for (i = 0; i < n; ++i) addAttribute(AttributeInfo.read(cp, in));
minor = in.readUnsignedShort(); major = in.readUnsignedShort(); constPool = new ConstPool(in); accessFlags = in.readUnsignedShort(); thisClass = in.readUnsignedShort(); constPool.setThisClassInfo(thisClass); superClass = in.readUnsignedShort(); n = in.readUnsignedShort(); if (n == 0) interfaces = null; interfaces = new int[n]; for (i = 0; i < n; ++i) interfaces[i] = in.readUnsignedShort(); n = in.readUnsignedShort(); fields = new ArrayList(); for (i = 0; i < n; ++i) addField2(new FieldInfo(cp, in)); n = in.readUnsignedShort(); methods = new ArrayList(); for (i = 0; i < n; ++i) n = in.readUnsignedShort(); for (i = 0; i < n; ++i) addAttribute(AttributeInfo.read(cp, in));
DataInputStream classStream = new DataInputStream(stream); if (classStream.readInt() != CLASS_MAGIC) { throw new ClassFormatError( "No Magic Code Found - probably not a Java class file."); /* int minorVersion = */ classStream.readUnsignedShort(); /* int majorVersion = */ classStream.readUnsignedShort(); constantPool.resolve(); /* int accessFlags = */ classStream.readUnsignedShort(); int thisClassIndex = classStream.readUnsignedShort(); /* int superClassIndex = */ classStream.readUnsignedShort(); ClassCPInfo classInfo = (ClassCPInfo) constantPool.getEntry(thisClassIndex);
int constant_pool_count = dis.readUnsignedShort(); for (int i = 0; i < (constant_pool_count - 1); i++) { byte flag = dis.readByte(); switch (flag) { case 7://CONSTANT_Class: int z = dis.readUnsignedShort(); classIndex.put(i+1, z); break; break; case 1://CONSTANT_Utf8: int len = dis.readUnsignedShort(); byte[] data = new byte[len]; dis.readFully(data); int z = dis.readUnsignedShort(); meta.type = strs.get(classIndex.get(z)); if (meta.type != null) { int interfaces_count = dis.readUnsignedShort(); dis.skipBytes(2 * interfaces_count);//每个接口数据,是2个字节 int fields_count = dis.readUnsignedShort(); for (int i = 0; i < fields_count; i++) { dis.skipBytes(2); dis.skipBytes(2); dis.skipBytes(2); int attributes_count = dis.readUnsignedShort(); for (int j = 0; j < attributes_count; j++) {