Represents a .NET header from an application. This header is only available if the assembly is written in a .NET language.
Inheritance: IHeader, IDisposable, IDataDirectoryProvider, ICacheProvider
Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
 internal NETHeaderReader(NTHeader header, NETHeader parent)
 {
     this.parent = parent;
     header._assembly._netHeader = parent;
     image = header._assembly._peImage;
     this.ntHeader = header;
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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),
     };
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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.");
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 10
0
 public BlobSignatureReader(byte[] bytes, NETHeader netHeader)
     : this(new MemoryStream(bytes), netHeader)
 {
 }
Ejemplo n.º 11
0
 public BlobSignatureReader(Stream input, NETHeader netHeader)
     : base(input)
 {
     _netHeader = netHeader;
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 13
0
 public MetaDataRow(uint offset, params ValueType[] parts)
 {
     this._offset = offset;
     this._parts = parts;
     this._netHeader = null;
 }
Ejemplo n.º 14
0
 internal NETHeaderReader(NTHeader header, NETHeader parent)
 {
     header.assembly.netHeader = parent;
         image = header.assembly.peImage;
         this.ntHeader = header;
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 16
0
 public MetaDataRow(uint offset, params ValueType[] parts)
 {
     this._offset    = offset;
     this._parts     = parts;
     this._netHeader = null;
 }
Ejemplo n.º 17
0
 public BlobSignatureReader(Stream input, NETHeader netHeader)
     : base(input)
 {
     _netHeader = netHeader;
 }
Ejemplo n.º 18
0
 internal TablesHeap(NETHeader netheader, int headeroffset, Structures.METADATA_STREAM_HEADER rawHeader, string name)
     : base(netheader, headeroffset, rawHeader, name)
 {
 }
Ejemplo n.º 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.
        }
Ejemplo n.º 20
0
 public BlobSignatureReader(byte[] bytes, NETHeader netHeader)
     : this(new MemoryStream(bytes), netHeader)
 {
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 22
0
 internal UserStringsHeap(NETHeader netheader, int headeroffset, Structures.METADATA_STREAM_HEADER rawHeader, string name)
     : base(netheader, headeroffset, rawHeader, name)
 {
 }
Ejemplo n.º 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);
 }