예제 #1
0
파일: PyBytesObject.cs 프로젝트: zooba/PTVS
        public static PyBytesObject Create(DkmProcess process, AsciiString value) {
            var allocator = process.GetDataItem<PyObjectAllocator>();
            Debug.Assert(allocator != null);

            var result = allocator.Allocate<PyBytesObject>(value.Bytes.Length);
            result.ob_size.Write(value.Bytes.Length);
            process.WriteMemory(result.ob_sval.Address, value.Bytes);

            return result;
        }
예제 #2
0
        public static PyUnicodeObject27 Create(DkmProcess process, string value) {
            // Allocate string buffer together with the object itself in a single block.
            var allocator = process.GetDataItem<PyObjectAllocator>();
            Debug.Assert(allocator != null);

            var result = allocator.Allocate<PyUnicodeObject27>(value.Length * 2);
            result.length.Write(value.Length);

            var str = result.Address.OffsetBy(StructProxy.SizeOf<PyUnicodeObject27>(process));
            result.str.Raw.Write(str);

            var buf = Encoding.Unicode.GetBytes(value);
            process.WriteMemory(str, buf);

            return result;
        }
예제 #3
0
        public static PyUnicodeObject33 Create(DkmProcess process, string value) {
            var allocator = process.GetDataItem<PyObjectAllocator>();
            Debug.Assert(allocator != null);

            var result = allocator.Allocate<PyUnicodeObject33>(value.Length * sizeof(char));

            result._asciiObject.hash.Write(-1);
            result._asciiObject.length.Write(value.Length);
            result._compactObject.wstr_length.Write(value.Length);

            var state = new State {
                interned = Interned.SSTATE_NOT_INTERNED,
                kind = PyUnicode_Kind.PyUnicode_2BYTE_KIND,
                compact = true,
                ascii = false,
                ready = true
            };
            result._asciiObject.state.Write((byte)state);

            ulong dataPtr = result.Address.OffsetBy(StructProxy.SizeOf<PyCompactUnicodeObject>(process));
            result._asciiObject.wstr.Write(dataPtr);
            process.WriteMemory(dataPtr, Encoding.Unicode.GetBytes(value));

            return result;
        }