示例#1
0
			public void Read(BinaryReader reader, MDStream stream)
			{	
				offs = reader.ReadUInt32 ();
				size = reader.ReadUInt32 ();

				StringBuilder name_builder = new StringBuilder ();
				while (true) {
					sbyte c = reader.ReadSByte();
					if (c == 0) 
						break;
					name_builder.Append ((char) c);
				}

				name = name_builder.ToString ();
				if (name.Length == 0)
					throw new BadImageException("Invalid stream name.");

				// Round up to dword boundary.
				long pos = reader.BaseStream.Position;
				if (stream != null) 
					pos -= stream.Root.filePos;
				pos += 3;
				pos &= ~3;
				if (stream != null) 
					pos += stream.Root.filePos;
				
				// Advance file pointer.
				reader.BaseStream.Position = pos;
			}
示例#2
0
文件: MDHeap.cs 项目: emtees/old-code
		protected MDHeap(MDStream stream)
		{
			this.stream = stream;
			if (stream.RawData != null) {
				FromRawData(stream.RawData);
			}
		}
示例#3
0
            public void Write(BinaryWriter writer, MDStream stream)
            {
                writer.Write(offs);
                writer.Write(size);

                for (int i = 0; i < name.Length; i++)
                {
                    writer.Write((sbyte)name[i]);
                }
                writer.Write((sbyte)'\0');

                // Round up to dword boundary.
                long pos = writer.BaseStream.Position;

                if (stream != null)
                {
                    pos -= stream.Root.filePos;
                }
                pos += 3;
                pos &= ~3;
                if (stream != null)
                {
                    pos += stream.Root.filePos;
                }

                // Advance file pointer.
                writer.BaseStream.Position = pos;
            }
示例#4
0
        public MethodIL GetMethodBody(int num)
        {
            MethodIL il = null;

            if (img == null)
            {
                return(il);
            }
            MDStream   tabs     = Streams["#~"] as MDStream;
            TablesHeap tabsHeap = tabs.Heap as TablesHeap;

            if (tabsHeap.HasMethod)
            {
                MDTable methods = tabsHeap[TableId.Method];
                if (methods == null)
                {
                    return(il);
                }
                MethodRow row = methods[num] as MethodRow;
                if (row == null)
                {
                    return(il);
                }
                BinaryReader reader = img.reader;
                reader.BaseStream.Position = img.RVAToVA(row.RVA);
                il = new MethodIL();
                il.Read(reader);
            }
            return(il);
        }
示例#5
0
 protected MDHeap(MDStream stream)
 {
     this.stream = stream;
     if (stream.RawData != null)
     {
         FromRawData(stream.RawData);
     }
 }
示例#6
0
文件: MDHeap.cs 项目: emtees/old-code
		/// <summary>
		/// Heap factory.
		/// </summary>
		/// <param name="stream">Base stream.</param>
		/// <returns></returns>
		public static MDHeap Create(MDStream stream)
		{
			MDHeap res = null;

			switch (stream.Name) {
				case "#~" :
				case "#-" :
					res = new TablesHeap(stream);
					break;
				case "#Strings" :
					res = new StringsHeap(stream);
					break;
				case "#GUID" :
					res = new GUIDHeap(stream);
					break;
			}

			return res;
		}
示例#7
0
			public void Write (BinaryWriter writer, MDStream stream)
			{
				writer.Write (offs);
				writer.Write (size);

				for (int i=0; i<name.Length; i++)
					writer.Write ((sbyte)name[i]);
				writer.Write ((sbyte) '\0');	
			
				// Round up to dword boundary.
				long pos = writer.BaseStream.Position;
				if (stream != null) 
					pos -= stream.Root.filePos;
				pos += 3;
				pos &= ~3;
				if (stream != null) 
					pos += stream.Root.filePos;

				// Advance file pointer.
				writer.BaseStream.Position = pos;
			}
示例#8
0
            public void Read(BinaryReader reader, MDStream stream)
            {
                offs = reader.ReadUInt32();
                size = reader.ReadUInt32();

                StringBuilder name_builder = new StringBuilder();

                while (true)
                {
                    sbyte c = reader.ReadSByte();
                    if (c == 0)
                    {
                        break;
                    }
                    name_builder.Append((char)c);
                }

                name = name_builder.ToString();
                if (name.Length == 0)
                {
                    throw new BadImageException("Invalid stream name.");
                }

                // Round up to dword boundary.
                long pos = reader.BaseStream.Position;

                if (stream != null)
                {
                    pos -= stream.Root.filePos;
                }
                pos += 3;
                pos &= ~3;
                if (stream != null)
                {
                    pos += stream.Root.filePos;
                }

                // Advance file pointer.
                reader.BaseStream.Position = pos;
            }
示例#9
0
        /// <summary>
        /// Heap factory.
        /// </summary>
        /// <param name="stream">Base stream.</param>
        /// <returns></returns>
        public static MDHeap Create(MDStream stream)
        {
            MDHeap res = null;

            switch (stream.Name)
            {
            case "#~":
            case "#-":
                res = new TablesHeap(stream);
                break;

            case "#Strings":
                res = new StringsHeap(stream);
                break;

            case "#GUID":
                res = new GUIDHeap(stream);
                break;
            }

            return(res);
        }
