当前位置: 首页>>代码示例>>C#>>正文


C# MetadataReader.GetBlobBytes方法代码示例

本文整理汇总了C#中MetadataReader.GetBlobBytes方法的典型用法代码示例。如果您正苦于以下问题:C# MetadataReader.GetBlobBytes方法的具体用法?C# MetadataReader.GetBlobBytes怎么用?C# MetadataReader.GetBlobBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MetadataReader的用法示例。


在下文中一共展示了MetadataReader.GetBlobBytes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ValidateMethodDef


//.........这里部分代码省略.........
            {
                new byte[] { 0x20, 0x00, 0x01 }, new byte[] { 0x20, 01, 0x0e, 0x08 },
                new byte[] { 0x20, 02, 01, 0x08, 0x0e }, new byte[] { 0x20, 00, 0x11, 0x09 },
                new byte[] { 0x20, 02, 01, 0x11, 0x0d, 0x12, 0x11 }, new byte[] { 0x20, 01, 0x12, 0x15, 0x10, 0x12, 0x19 },
                new byte[] { 0x00, 00, 01 }, new byte[] { 0x20, 01, 01, 0x12, 0x18 },
                new byte[] { 0x20, 01, 01, 0x12, 0x18 }, new byte[] { 0x20, 02, 01, 0x1c, 0x12, 0x21 },
                new byte[] { 0x20, 01, 0x1c, 0x10, 0x11, 0x14 }, new byte[] { 0x20, 02, 01, 0x1c, 0x18 },
                new byte[] { 0x20, 04, 0x12, 0x2d, 0x1c, 0x12, 0x21, 0x12, 0x31, 0x1c }, new byte[] { 0x20, 01, 01, 0x12, 0x2d },
                new byte[] { 0x20, 02, 01, 0x1c, 0x12, 0x21 },
            };

            if (startIndex > reader.MethodDefTable.NumberOfRows)
            {
                return;
            }

            uint zeroBased = startIndex - 1;
            uint delta = count;

            // Last one
            if (0xF0000000 == count)
            {
                delta = (uint)reader.MethodDefTable.NumberOfRows - zeroBased;
                if (0 == delta)
                {
                    return;
                }
            }

            Assert.InRange((uint)reader.MethodDefTable.NumberOfRows, zeroBased + delta, uint.MaxValue); // 1 based
            bool first = true;
            uint prevParamStart = 0;
            for (uint i = zeroBased; i < zeroBased + delta; i++)
            {
                var handle = MethodDefinitionHandle.FromRowId((int)i + 1);
                var flags = reader.MethodDefTable.GetFlags(handle);
                var implFlags = reader.MethodDefTable.GetImplFlags(handle);
                var rva = reader.MethodDefTable.GetRva(handle);
                var name = reader.MethodDefTable.GetName(handle);
                var signature = reader.MethodDefTable.GetSignature(handle);
                var paramStart = (uint)reader.MethodDefTable.GetParamStart((int)i + 1);

                if (isMod)
                {
                    // Console.WriteLine("M: {0}", reader.GetString(row.Name));
                    Assert.Equal(modNames[i], reader.GetString(name));

                    Assert.Equal(modFlags[i], (ushort)flags);
                    Assert.Equal(modImpls[i], (ushort)implFlags);
                    Assert.Equal(modRVAs[i], (uint)rva);
                }
                else
                {
                    // Console.WriteLine("M: {0}", reader.GetString(row.Name));
                    Assert.Equal(expNames[i], reader.GetString(name));

                    Assert.Equal(expFlags[i], (ushort)flags);
                    Assert.Equal((ushort)0, (ushort)implFlags);
                    Assert.Equal(expRVAs[i], (uint)rva);
                }

                var sig = reader.GetBlobBytes(signature);
                int len = 0;
                if (isMod)
                {
                    len = modSigs[i].Length;
                }
                else
                {
                    len = expSigs[i].Length;
                }

                for (int j = 0; j < len; j++)
                {
                    if (isMod)
                    {
                        Assert.Equal(modSigs[i][j], sig[j]);
                    }
                    else
                    {
                        Assert.Equal(expSigs[i][j], sig[j]);
                    }
                }

                // validate previous row's param as it needs current row's other to calc how many
                if (!first)
                {
                    ValidateParam(reader, prevParamStart, paramStart - prevParamStart, isMod);
                }

                // Last
                if (i + 1 == reader.MethodDefTable.NumberOfRows)
                {
                    ValidateParam(reader, paramStart, 0xF0000000, isMod);
                }

                prevParamStart = paramStart;
                first = false;
            }
        }
