Esempio n. 1
0
        public static PEHeaderParser FromFile(String filename, Action <PDBContainer> PDBContainerGetter = null)
        {
            if (!File.Exists(filename))
            {
                throw new FileNotFoundException(filename);
            }
            PEHeaderParser ret = new PEHeaderParser();

            ret.Read(filename, PDBContainerGetter);

            return(ret);
        }
Esempio n. 2
0
            public static PDBContainer FromBinaryReader(BinaryReader r, PEHeaderParser parser, bool parsingFile = true)
            {
                IMAGE_DATA_DIRECTORY selectDirectory = parser.NTHeader.OptionalHeader.DebuggingInformation;


                long addr = 0;

                if (parsingFile)
                {
                    for (int i = 0; i < parser.SectionHeaders.Count; ++i)
                    {
                        var section = parser.SectionHeaders[i];
                        if (selectDirectory.VirtualAddress >= section.VirtualAddress && selectDirectory.VirtualAddress <= section.VirtualAddress + section.VirtualSize)
                        {
                            addr = selectDirectory.VirtualAddress - section.VirtualAddress + section.PointerToRawData;
                        }
                    }
                }
                else
                {
                    addr = selectDirectory.VirtualAddress;
                }
                if (selectDirectory.Size > 0 && addr > 0)
                {
                    r.BaseStream.Position = addr;
                    byte[] buf = r.ReadBytes(unchecked ((int)selectDirectory.Size));
                    using (BinaryReader bufFetcher = new BinaryReader(new MemoryStream(buf)))
                    {
                        bufFetcher.BaseStream.Position = 0;
                        DebugDataDirectory debugData = new DebugDataDirectory();
                        debugData.Characteristics = bufFetcher.ReadUInt32();
                        debugData.TimeDateStamp   = bufFetcher.ReadUInt32();
                        debugData.MajorVersion    = bufFetcher.ReadUInt16();
                        debugData.MinorVersion    = bufFetcher.ReadUInt16();

                        debugData.Type             = bufFetcher.ReadUInt32();
                        debugData.SizeOfData       = bufFetcher.ReadUInt32();
                        debugData.AddressOfRawData = bufFetcher.ReadUInt32();
                        debugData.PointerToRawData = bufFetcher.ReadUInt32();
                        if (debugData.SizeOfData > 0 && debugData.PointerToRawData != 0)
                        {
                            PDBContainer pdbContainer = new PDBContainer(debugData.SizeOfData, parser);
                            r.BaseStream.Position = debugData.PointerToRawData;
                            pdbContainer.RawPdb   = r.ReadBytes(unchecked ((int)debugData.SizeOfData));
                            pdbContainer.FillBaseInfo(0, parser.FileSize, selectDirectory.VirtualAddress);
                            return(pdbContainer);
                        }
                    }
                }
                return(null);
            }
Esempio n. 3
0
 public PDBContainer(uint size, PEHeaderParser parser)
 {
     this.ImageSize = size;
     this.Parser    = parser;
 }