Represents a .NET header from an application. This header is only available if the assembly is written in a .NET language.
Наследование: IHeader, IDisposable, IDataDirectoryProvider, ICacheProvider
Пример #1
0
        public NetHeaderDlg(NETHeader header)
        {
            this.header = header;
            InitializeComponent();

            textBox1.Text = "0x" + header.RawOffset.ToString("X8");
            textBox2.Text = header.Flags.ToString();
            textBox3.Text = header.MetaDataHeader.VersionString;
            textBox4.Text = header.MetaDataStreams.Length.ToString();
            textBox5.Text = "0x" + header.EntryPointToken.ToString("X8");

            for (int i = 0; i <= header.MetaDataStreams.Length - 1; i++)
            {
                DataGridViewRow row = new DataGridViewRow();
                row.Cells.Add(new DataGridViewTextBoxCell() { Value = header.MetaDataStreams[i].HeaderOffset.ToString("X8") });
                row.Cells.Add(new DataGridViewTextBoxCell() { Value = header.MetaDataStreams[i].StreamSize.ToString("X8") });
                row.Cells.Add(new DataGridViewTextBoxCell() { Value = header.MetaDataStreams[i].Name });

                byte[] bytes = new byte[4];
                new MemoryStream(header.MetaDataStreams[i].Contents).Read(bytes,0,4);
                string firstbytestext = "";
                foreach (byte b in bytes)
                    firstbytestext += b.ToString("X2") + " ";
                firstbytestext += "...";
                row.Cells.Add(new DataGridViewTextBoxCell() { Value = firstbytestext });
                row.Tag = header.MetaDataStreams[i];
                dataGridView1.Rows.Add(row);
            }

            dataGridView1.CellDoubleClick += new DataGridViewCellEventHandler(dataGridView1_CellDoubleClick);
        }
Пример #2
0
 internal NETHeaderReader(NTHeader header, NETHeader parent)
 {
     this.parent = parent;
     header._assembly._netHeader = parent;
     image = header._assembly._peImage;
     this.ntHeader = header;
 }
Пример #3
0
 internal NETTableReconstructor(TablesHeap tablesHeap)
 {
     this.tablesHeap = tablesHeap;
     this.netHeader = tablesHeap.netheader;
     stream = new MemoryStream();
     writer = new BinaryWriter(stream);
     stream.Seek(0, SeekOrigin.Begin);
 }
Пример #4
0
 internal MetaDataStream(NETHeader netheader, int headeroffset, Structures.METADATA_STREAM_HEADER rawHeader, string name)
 {
     this.headeroffset = headeroffset;
     this.netheader = netheader;
     this.streamHeader = rawHeader;
     this.name = name;
     this.indexsize = 2;
 }
Пример #5
0
 internal MetaDataStream(NETHeader netheader, NETHeaderReader reader, int headeroffset, int offset, int size,  string name)
 {
     this.headeroffset = headeroffset;
     this.netheader = netheader;
     this.offset = offset;
     this.size = size;
     this.reader = reader;
     this.name = name;
 }
Пример #6
0
 private void ConstructNetDirectories(NETHeader newHeader)
 {
     newHeader.DataDirectories = new DataDirectory[] {
      new DataDirectory(DataDirectoryName.NETMetadata, default(Section), 0, newHeader._rawHeader.MetaData),
      new DataDirectory(DataDirectoryName.NETResource, default(Section), 0, newHeader._rawHeader.Resources),
      new DataDirectory(DataDirectoryName.NETStrongName, default(Section), 0, newHeader._rawHeader.StrongNameSignature),
      new DataDirectory(DataDirectoryName.NETCodeManager, default(Section), 0, newHeader._rawHeader.CodeManagerTable),
      new DataDirectory(DataDirectoryName.NETVTableFixups, default(Section), 0, newHeader._rawHeader.VTableFixups),
      new DataDirectory(DataDirectoryName.NETExport, default(Section), 0, newHeader._rawHeader.ExportAddressTableJumps),
      new DataDirectory(DataDirectoryName.NETNativeHeader, default(Section), 0, newHeader._rawHeader.ManagedNativeHeader),
     };
 }
Пример #7
0
        internal MetaDataStream(NETHeader netheader, int headeroffset, Structures.METADATA_STREAM_HEADER rawHeader, string name)
        {
            this._headeroffset = headeroffset;
            this._netheader = netheader;
            this._streamHeader = rawHeader;
            this._name = name;
            this._indexsize = 2;

            byte[] contents = netheader._assembly._peImage.ReadBytes(StreamOffset, (int)StreamSize);
            _mainStream = new MemoryStream();
            _binReader = new BinaryReader(_mainStream);
            _binWriter = new BinaryWriter(_mainStream);
            _mainStream.Write(contents, 0, contents.Length);
            _mainStream.Seek(0, SeekOrigin.Begin);
        }
Пример #8
0
 private MetaDataStream GetHeap(NETHeader netheader, int headeroffset, Structures.METADATA_STREAM_HEADER rawHeader, string name)
 {
     switch (name)
     {
         case "#~":
         case "#-":
             return new TablesHeap(netheader, headeroffset, rawHeader, name);
         case "#Strings":
             return new StringsHeap(netheader, headeroffset, rawHeader, name);
         case "#US":
             return new UserStringsHeap(netheader, headeroffset, rawHeader, name);
         case "#GUID":
             return new GuidHeap(netheader, headeroffset, rawHeader, name);
         case "#Blob":
             return new BlobHeap(netheader, headeroffset, rawHeader, name);
         default:
             throw new ArgumentException("Metadatastream is not recognized as a valid heap.");
     }
 }
