Exemplo n.º 1
0
        static object ReadBlobToken(int col, MetadataTable tbl, MetadataReader rdr, uint[] lens)
        {
            if (rdr.BaseStream.Root[MetadataStreamType.Blob] == null)
            {
                rdr.ReadUInt16();
                return(BlobToken.Null);
            }
            BlobHeap bh = rdr.BaseStream.Root[MetadataStreamType.Blob].Heap as BlobHeap;
            uint     tkn;

            if (bh.Stream.Length > ushort.MaxValue)
            {
                tkn = rdr.ReadUInt32();
            }
            else
            {
                tkn = rdr.ReadUInt16();
            }
            return(bh.Resolve(new MetadataToken(tkn)));
        }
Exemplo n.º 2
0
        internal MetadataRow(MetadataTable tbl, bool needInit)
            : base(tbl)
        {
            vals = new object[tbl.TableDef.Columns.Length];
            par  = tbl;
            if (!needInit)
            {
                return;
            }

            BlobHeap    bh = tbl.Heap.Stream.Root[MetadataStreamType.Blob].Heap as BlobHeap;
            StringsHeap sh = tbl.Heap.Stream.Root[MetadataStreamType.Strings].Heap as StringsHeap;
            GUIDHeap    gh = tbl.Heap.Stream.Root[MetadataStreamType.GUID].Heap as GUIDHeap;

            foreach (MetadataColumn col in tbl.Columns)
            {
                if (col.Type is Type)
                {
                    if ((col.Type as Type).IsEnum)
                    {
                        this[col.Index] = Enum.ToObject(col.Type as Type, 0);
                    }
                    else
                    {
                        switch ((col.Type as Type).FullName)
                        {
                        case "System.Byte":
                            this[col.Index] = (byte)0;
                            break;

                        case "System.UInt16":
                            this[col.Index] = (ushort)0;
                            break;

                        case "System.UInt32":
                            this[col.Index] = (uint)0;
                            break;

                        case "NetPE.Core.Rva":
                            this[col.Index] = (Rva)0;
                            break;

                        case "NetPE.Core.Metadata.BlobToken":
                            this[col.Index] = bh.Resolve(new MetadataToken(MetadataTokenType.Unknown, 0));
                            break;

                        case "NetPE.Core.Metadata.GUIDToken":
                            this[col.Index] = gh.Resolve(new MetadataToken(MetadataTokenType.Unknown, 0));
                            break;

                        case "NetPE.Core.Metadata.StringToken":
                            this[col.Index] = sh.Resolve(new MetadataToken(MetadataTokenType.Unknown, 0));
                            break;
                        }
                    }
                }
                else if (col.Type is TableType)
                {
                    this[col.Index] = new TableToken(tbl.Heap, new MetadataToken((MetadataTokenType)(TableType)col.Type, 0));
                }
                else if (col.Type is CodedIndex)
                {
                    this[col.Index] = new TableToken(tbl.Heap, new MetadataToken((MetadataTokenType)CodedIndexDefs.MdCodedIndexDefs[(CodedIndex)col.Type].TableTypes[0].Key, 0));
                }
            }
        }