开发者ID:nnyamhon,项目名称:corefx,代码行数:101,代码来源:MetadataReaderTests.cs

示例2: ValidateProperty

        /// <summary>
        /// PropertyMap Table Columns:
        ///     Parent (RID to TypeDef)
        ///     PropertyList (RID to EventTable)
        /// ===========================================
        /// Property Table Columns:
        ///     Name (offset to #String)
        ///     PropFlags (2 byte unsigned)
        ///     Type (offset to #blob - Signature)
        /// </summary>
        private void ValidateProperty(MetadataReader reader, uint rowId, uint startIndex, uint count, bool isVBMod = false)
        {
            if (0 == count)
            {
                return;
            }

            // ModuleCS01
            var expNames = new string[]
            {
                "AppProp", "P01", "Item", "P01", "Item",
                "CS1IGoo<System.Linq.Expressions.Expression,System.Object>.P01",
                "CS1IGoo<System.Linq.Expressions.Expression,System.Object>.Item",
            };
            var expSigs = new byte[][]
            {
                new byte[] { 0x28, 00, 0x15, 0x12, 0x21, 0x02, 0x12, 0x19, 0x1c }, new byte[] { 0x28, 00, 0x13, 00 },
                new byte[] { 0x28, 01, 0x1c, 0x13, 00 }, new byte[] { 0x28, 0x00, 0x13, 00 }, new byte[] { 0x28, 0x01, 0x1c, 0x13, 00 },
                new byte[] { 0x28, 00, 0x12, 0x19 }, new byte[] { 0x28, 01, 0x1c, 0x12, 0x19 }
            };

            // ModuleVB01
            // Prop: 0:0000, 1:string#13c, 2:blob#70 | 0:0000, 1:string#14d, 2:blob#75
            var modNames = new string[]
            {
                "ModVBDefaultProp", "ModVBProp",
            };
            var modSigs = new byte[][]
            {
                new byte[] { 0x28, 01, 0x0e, 0x08 }, new byte[] { 0x28, 00, 0x11, 0x09 },
            };

            // Validity Rules
            uint zeroBased = startIndex - 1;
            uint delta = count;

            // Last one
            if (0xF0000000 == count)
            {
                delta = (uint)reader.PropertyTable.NumberOfRows - zeroBased;
                if (0 == delta)
                {
                    return;
                }
            }

            Assert.InRange((uint)reader.PropertyTable.NumberOfRows, zeroBased + count, uint.MaxValue);
            for (uint i = zeroBased; i < zeroBased + count; i++)
            {
                var handle = PropertyDefinitionHandle.FromRowId((int)i + 1);
                var row = reader.GetPropertyDefinition(handle);

                // Name
                if (isVBMod)
                {
                    Assert.Equal(modNames[i], reader.GetString(row.Name));
                }
                else
                {
                    Assert.Equal(expNames[i], reader.GetString(row.Name));
                }

                Assert.Equal(0, (ushort)row.Attributes);

                var sig = reader.GetBlobBytes(row.Signature);
                Assert.Equal(40, sig[0]);
                byte[] exp;
                if (isVBMod)
                {
                    exp = modSigs[i];
                }
                else
                {
                    exp = expSigs[i];
                }

                for (int j = 0; j < exp.Length; j++)
                {
                    Assert.Equal(exp[j], sig[j]);
                }
            } // for
        }
开发者ID:nnyamhon,项目名称:corefx,代码行数:92,代码来源:MetadataReaderTests.cs

