Exemplo n.º 1
0
            internal static UInt32 GetInlineField(byte *pFields, EETypeOptionalFieldTag eTag, UInt32 uiDefaultValue)
            {
                if (pFields == null)
                {
                    return(uiDefaultValue);
                }

                bool isLastField = false;

                while (!isLastField)
                {
                    byte fieldHeader = NativePrimitiveDecoder.ReadUInt8(ref pFields);
                    isLastField = (fieldHeader & 0x80) != 0;
                    EETypeOptionalFieldTag eCurrentTag = (EETypeOptionalFieldTag)(fieldHeader & 0x7f);
                    UInt32 uiCurrentValue = NativePrimitiveDecoder.DecodeUnsigned(ref pFields);

                    // If we found a tag match return the current value.
                    if (eCurrentTag == eTag)
                    {
                        return(uiCurrentValue);
                    }
                }

                // Reached end of stream without getting a match. Field is not present so return default value.
                return(uiDefaultValue);
            }
Exemplo n.º 2
0
        private static unsafe string GetStringFromMemoryInNativeFormat(IntPtr pointerToDataStream)
        {
            byte *dataStream = (byte *)pointerToDataStream.ToPointer();
            uint  stringLen  = NativePrimitiveDecoder.DecodeUnsigned(ref dataStream);

            return(Encoding.UTF8.GetString(dataStream, checked ((int)stringLen)));
        }
Exemplo n.º 3
0
        private static unsafe void InitializeStringTable()
        {
            int    length       = 0;
            IntPtr strEETypePtr = GetModuleSection((int)ModuleSectionIds.StringEETypePtr, out length);

            Contract.Assert(length == IntPtr.Size);

            IntPtr strTableStart = GetModuleSection((int)ModuleSectionIds.StringFixupStart, out length);

            Contract.Assert(length % IntPtr.Size == 0);

            IntPtr strTableEnd = (IntPtr)((byte *)strTableStart + length);

            for (IntPtr *tab = (IntPtr *)strTableStart; tab < (IntPtr *)strTableEnd; tab++)
            {
                byte *bytes = (byte *)*tab;
                int   len   = (int)NativePrimitiveDecoder.DecodeUnsigned(ref bytes);
                int   count = LowLevelUTF8Encoding.GetCharCount(bytes, len);
                Contract.Assert(count >= 0);

                string newStr = RuntimeImports.RhNewArrayAsString(new EETypePtr(strEETypePtr), count);
                fixed(char *dest = newStr)
                {
                    int newCount = LowLevelUTF8Encoding.GetChars(bytes, len, dest, count);

                    Contract.Assert(newCount == count);
                }

                GCHandle handle = GCHandle.Alloc(newStr);
                *        tab    = (IntPtr)handle;
            }
        }
Exemplo n.º 4
0
        internal OptionalFieldsRuntimeBuilder(byte *pInitializeFromOptionalFields = null)
        {
            if (pInitializeFromOptionalFields == null)
            {
                return;
            }

            bool isLastField = false;

            while (!isLastField)
            {
                byte fieldHeader = NativePrimitiveDecoder.ReadUInt8(ref pInitializeFromOptionalFields);
                isLastField = (fieldHeader & 0x80) != 0;
                EETypeOptionalFieldTag eCurrentTag = (EETypeOptionalFieldTag)(fieldHeader & 0x7f);
                UInt32 uiCurrentValue = NativePrimitiveDecoder.DecodeUnsigned(ref pInitializeFromOptionalFields);

                _rgFields[(int)eCurrentTag].m_fPresent = true;
                _rgFields[(int)eCurrentTag].m_uiValue  = uiCurrentValue;
            }
        }
Exemplo n.º 5
0
        private static unsafe void InitializeStringTable(IntPtr stringTableStart, int length)
        {
            IntPtr stringTableEnd = (IntPtr)((byte *)stringTableStart + length);

            for (IntPtr *tab = (IntPtr *)stringTableStart; tab < (IntPtr *)stringTableEnd; tab++)
            {
                byte *bytes = (byte *)*tab;
                int   len   = (int)NativePrimitiveDecoder.DecodeUnsigned(ref bytes);
                int   count = LowLevelUTF8Encoding.GetCharCount(bytes, len);
                Contract.Assert(count >= 0);

                string newStr = RuntimeImports.RhNewArrayAsString(EETypePtr.EETypePtrOf <string>(), count);
                fixed(char *dest = newStr)
                {
                    int newCount = LowLevelUTF8Encoding.GetChars(bytes, len, dest, count);

                    Contract.Assert(newCount == count);
                }

                GCHandle handle = GCHandle.Alloc(newStr);
                *        tab    = (IntPtr)handle;
            }
        }