Example #1
0
        const ushort DosSignature = 0x5a4d; // MZ

        #endregion Fields

        #region Methods

        public static DosHeader Parse(BinaryReader br)
        {
            PscxArgumentException.ThrowIfIsNull(br);

            ushort signature = br.ReadUInt16();
            if (DosSignature != signature) {
                InvalidPEFileException.ThrowInvalidDosHeader();
            }

            DosHeader hdr = new DosHeader();

            hdr.BytesOnLastPage = br.ReadUInt16();
            hdr.PageCount = br.ReadUInt16();
            hdr.RelocationCount = br.ReadUInt16();
            hdr.HeaderSize = br.ReadUInt16();
            hdr.MinExtraParagraphs = br.ReadUInt16();
            hdr.MaxExtraParagraphs = br.ReadUInt16();
            hdr.InitialSS = br.ReadUInt16();
            hdr.InitialSP = br.ReadUInt16();
            hdr.Checksum = br.ReadUInt16();
            hdr.InitialIP = br.ReadUInt16();
            hdr.InitialCS = br.ReadUInt16();
            hdr.RelocationTableOffset = br.ReadUInt16();
            hdr.OverlayNumber = br.ReadUInt16();

            // reserved words
            for (int i = 0; i < 4; i++) br.ReadUInt16();

            hdr.OemID = br.ReadUInt16();
            hdr.OemInfo = br.ReadUInt16();

            // reserved words
            for (int i = 0; i < 10; i++) br.ReadUInt16();

            hdr.CoffHeaderOffset = br.ReadUInt32();

            return hdr;
        }
Example #2
0
        public PortableExecutableInfo(string path)
        {
            this.imagePath = path;

            using(Stream stream = OpenImage())
            {
                using (BinaryParser br = new BinaryParser(stream))
                {
                    dosHeader = DosHeader.Parse(br);

                    br.SkipTo(dosHeader.CoffHeaderOffset);

                    coffHeader = br.ReadRecord<CoffHeader>();
                    peHeader = PEHeader.Parse(br);

                    sections = new List<PESection>();
                    for (int i = 0; i < coffHeader.NumberOfSections; i++)
                    {
                        sections.Add(br.ReadRecord<PESection>());
                    }
                }
            }
        }
Example #3
0
        public PortableExecutableInfo(string path)
        {
            this.imagePath = path;

            using (Stream stream = OpenImage())
            {
                using (BinaryParser br = new BinaryParser(stream))
                {
                    dosHeader = DosHeader.Parse(br);

                    br.SkipTo(dosHeader.CoffHeaderOffset);

                    coffHeader = br.ReadRecord <CoffHeader>();
                    peHeader   = PEHeader.Parse(br);

                    sections = new List <PESection>();
                    for (int i = 0; i < coffHeader.NumberOfSections; i++)
                    {
                        sections.Add(br.ReadRecord <PESection>());
                    }
                }
            }
        }