Example #1
0
 public StreamHeader(AssemblyBuffer buffer, CLRHeader clrHeader)
 {
     this.Offset          = buffer.ReadDWord();
     this.Size            = buffer.ReadDWord();
     this.Name            = buffer.ReadDwordAlignedString();
     this.AbsoluteAddress = (clrHeader.MetaData.RVA - 0x1E00) + this.Offset;
 }
Example #2
0
        private CLRHeader ReadCLRHeader(BinaryReader assemblyReader, PEHeader peHeader)
        {
            var clrDirectoryHeader = peHeader.Directories[(int)DataDirectoryName.CLRHeader];
            var clrDirectoryData   = ReadVirtualDirectory(assemblyReader, clrDirectoryHeader, peHeader.Sections);

            using (var reader = new BinaryReader(new MemoryStream(clrDirectoryData)))
            {
                var a = new CLRHeader
                {
                    HeaderSize               = reader.ReadUInt32(),
                    MajorRuntimeVersion      = reader.ReadUInt16(),
                    MinorRuntimeVersion      = reader.ReadUInt16(),
                    MetaDataDirectoryAddress = reader.ReadUInt32(),
                    MetaDataDirectorySize    = reader.ReadUInt32(),
                    Flags                          = reader.ReadUInt32(),
                    EntryPointToken                = reader.ReadUInt32(),
                    ResourcesDirectoryAddress      = reader.ReadUInt32(),
                    ResourcesDirectorySize         = reader.ReadUInt32(),
                    StrongNameSignatureAddress     = reader.ReadUInt32(),
                    StrongNameSignatureSize        = reader.ReadUInt32(),
                    CodeManagerTableAddress        = reader.ReadUInt32(),
                    CodeManagerTableSize           = reader.ReadUInt32(),
                    VTableFixupsAddress            = reader.ReadUInt32(),
                    VTableFixupsSize               = reader.ReadUInt32(),
                    ExportAddressTableJumpsAddress = reader.ReadUInt32(),
                    ExportAddressTableJumpsSize    = reader.ReadUInt32(),
                    ManagedNativeHeaderAddress     = reader.ReadUInt32(),
                    ManagedNativeHeaderSize        = reader.ReadUInt32()
                };
                return(a);
            }
        }
Example #3
0
        private void ReadCLRHeader()
        {
            var clr = _directories[DIRECTORY_ENTRY_COM_DESCRIPTOR];

            MoveTo(ResolveVirtualAddress(clr.RVA));
            _clrHeader = ReadStruct <CLRHeader>();
        }
Example #4
0
 internal CLRMetaData(CLRContent clr, Location location, CLRHeader header)
 {
     CLR = clr;
     Location = location;
     Header = new CLRMetaDataHeader(this);
     StreamTable = new CLRMetaDataStreamTable(this);
     Streams = new CLRMetaDataStreams(this);
 }
        public DefsAndRefsStream(AssemblyBuffer buffer, CLRHeader clrHeader, MetaDataHeader metaDataHeader) :
            base(buffer, clrHeader)
        {
            this._metaDataHeader = metaDataHeader;
            this.TableLengths    = new uint[64];
            this.TableRows       = new Dictionary <MetaDataTableType, List <TableRow> >();

            Instance = this;
        }
Example #6
0
        public void WhenIReadTheCLRHeader()
        {
            var fileName = ScenarioContext.Current.Get <string>("FileName");
            var filePath = string.Format(@".\TestArtifacts\{0}", fileName);

            if (!File.Exists(filePath))
            {
                filePath = string.Format(@".\{0}", fileName);
                Console.WriteLine(string.Format(@"File not Found: .\TestArtifacts\{0}", fileName));
            }
            using (FileStream inputFile = File.OpenRead(filePath))
            {
                var optionalHeaderDataDirectories = ScenarioContext.Current.Get <OptionalHeaderDataDirectories>("OptionalHeaderDataDirectories");
                var sectionTables = ScenarioContext.Current.Get <List <SectionTable> >("SectionTables");
                inputFile.Position = CLRHeader.StartingPosition(optionalHeaderDataDirectories, sectionTables);
                CLRHeader?clrHeader =
                    inputFile.ReadStructure <CLRHeader>();
                ScenarioContext.Current.Add("CLRHeader", clrHeader.Value);
            }
        }
Example #7
0
 public BlobStream(AssemblyBuffer buffer, CLRHeader clrHeader) :
     base(buffer, clrHeader)
 {
 }
Example #8
0
        public static CLRMetaData Get(CLRHeader header)
        {
            LocationCalculator calc = header.CLR.DataDirectory.Directories.Image.GetCalculator();
            ulong image_base = header.CLR.DataDirectory.Directories.Image.NTHeaders.OptionalHeader.ImageBase;
            uint rva = header.MetaDataAddress;
            ulong va = image_base + rva;
            ulong offset = calc.RVAToOffset(rva);
            uint size = header.MetaDataSize;
            Section section = calc.RVAToSection(rva);
            Location location = new Location(offset, rva, va, size, size, section);
            CLRMetaData meta_data = new CLRMetaData(header.CLR, location, header);

            return meta_data;
        }