示例3: ValidateFieldDef

        /// <summary>
        /// Field Table Columns:
        ///     Name (offset to #String)
        ///     Flags (2 byte unsigned)
        ///     Signature (offset to #blob)
        /// </summary>
        private void ValidateFieldDef(MetadataReader reader, uint startIndex, uint count, bool isMod = false)
        {
            if (count == 0)
            {
                return;
            }

            // APPCS
            var expNames = new string[] { "AppField01", "AppField02" };
            var expFlags = new FieldAttributes[]
            {
                /*0x11*/
                         FieldAttributes.Private | FieldAttributes.Static,
                /*0x01*/ FieldAttributes.Private,
                };
            var expSigs = new byte[][] { new byte[] { 0x06, 0x12, 0x11 }, new byte[] { 0x06, 0x12, 0x25 }, };

            // =====================================================================================================
            // VB Module - 8
            var modNames = new string[] { "ConstString", "ArrayField", "AnEventEvent", "value__", "None", "Red", "Yellow", "Blue", };
            var modFlags = new FieldAttributes[]
            {
                /* 0x8053 */
                             FieldAttributes.HasDefault | FieldAttributes.Literal | FieldAttributes.Static | FieldAttributes.FamANDAssem | FieldAttributes.Private,
                /* 0x0016 */ FieldAttributes.Static | FieldAttributes.Family | FieldAttributes.FamANDAssem,
                /* 0x0001 */ FieldAttributes.Private,
                /* 0x0606 */ FieldAttributes.RTSpecialName | FieldAttributes.SpecialName | FieldAttributes.Family | FieldAttributes.FamANDAssem,
                /* 0x8056 */ FieldAttributes.HasDefault | FieldAttributes.Literal | FieldAttributes.Static | FieldAttributes.Family | FieldAttributes.FamANDAssem,
                /* 0x8056 */ FieldAttributes.HasDefault | FieldAttributes.Literal | FieldAttributes.Static | FieldAttributes.Family | FieldAttributes.FamANDAssem,
                /* 0x8056 */ FieldAttributes.HasDefault | FieldAttributes.Literal | FieldAttributes.Static | FieldAttributes.Family | FieldAttributes.FamANDAssem,
                /* 0x8056 */ FieldAttributes.HasDefault | FieldAttributes.Literal | FieldAttributes.Static | FieldAttributes.Family | FieldAttributes.FamANDAssem,
                };
            var modSigs = new byte[][]
            {
                new byte[] { 0x06, 0x0e }, new byte[] { 0x06, 0x14, 0x11, 0x14, 02, 00, 02, 00, 00 },
                new byte[] { 0x06, 0x12, 0x18 }, new byte[] { 0x06, 0x08 },
                new byte[] { 0x06, 0x11, 0x10 }, new byte[] { 0x06, 0x11, 0x10 },
                new byte[] { 0x06, 0x11, 0x10 }, new byte[] { 0x06, 0x11, 0x10 },
            };

            if (startIndex > reader.FieldTable.NumberOfRows)
            {
                return;
            }

            uint zeroBased = startIndex - 1;
            uint delta = count;

            // Last one
            if (0xF0000000 == count)
            {
                delta = (uint)reader.FieldTable.NumberOfRows - zeroBased;
                if (0 == delta)
                {
                    return;
                }
            }

            Assert.InRange((uint)reader.FieldTable.NumberOfRows, zeroBased + delta, uint.MaxValue); // 1 based
            for (uint i = zeroBased; i < zeroBased + delta; i++)
            {
                var handle = FieldDefinitionHandle.FromRowId((int)(i + 1));
                var row = reader.GetFieldDefinition(handle);

                if (isMod)
                {
                    Assert.Equal(modNames[i], reader.GetString(row.Name));
                    Assert.Equal(modFlags[i], row.Attributes);
                }
                else
                {
                    Assert.Equal(expNames[i], reader.GetString(row.Name));
                    Assert.Equal(expFlags[i], row.Attributes);
                }

                var sig = reader.GetBlobBytes(row.Signature);

                // calling convention, always 6 for field
                Assert.Equal(sig[0], 6);
                int len = 0;
                if (isMod)
                {
                    len = modSigs[i].Length;
                }
                else
                {
                    len = expSigs[i].Length;
                }

                for (int j = 1; j < len; j++)
                {
                    if (isMod)
                    {
                        Assert.Equal(modSigs[i][j], sig[j]);
//.........这里部分代码省略.........
开发者ID:nnyamhon,项目名称:corefx,代码行数:101,代码来源:MetadataReaderTests.cs


注:本文中的MetadataReader.GetBlobBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。