private object CreateData(MDTables helper)
        {
            switch (_type)
            {
            case Types.UInt16:
                return((ushort)_rawData);

            case Types.UInt32:
                return(_rawData);

            case Types.String:
                return(helper.GetString((int)_rawData));

            case Types.Guid:
                return(helper.GetGuid((int)_rawData));

            case Types.Blob:
                return(helper.GetBlob((int)_rawData));
                //case Types.UserString:
                //	return _helper.GetBlob((int)_rawData);
            }

            if ((int)_type < 64)
            {
                return(new RID(_type, _rawData));
            }

            return(new CodedToken(_rawData));
        }
Beispiel #2
0
        public MModule(BinaryReader reader)
        {
            try
            {
                _mh = new ModHeaders(reader);
            }
            catch (Exception)
            {
                return;
            }

            //imports
            try
            {
                _imp = new ImpExports(reader, this);
            }
            catch (Exception)
            {
                return;
            }

            //relocs
            try
            {
                _fix = new Relocations(reader, this);
            }
            catch (Exception)
            {
                return;
            }

            //heaps
            try
            {
                _stringHeap = new MDStringHeap(reader, _mh.MetaDataHeaders.StringStreamHeader.Offset + _mh.MetaDataHeaders.StorageSigAndHeader.Start, _mh.MetaDataHeaders.StringStreamHeader.Size, _mh.MetaDataHeaders.StringStreamHeader.Name);
                _blobHeap   = new MDBlobHeap(reader, _mh.MetaDataHeaders.BlobStreamHeader.Offset + _mh.MetaDataHeaders.StorageSigAndHeader.Start, _mh.MetaDataHeaders.BlobStreamHeader.Size, _mh.MetaDataHeaders.BlobStreamHeader.Name);
                _GUIDHeap   = new MDGUIDHeap(reader, _mh.MetaDataHeaders.GUIDStreamHeader.Offset + _mh.MetaDataHeaders.StorageSigAndHeader.Start, _mh.MetaDataHeaders.GUIDStreamHeader.Size, _mh.MetaDataHeaders.GUIDStreamHeader.Name);

                if (_mh.MetaDataHeaders.USStreamHeader != null)
                {
                    _USHeap = new MDBlobHeap(reader, _mh.MetaDataHeaders.USStreamHeader.Offset + _mh.MetaDataHeaders.StorageSigAndHeader.Start, _mh.MetaDataHeaders.USStreamHeader.Size, _mh.MetaDataHeaders.USStreamHeader.Name);
                }
            }
            catch (Exception)
            {
                return;
            }

            //tables
            try
            {
                reader.BaseStream.Position = _mh.MetaDataTableHeader.End;
                _tables = new MDTables(reader, this);
            }
            catch (Exception)
            {
                return;
            }
        }
        public TableCell(Types type, BinaryReader reader, MDTables helper)
        {
            _type = type;

            try
            {
                // Fixed
                if (type == Types.UInt16)
                {
                    _rawData = reader.ReadUInt16();
                }
                if (type == Types.UInt32)
                {
                    _rawData = reader.ReadUInt32();
                }

                // Heap
                if (type == Types.String)
                {
                    _rawData = ((helper.GetStringIndexSize() == 2) ? reader.ReadUInt16() : reader.ReadUInt32());
                }
                if (type == Types.Guid)
                {
                    _rawData = ((helper.GetGuidIndexSize() == 2) ? reader.ReadUInt16() : reader.ReadUInt32());
                }
                if (type == Types.Blob)
                {
                    _rawData = ((helper.GetBlobIndexSize() == 2) ? reader.ReadUInt16() : reader.ReadUInt32());
                }

                // Rid
                if ((int)type < 64)
                {
                    Table table = helper.GetTable(type);
                    _rawData = ((uint)type << 24) | ((table.Count < 65536) ? reader.ReadUInt16() : reader.ReadUInt32());
                }

                // Coded token (may need to be uncompressed from 2-byte form)
                else if ((int)type < 97)
                {
                    int     codedToken     = (helper.SizeOfType(type) == 2) ? reader.ReadUInt16() : reader.ReadInt32();
                    Types[] referredTables = helper.CodedTokenTypes(type);

                    int tableIndex = (codedToken & ~(-1 << helper.CodedTokenBits(referredTables.Length)));
                    int index      = (codedToken >> helper.CodedTokenBits(referredTables.Length));

                    int token = helper.ToToken(referredTables[tableIndex], index - 1);
                    _rawData = (uint)token;
                }

                _data = CreateData(helper);
            }
            catch (Exception)
            {
                _type = Types.String;
                _data = "Unreadable cell: " + type + " " + _rawData;
            }
        }
        public Table(Types type, Types[] colTypes, String[] colNames, MDTables helper, BinaryReader reader)
        {
            _type   = type;
            _helper = helper;

            _colDescs = new ColDesc[colTypes.Length];

            for (int i = 0; i < _colDescs.Length; i++)
            {
                _colDescs[i] = new ColDesc(colTypes[i], colNames[i]);
            }

            _rows = new Row[helper.GetTableRows(type)];

            _rowSize = 0;
            foreach (ColDesc cd in _colDescs)
            {
                _rowSize += _helper.SizeOfType(cd.Type);
            }

            data = reader.ReadBytes(_rowSize * Count);
        }
