// Create or return HeapRef corresponding to this string public HeapReference createString(ClassFile stringType, ConstantPoolInfo_String stringConst) { // the reason this method exists is because I suck and can't seem // to properly output unicode characters without breaking everything string stringVal = stringConst.getValue(); if (stringMap[stringVal] == null){ HeapReference stringRef = newInstance(stringType); StackFrame stringFrame = new StackFrame(stringType.getConstantPool()); // Attempt to initialize using the character array MethodInfo stringInit = stringType.getMethod("<init>","([C)V"); if (stringInit == null){ throw new Exception("Unable to find init method for string"); } stringFrame.setMethod(stringType,stringInit); stringFrame.getLocalVariables()[0] = stringRef; stringFrame.getLocalVariables()[1] = stringConst; string printableChars = ""; //stringRef.isUnicode = true; // I suck char[] chars = stringVal.ToCharArray(); for (int i = 0; i < chars.Length; i++){ if (chars[i] > 13 && chars[i] < 127){ printableChars += chars[i]; } } if (log.IsDebugEnabled) log.DebugFormat("stringval1:{0}",printableChars); //if (log.IsDebugEnabled) log.DebugFormat(stringVal); // if (log.IsDebugEnabled) log.DebugFormat("U:" + stringRef.isUnicode); stringType.execute("<init>","([C)V",stringFrame); stringMap.Add(stringVal,stringRef); reverseStringMap.Add(stringRef,stringVal); } return (HeapReference) stringMap[stringVal]; }
public static ConstantPoolInfo readConstantPoolEntry(MSBBinaryReaderWrapper reader) { byte tag = reader.ReadByte(); ConstantPoolInfo info = null; switch (tag) { case TYPE_CLASS: { info = new ConstantPoolInfo_Class(tag); break; } case TYPE_METHOD_REF: { info = new ConstantPoolInfo_MethodRef(tag); break; } case TYPE_INTERFACE_METHOD_REF: { info = new ConstantPoolInfo_InterfaceMethodRef(tag); break; } case TYPE_FIELD_REF: { info = new ConstantPoolInfo_FieldRef(tag); break; } case TYPE_STRING: { info = new ConstantPoolInfo_String(tag); break; } case TYPE_UTF8: { info = new ConstantPoolInfo_UTF8(tag); break; } case TYPE_NAME_AND_TYPE: { info = new ConstantPoolInfo_NameAndType(tag); break; } case TYPE_INTEGER: { info = new ConstantPoolInfo_Integer(tag); break; } case TYPE_FLOAT: { info = new ConstantPoolInfo_Float(tag); break; } case TYPE_DOUBLE: { info = new ConstantPoolInfo_Double(tag); break; } case TYPE_LONG: { info = new ConstantPoolInfo_Long(tag); break; } default: { throw new UnknownConstantPoolTypeException(String.Format("Do not know how to parse {0}",tag)); } } info.parse(reader); return info; }