Beispiel #1
0
        // 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];
        }
Beispiel #2
0
        public HeapReference createString(ClassFile stringType, string stringVal)
        {
            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] = stringVal;
            //	stringRef.isUnicode = containsUnicode(stringVal);
                char[] chars = stringVal.ToCharArray();
                    string printableChars = "";

                //stringRef.isUnicode = true; // I suck

                for (int i = 0; i < chars.Length; i++){
                    if (chars[i] > 13 && chars[i] < 127){
                        printableChars += chars[i];
                    }
                }

                if (log.IsDebugEnabled) log.DebugFormat("stringval2:{0}",printableChars);

             	stringType.execute("<init>","([C)V",stringFrame);
                stringMap.Add(stringVal,stringRef);
                reverseStringMap.Add(stringRef,stringVal);
            }
            return (HeapReference) stringMap[stringVal];
        }