示例#10
0
 internal TablesHeap(MDStream stream) : base(stream)
 {
 }
示例#11
0
		internal StringsHeap(MDStream stream) : base(stream)
		{
		}
示例#12
0
		internal TablesHeapBase(MDStream stream) : base(stream)
		{
		}
示例#13
0
 internal GUIDHeap(MDStream stream) : base(stream)
 {
 }
示例#14
0
        unsafe public void Read(BinaryReader reader)
        {
            filePos = reader.BaseStream.Position;

            sig = reader.ReadUInt32();
            if (sig != Sig)
            {
                throw new BadImageException("Invalid MetaData Signature.");
            }

            majVer   = reader.ReadInt16();
            minVer   = reader.ReadInt16();
            reserved = reader.ReadUInt32();

            // Length of version string.
            len = reader.ReadInt32();

            // Read version string.
            if (len != 0)
            {
                sbyte *pVer = stackalloc sbyte [len];
                sbyte *p    = pVer;

                long pos = reader.BaseStream.Position;
                int  i;
                for (i = len; --i >= 0;)
                {
                    sbyte c = reader.ReadSByte();
                    if (c == 0)
                    {
                        break;
                    }
                    *p++ = c;
                }

                verStr = PEUtils.GetString(pVer, 0, len - i - 1, Encoding.UTF8);

                // Round up to dword boundary, relative to header start.
                pos += len;
                pos -= filePos;
                pos += 3;
                pos &= ~3;
                pos += filePos;

                // Advance file pointer.
                reader.BaseStream.Position = pos;
            }
            else
            {
                VersionString = String.Empty;
            }

            flags    = reader.ReadInt16();
            nStreams = reader.ReadInt16();
            streams  = new Hashtable(nStreams);

            // load all streams into memory
            for (int i = nStreams; --i >= 0;)
            {
                MDStream s = new MDStream(this);
                s.Read(reader);
                // TODO: check for duplicated streams,
                // use Add instead of indexer.
                streams[s.Name] = s;
            }

            MDStream tabs = Streams["#~"] as MDStream;

            // Try uncompressed stream.
            if (tabs == null)
            {
                tabs = Streams["#-"] as MDStream;
            }
            if (tabs == null)
            {
                throw new BadMetaDataException("Missing #~ stream.");
            }

            TablesHeap tabsHeap = tabs.Heap as TablesHeap;

            // cache index sizes
            strIdx  = tabsHeap.StringsIndexSize;
            guidIdx = tabsHeap.GUIDIndexSize;
            blobIdx = tabsHeap.BlobIndexSize;
        }
示例#15
0
		internal GUIDHeap(MDStream stream) : base(stream)
		{
		}
示例#16
0
 internal StringsHeap(MDStream stream) : base(stream)
 {
 }
示例#17
0
		unsafe public void Read(BinaryReader reader)
		{
			filePos = reader.BaseStream.Position;
			
			sig = reader.ReadUInt32();
			if (sig != Sig) {
				throw new BadImageException("Invalid MetaData Signature.");
			}

			majVer = reader.ReadInt16();
			minVer = reader.ReadInt16();
			reserved = reader.ReadUInt32();

			// Length of version string.
			len = reader.ReadInt32();
			
			// Read version string.
			if (len != 0) {
				sbyte* pVer = stackalloc sbyte [len];
				sbyte* p = pVer;

				long pos = reader.BaseStream.Position;
				int i;
				for (i = len; --i >= 0;) {
					sbyte c = reader.ReadSByte();
					if (c == 0) break;
					*p++ = c;
				}

				verStr = PEUtils.GetString (pVer, 0, len-i-1, Encoding.UTF8);

				// Round up to dword boundary, relative to header start.
				pos += len;
				pos -= filePos;
				pos += 3;
				pos &= ~3;
				pos += filePos;

				// Advance file pointer.
				reader.BaseStream.Position = pos;
			} else {
				VersionString = String.Empty;
			}
			
			flags = reader.ReadInt16();
			nStreams = reader.ReadInt16();
			streams = new Hashtable(nStreams);

			// load all streams into memory
			for (int i = nStreams; --i >=0;) {
				MDStream s = new MDStream(this);
				s.Read(reader);
				// TODO: check for duplicated streams,
				// use Add instead of indexer.
				streams[s.Name] = s;
			}

			MDStream tabs = Streams["#~"] as MDStream;
			// Try uncompressed stream.
			if (tabs == null) tabs = Streams["#-"] as MDStream;
			if (tabs == null) throw new BadMetaDataException("Missing #~ stream.");

			TablesHeap tabsHeap = tabs.Heap as TablesHeap;
			// cache index sizes
			strIdx = tabsHeap.StringsIndexSize;
			guidIdx = tabsHeap.GUIDIndexSize;
			blobIdx = tabsHeap.BlobIndexSize;
		}