Beispiel #5
0
        public MModule(BinaryReader reader)
        {
            try
            {
                _mh = new ModHeaders(reader);
            }
            catch (Exception)
            {
                return;
            }

            //imports
            try
            {
                _imp = new ImpExports(reader, this);
            }
            catch (Exception)
            {
                return;
            }

            //relocs
            try
            {
                _fix = new Relocations(reader, this);
            }
            catch (Exception)
            {
                return;
            }

            //heaps
            try
            {
                _stringHeap = new MDStringHeap(reader, _mh.MetaDataHeaders.StringStreamHeader.Offset + _mh.MetaDataHeaders.StorageSigAndHeader.Start,
                                               _mh.MetaDataHeaders.StringStreamHeader.Size, _mh.MetaDataHeaders.StringStreamHeader.Name);
                _blobHeap = new MDBlobHeap(reader, _mh.MetaDataHeaders.BlobStreamHeader.Offset + _mh.MetaDataHeaders.StorageSigAndHeader.Start,
                                           _mh.MetaDataHeaders.BlobStreamHeader.Size, _mh.MetaDataHeaders.BlobStreamHeader.Name);
                _GUIDHeap = new MDGUIDHeap(reader, _mh.MetaDataHeaders.GUIDStreamHeader.Offset + _mh.MetaDataHeaders.StorageSigAndHeader.Start,
                                           _mh.MetaDataHeaders.GUIDStreamHeader.Size, _mh.MetaDataHeaders.GUIDStreamHeader.Name);

                if (_mh.MetaDataHeaders.USStreamHeader != null)
                {
                    _USHeap = new MDBlobHeap(reader, _mh.MetaDataHeaders.USStreamHeader.Offset + _mh.MetaDataHeaders.StorageSigAndHeader.Start,
                                             _mh.MetaDataHeaders.USStreamHeader.Size, _mh.MetaDataHeaders.USStreamHeader.Name);
                }
            }
            catch (Exception)
            {
                return;
            }

            //tables
            try
            {
                reader.BaseStream.Position = _mh.MetaDataTableHeader.End;
                _tables = new MDTables(reader, this);
            }
            catch
            {
            }
        }
Beispiel #6
0
        private object CreateData(MDTables helper)
        {
            switch (_type)
            {
                case Types.UInt16:
                    return (ushort) _rawData;
                case Types.UInt32:
                    return _rawData;
                case Types.String:
                    return helper.GetString((int) _rawData);
                case Types.Guid:
                    return helper.GetGuid((int) _rawData);
                case Types.Blob:
                    return helper.GetBlob((int) _rawData);
                    //case Types.UserString:
                    //	return _helper.GetBlob((int)_rawData);
            }

            if ((int) _type < 64)
            {
                return new RID(_type, _rawData);
            }

            return new CodedToken(_rawData);
        }
Beispiel #7
0
        public TableCell(Types type, BinaryReader reader, MDTables helper)
        {
            _type = type;

            try
            {
                // Fixed
                if (type == Types.UInt16)
                {
                    _rawData = reader.ReadUInt16();
                }
                if (type == Types.UInt32)
                {
                    _rawData = reader.ReadUInt32();
                }

                // Heap
                if (type == Types.String)
                {
                    _rawData = ((helper.GetStringIndexSize() == 2) ? reader.ReadUInt16() : reader.ReadUInt32());
                }
                if (type == Types.Guid)
                {
                    _rawData = ((helper.GetGuidIndexSize() == 2) ? reader.ReadUInt16() : reader.ReadUInt32());
                }
                if (type == Types.Blob)
                {
                    _rawData = ((helper.GetBlobIndexSize() == 2) ? reader.ReadUInt16() : reader.ReadUInt32());
                }

                // Rid
                if ((int) type < 64)
                {
                    Table table = helper.GetTable(type);
                    _rawData = ((uint) type << 24) | ((table.Count < 65536) ? reader.ReadUInt16() : reader.ReadUInt32());
                }

                    // Coded token (may need to be uncompressed from 2-byte form)
                else if ((int) type < 97)
                {
                    int codedToken = (helper.SizeOfType(type) == 2) ? reader.ReadUInt16() : reader.ReadInt32();
                    Types[] referredTables = helper.CodedTokenTypes(type);

                    int tableIndex = (codedToken & ~(-1 << helper.CodedTokenBits(referredTables.Length)));
                    int index = (codedToken >> helper.CodedTokenBits(referredTables.Length));

                    int token = helper.ToToken(referredTables[tableIndex], index - 1);
                    _rawData = (uint) token;
                }

                _data = CreateData(helper);
            }
            catch (Exception)
            {
                _type = Types.String;
                _data = "Unreadable cell: " + type + " " + _rawData;
            }
        }
Beispiel #8
0
        public Table(Types type, Types[] colTypes, String[] colNames, MDTables helper, BinaryReader reader)
        {
            _type = type;
            _helper = helper;

            _colDescs = new ColDesc[colTypes.Length];

            for (int i = 0; i < _colDescs.Length; i++)
            {
                _colDescs[i] = new ColDesc(colTypes[i], colNames[i]);
            }

            _rows = new Row[helper.GetTableRows(type)];

            _rowSize = 0;
            foreach (ColDesc cd in _colDescs)
            {
                _rowSize += _helper.SizeOfType(cd.Type);
            }

            data = reader.ReadBytes(_rowSize*Count);
        }
 public CodedToken(Types type, uint raw, MDTables helper)
 {
     _rawData = raw;
     _type    = type;
 }
 public CodedToken(Types type, uint raw, MDTables helper)
 {
     _rawData = raw;
     _type = type;
 }