public MethodInfo(MSBBinaryReaderWrapper reader,ConstantPoolInfo[] pool) { accessFlags = reader.ReadUInt16(); nameIndex = reader.ReadUInt16(); descriptorIndex = reader.ReadUInt16(); attributeCount = reader.ReadUInt16(); if (log.IsDebugEnabled) log.DebugFormat("Method = {0}{1}",pool[nameIndex - 1],pool[descriptorIndex-1]); attributes = new AttributeInfo[attributeCount]; for (int i = 0; i < attributeCount; i++) { attributes[i] = AttributeInfo.readAttributeInfo(reader,pool); if (attributes[i] is CodeAttribute){ methodCode = (CodeAttribute) attributes[i]; } } // if (log.IsDebugEnabled) log.DebugFormat("Name should be {0}",pool[nameIndex-1]); name = (ConstantPoolInfo_UTF8)pool[nameIndex - 1]; descriptor = (ConstantPoolInfo_UTF8)pool[descriptorIndex - 1]; // deriveParameterCount(); }
public override void parse(MSBBinaryReaderWrapper reader, ConstantPoolInfo[] pool) { UInt16 count = reader.ReadUInt16(); //if (log.IsDebugEnabled) log.DebugFormat("Will read in {0} line number mappings",count); for (int i = 0; i < count; i++){ UInt16 position = reader.ReadUInt16(); UInt16 lineNumber = reader.ReadUInt16(); lineNumberTable.Add(position,lineNumber); //if (log.IsDebugEnabled) log.DebugFormat("{0}->{1}",position,lineNumber); } }
public FieldInfo(MSBBinaryReaderWrapper reader,ConstantPoolInfo[] pool) { accessFlags = reader.ReadUInt16(); nameIndex = reader.ReadUInt16(); descriptorIndex = reader.ReadUInt16(); //if (log.IsDebugEnabled) log.DebugFormat("Name should be {0}",pool[nameIndex-1]); name = (ConstantPoolInfo_UTF8)pool[nameIndex - 1]; descriptor = (ConstantPoolInfo_UTF8)pool[descriptorIndex - 1]; attributeCount = reader.ReadUInt16(); attributes = new AttributeInfo[attributeCount]; for (int i = 0; i < attributeCount; i++) { attributes[i] = AttributeInfo.readAttributeInfo(reader,pool); } }
public override void parse(MSBBinaryReaderWrapper reader, ConstantPoolInfo[] pool) { innerClassCount = reader.ReadUInt16(); innerClasses = new InnerClassInfo[innerClassCount]; for (int i = 0; i < innerClassCount; i++){ innerClasses[i] = new InnerClassInfo(reader,pool); } }
public override void parse(MSBBinaryReaderWrapper reader, ConstantPoolInfo[] pool) { //base.parse(reader,pool); maxLength = reader.ReadUInt16(); maxLocals = reader.ReadUInt16(); codeLength = reader.ReadUInt32(); int readLength = 0; while (readLength < codeLength) { ByteCode bc = ByteCodeFactory.readByteCode(reader,pool,readLength); //code.Add(bc); //if (log.IsDebugEnabled) log.DebugFormat("{0}: {1}",readLength,bc); code.Add(readLength,bc); readLength += bc.getSize(); } exceptionTableLength = reader.ReadUInt16(); //if (log.IsDebugEnabled) log.DebugFormat("Exception table length: {0}",exceptionTableLength); exceptions = new ExceptionTableEntry[exceptionTableLength]; for (int i = 0; i < exceptionTableLength; i++){ exceptions[i] = new ExceptionTableEntry(reader); } attributeCount = reader.ReadUInt16(); //if (log.IsDebugEnabled) log.DebugFormat("Have {0} code attributes",attributeCount); attributes = new AttributeInfo[attributeCount]; for (int i = 0; i < attributeCount; i++) { attributes[i] = AttributeInfo.readAttributeInfo(reader,pool); if (attributes[i] is LineNumberTableAttribute){ lineNumbers = (LineNumberTableAttribute) attributes[i]; } } }
public InnerClassInfo(MSBBinaryReaderWrapper reader, ConstantPoolInfo[] pool) { UInt16 innerClassIndex = reader.ReadUInt16(); if (innerClassIndex != 0){ innerClass = (ConstantPoolInfo_Class) pool[innerClassIndex - 1]; } UInt16 outerClassIndex = reader.ReadUInt16(); if (outerClassIndex != 0){ outerClass = (ConstantPoolInfo_Class) pool[outerClassIndex - 1]; } UInt16 innerNameIndex = reader.ReadUInt16(); if (innerNameIndex != 0){ innerName = (ConstantPoolInfo_UTF8) pool[innerNameIndex - 1]; } accessFlags = reader.ReadUInt16(); }
public static AttributeInfo readAttributeInfo(MSBBinaryReaderWrapper reader, ConstantPoolInfo[] pool) { int nameIdx = reader.ReadUInt16(); //if (log.IsDebugEnabled) log.DebugFormat("Read Index {0}/{0:X}",nameIdx); if (pool[nameIdx - 1] is ConstantPoolInfo_UTF8){ ConstantPoolInfo_UTF8 utf8Name = (ConstantPoolInfo_UTF8)pool[nameIdx - 1]; //if (log.IsDebugEnabled) log.DebugFormat("Attribute name: {0}",utf8Name); String attrName = utf8Name.getUTF8String(); if (attrName.Equals("Code")) { return new CodeAttribute(utf8Name,reader,pool); } else if (attrName.Equals("InnerClasses")){ return new InnerClassesAttribute(utf8Name,reader,pool); } else if (attrName.Equals("ConstantValue")){ return new ConstantValueAttribute(utf8Name,reader,pool); } else if (attrName.Equals("LineNumberTable")){ return new LineNumberTableAttribute(utf8Name,reader,pool); } else if (attrName.Equals("SourceFile")){ return new SourceFileAttribute(utf8Name,reader,pool); } else if ( attrName.Equals("LocalVariableTable") || attrName.Equals("Signature") || attrName.Equals("Exceptions") || attrName.Equals("Deprecated") || attrName.Equals("EnclosingMethod") || attrName.Equals("RuntimeVisibleAnnotations")){ return new AttributeInfo(utf8Name,reader,pool); } else { throw new Exception("Don't know how to handle " + attrName); } } else { throw new Exception("Expected UTF8, instead got " + pool[nameIdx - 1]); } }
public override void parse(MSBBinaryReaderWrapper reader) { length = reader.ReadUInt16(); chars = ""; ArrayList codePointArr = new ArrayList(); byte[] originalChars = reader.getReader().ReadBytes(length); for (int i = 0; i < length; i++){ if ((originalChars[i] & 0x80) ==0){ // ascii char theChar = (char) originalChars[i]; chars += theChar.ToString(); // yeah bad codePointArr.Add((int)theChar); } else if ((originalChars[i] & 0xE0) == 0xC0){ // u0080-u07ff byte[] temp = new byte[2]; int val = (originalChars[i] & 0x1F) << 6; i++; val = val | (originalChars[i] & 0x3F); temp[0] = (byte)((val & 0x700) >> 8); temp[1] = (byte)(val & 0xFF); chars += BitConverter.ToChar(temp,0); isUnicode = true; codePointArr.Add(val); } else if ((originalChars[i] & 0xE0) == 0xE0){ // u0800-ffff byte[] temp = new byte[2]; int val = (originalChars[i] & 0xF) << 12; i++; val = val | (originalChars[i] & 0x3F); i++; val = val | (originalChars[i] & 0x3F); temp[0] = (byte)((val & 0xFF00) >> 8); temp[1] = (byte)(val & 0xFF); chars += BitConverter.ToChar(temp,0); isUnicode = true; codePointArr.Add(val); } } }
public override void parse(MSBBinaryReaderWrapper reader) { nameIndex = reader.ReadUInt16(); descriptorIndex = reader.ReadUInt16(); }
public override void parse(MSBBinaryReaderWrapper reader) { classIndex = reader.ReadUInt16(); nameAndTypeIndex = reader.ReadUInt16(); }
/** * Constructs new ClassFile from the given reader_ */ public ClassFile(BinaryReader reader_) { MSBBinaryReaderWrapper reader = new MSBBinaryReaderWrapper(reader_); System.UInt32 magic = reader.ReadUInt32(); // if it doesn't start with CLASS_FILE_MAGIC, it ain't even valid! if (magic != CLASS_FILE_MAGIC) { if (log.IsDebugEnabled) log.DebugFormat("Did not get proper magic..."); if (log.IsDebugEnabled) log.DebugFormat("{0:X}",CLASS_FILE_MAGIC); if (log.IsDebugEnabled) log.DebugFormat("{0:X}",magic); } else { minor = reader.ReadUInt16(); major = reader.ReadUInt16(); if (log.IsDebugEnabled) log.DebugFormat("{0}.{1}",major,minor); /** * The constant pool is the set of Strings, method names, class names and numbers * that will be referenced throughout the class */ constantPoolCount = (UInt16)(reader.ReadUInt16() - 1); // the value here is the maximum 1-indexed entry if (log.IsDebugEnabled) log.DebugFormat("{0} constant pool entries",constantPoolCount); constantPool = new ConstantPoolInfo[constantPoolCount]; /** * Pass 1 - Read in the actual entries */ for (int i = 0; i < constantPoolCount; i++) { constantPool[i] = ConstantPoolInfoFactory.readConstantPoolEntry(reader); // Long entries take up 2 constants if (constantPool[i] is ConstantPoolInfo_Long || constantPool[i] is ConstantPoolInfo_Double){ constantPool[i+1] = constantPool[i]; i++; } if (constantPool[i] is ConstantPoolInfo_UTF8){ //ConstantPoolInfo_UTF8 utf8 = (ConstantPoolInfo_UTF8) constantPool[i]; //if (log.IsDebugEnabled) log.DebugFormat("{0} Read {1}:{2}",i+1,constantPool[i].getName(),utf8.isUnicode ? "(UNICODE STRING)" : constantPool[i].ToString()); } else { //if (log.IsDebugEnabled) log.DebugFormat("{0} Read {1}:{2}",i+1,constantPool[i].getName(),constantPool[i].ToString()); } } /** * Pass 2 - Resolve constant pool references * / */ for (int i = 0; i < constantPool.Length; i++) { constantPool[i].resolve(constantPool); //if (log.IsDebugEnabled) log.DebugFormat("{0} Read {1}:{2}",i+1,constantPool[i].getName(),constantPool[i].ToString()); } accessFlags = reader.ReadUInt16(); UInt16 thisClassIndex = reader.ReadUInt16(); thisClass = (ConstantPoolInfo_Class)constantPool[thisClassIndex - 1]; if (log.IsDebugEnabled) log.DebugFormat("This class: {0}",constantPool[thisClass.getNameIndex()-1]); UInt16 superClassIndex = reader.ReadUInt16(); if (superClassIndex != 0){ superClass = (ConstantPoolInfo_Class)constantPool[superClassIndex - 1]; if (log.IsDebugEnabled) log.DebugFormat("Super class: {0}",constantPool[superClass.getNameIndex()-1]); } else if (! thisClass.getClassName().Equals("java/lang/Object")){ throw new Exception("Only Object can have no superclasses"); } interfaceCount = reader.ReadUInt16(); if (log.IsDebugEnabled) log.DebugFormat("{0} interfaces",interfaceCount); if (interfaceCount > 0) { interfaces = new ConstantPoolInfo_Class[interfaceCount]; for (int i = 0; i < interfaceCount; i++) { UInt16 ifaceIdx = reader.ReadUInt16(); interfaces[i] = (ConstantPoolInfo_Class) constantPool[ifaceIdx -1]; } } fieldCount = reader.ReadUInt16(); if (log.IsDebugEnabled) log.DebugFormat("{0} fields",fieldCount); if (fieldCount > 0){ fields = new FieldInfo[fieldCount]; for (int i = 0; i < fieldCount; i++){ fields[i] = new FieldInfo(reader,constantPool); if (fields[i].isStatic()){ staticFieldValues.Add(fields[i].GetFieldName(),NullValue.INSTANCE); } } } methodCount = reader.ReadUInt16(); if (log.IsDebugEnabled) log.DebugFormat("{0} methods",methodCount); if (methodCount > 0) { methods = new MethodInfo[methodCount]; for (int i = 0; i < methodCount; i++) { methods[i] = new MethodInfo(reader,constantPool); //methods[i].resolve(constantPool); //if (log.IsDebugEnabled) log.DebugFormat("Method: {0}",methods[i]); //if (log.IsDebugEnabled) log.DebugFormat("Storing under {0}",methods[i].getMethodName()+methods[i].getDescriptor()); methodsByName[methods[i].getMethodName()+methods[i].getDescriptor()] = methods[i]; methods[i].SetClassFile(this); } } attributeCount = reader.ReadUInt16(); if (log.IsDebugEnabled) log.DebugFormat("{0} attributes",attributeCount); attributes = new AttributeInfo[attributeCount]; for (int i = 0; i < attributeCount; i++) { attributes[i] = AttributeInfo.readAttributeInfo(reader,constantPool); if (log.IsDebugEnabled) log.DebugFormat(attributes[i].ToString()); } } }
public override void parse(MSBBinaryReaderWrapper reader, ConstantPoolInfo[] pool) { UInt16 valueRef = reader.ReadUInt16(); value = pool[valueRef - 1]; }
public ExceptionTableEntry(MSBBinaryReaderWrapper reader) { startPC = reader.ReadUInt16(); endPC = reader.ReadUInt16(); handlerPC = reader.ReadUInt16(); catchType = reader.ReadUInt16(); }