Пример #9
0
 private MetaDataStream GetHeap(NETHeader netheader, int headeroffset, Structures.METADATA_STREAM_HEADER rawHeader, string name)
 {
     switch (name)
     {
         case "#~":
         case "#-":
             return new TablesHeap(netheader, headeroffset, rawHeader, name);
         case "#Strings":
             return new StringsHeap(netheader, headeroffset, rawHeader, name);
         case "#US":
             return new UserStringsHeap(netheader, headeroffset, rawHeader, name);
         case "#GUID":
             return new GuidHeap(netheader, headeroffset, rawHeader, name);
         case "#Blob":
             return new BlobHeap(netheader, headeroffset, rawHeader, name);
         default:
             return new MetaDataStream(netheader, headeroffset, rawHeader, name);
     }
 }
Пример #10
0
 public BlobSignatureReader(byte[] bytes, NETHeader netHeader)
     : this(new MemoryStream(bytes), netHeader)
 {
 }
Пример #11
0
 public BlobSignatureReader(Stream input, NETHeader netHeader)
     : base(input)
 {
     _netHeader = netHeader;
 }
Пример #12
0
 internal UserStringsHeap(NETHeader netheader, int headeroffset, Structures.METADATA_STREAM_HEADER rawHeader, string name)
     : base(netheader, headeroffset, rawHeader, name)
 {
     stream = new MemoryStream(Contents);
     binaryreader = new BinaryReader(stream);
 }
Пример #13
0
 public MetaDataRow(uint offset, params ValueType[] parts)
 {
     this._offset = offset;
     this._parts = parts;
     this._netHeader = null;
 }
Пример #14
0
 internal NETHeaderReader(NTHeader header, NETHeader parent)
 {
     header.assembly.netHeader = parent;
         image = header.assembly.peImage;
         this.ntHeader = header;
 }
Пример #15
0
        /// <summary>
        /// Gets the Portable Executeable's NT header by specifing the assembly.
        /// </summary>
        /// <param name="assembly">The assembly to read the nt header</param>
        /// <returns></returns>
        public static NETHeader FromAssembly(Win32Assembly assembly)
        {
            NETHeader header = new NETHeader();

            header.assembly = assembly;
            header.reader = new NETHeaderReader(assembly.ntHeader, header);
            header.metadata = new MetaDataHeader(header.reader);
            header.reader.LoadData();
            header.flags = header.reader.netHeader.Flags;
            header.entryPointToken = header.reader.netHeader.EntryPointToken;
            header.TokenResolver = new MetaDataTokenResolver(header);
            return header;
        }
Пример #16
0
 public MetaDataRow(uint offset, params ValueType[] parts)
 {
     this._offset    = offset;
     this._parts     = parts;
     this._netHeader = null;
 }
Пример #17
0
 public BlobSignatureReader(Stream input, NETHeader netHeader)
     : base(input)
 {
     _netHeader = netHeader;
 }
Пример #18
0
 internal TablesHeap(NETHeader netheader, int headeroffset, Structures.METADATA_STREAM_HEADER rawHeader, string name)
     : base(netheader, headeroffset, rawHeader, name)
 {
 }
Пример #19
0
        private void UpdateNetDirectories(NETHeader newHeader)
        {
            ConstructNetDirectories(newHeader);

            // first stream has offset equal to md header size.
            uint mdSize = newHeader.MetaDataStreams[0]._streamHeader.Offset;

            // add sizes of streams.
            foreach (MetaDataStream stream in newHeader.MetaDataStreams)
                mdSize += stream.StreamSize;

            newHeader.MetaDataDirectory.Size = mdSize;

            // TODO: resources directory.
        }
Пример #20
0
 public BlobSignatureReader(byte[] bytes, NETHeader netHeader)
     : this(new MemoryStream(bytes), netHeader)
 {
 }
Пример #21
0
        /// <summary>
        /// Gets the Portable Executeable's NT header by specifing the assembly.
        /// </summary>
        /// <param name="assembly">The assembly to read the nt header</param>
        /// <returns></returns>
        public static NETHeader FromAssembly(Win32Assembly assembly)
        {
            NETHeader header = new NETHeader();

            header._assembly = assembly;
            NETHeaderReader reader = new NETHeaderReader(assembly._ntHeader, header);
            header._metadata = new MetaDataHeader(reader);
            reader.LoadData();
            header.TokenResolver = new MetaDataTokenResolver(header);
            return header;
        }
Пример #22
0
 internal UserStringsHeap(NETHeader netheader, int headeroffset, Structures.METADATA_STREAM_HEADER rawHeader, string name)
     : base(netheader, headeroffset, rawHeader, name)
 {
 }
Пример #23
0
 //MetaDataStream stream)
 //: base(stream)
 internal BlobHeap(NETHeader netheader, int headeroffset, Structures.METADATA_STREAM_HEADER rawHeader, string name)
     : base(netheader, headeroffset, rawHeader, name)
 {
     this.mainStream = new MemoryStream(Contents);
     this.mainReader = new BinaryReader(this.mainStream);
 }