Exemplo n.º 1
0
        internal PeImage(Memory <byte> imageBytes)
        {
            using var peReader = new PEReader(new MemoryStream(imageBytes.ToArray()));

            BaseRelocationDirectory = new BaseRelocationDirectory(peReader.PEHeaders, imageBytes);

            DelayImportDirectory = new DelayImportDirectory(peReader.PEHeaders, imageBytes);

            ExportDirectory = new ExportDirectory(peReader.PEHeaders, imageBytes);

            Headers = peReader.PEHeaders;

            ImportDirectory = new ImportDirectory(peReader.PEHeaders, imageBytes);

            LoadConfigDirectory = new LoadConfigDirectory(peReader.PEHeaders, imageBytes);

            var debugDirectoryEntries = peReader.ReadDebugDirectory();

            if (debugDirectoryEntries.Any(entry => entry.Type == DebugDirectoryEntryType.CodeView))
            {
                var codeViewEntry = debugDirectoryEntries.First(entry => entry.Type == DebugDirectoryEntryType.CodeView);

                PdbData = peReader.ReadCodeViewDebugDirectoryData(codeViewEntry);
            }

            TlsDirectory = new TlsDirectory(peReader.PEHeaders, imageBytes);

            ValidatePeImage();
        }
Exemplo n.º 2
0
        internal PeImage(Memory <byte> imageBytes)
        {
            using var peReader = new PEReader(imageBytes.ToArray().ToImmutableArray());

            if (peReader.PEHeaders.PEHeader is null || !peReader.PEHeaders.IsDll)
            {
                throw new BadImageFormatException("The provided file was not a valid DLL");
            }

            ExportDirectory     = new ExportDirectory(peReader.PEHeaders, imageBytes);
            Headers             = peReader.PEHeaders;
            ImportDirectory     = new ImportDirectory(peReader.PEHeaders, imageBytes);
            LoadConfigDirectory = new LoadConfigDirectory(peReader.PEHeaders, imageBytes);
            RelocationDirectory = new RelocationDirectory(peReader.PEHeaders, imageBytes);
            ResourceDirectory   = new ResourceDirectory(peReader.PEHeaders, imageBytes);
            TlsDirectory        = new TlsDirectory(peReader.PEHeaders, imageBytes);
        }
Exemplo n.º 3
0
        internal PeImage(Memory <byte> imageBuffer)
        {
            using var peReader = new PEReader(new MemoryStream(imageBuffer.ToArray()));

            BaseRelocationDirectory = new BaseRelocationDirectory(peReader.PEHeaders, imageBuffer);

            DelayImportDirectory = new DelayImportDirectory(peReader.PEHeaders, imageBuffer);

            ExportDirectory = new ExportDirectory(peReader.PEHeaders, imageBuffer);

            Headers = peReader.PEHeaders;

            ImportDirectory = new ImportDirectory(peReader.PEHeaders, imageBuffer);

            LoadConfigDirectory = new LoadConfigDirectory(peReader.PEHeaders, imageBuffer);

            TlsDirectory = new TlsDirectory(peReader.PEHeaders, imageBuffer);

            ValidatePeImage();
        }
Exemplo n.º 4
0
        private void FileOpen(string file)
        {
            // Set status bar location for the file.
            tbStatusBarLocation.Text = file;

            // Parse the PE file
            if (!PeFile.IsPEFile(file))
            {
                ShowInvalidPeFileMsgBox();
                return;
            }

            _peFile = new PeFile(file);

            // Set all FileInfo fields.
            FileInfo.SetFileInfo(_peFile);

            // Set the DOS header fields
            DosNtHeader.SetDosHeader(_peFile);

            // Set the PE File fields
            DosNtHeader.SetNtHeader(_peFile);

            // Set the File header
            FileHeaderDebug.SetFileHeader(_peFile);

            // Set the Debug directory.
            FileHeaderDebug.SetDebug(_peFile);

            // Set the Optional header
            OptionalHeader.SetOptionalHeader(_peFile);

            // Set the imports.
            Imports.SetImports(_peFile);

            // Set the exports.
            Exports.SetExports(_peFile);

            // Set the resources.
            Resource.SetResources(_peFile);

            // Set the sections.
            SectionHeaders.SetSections(_peFile);

            // Set the Exception (only for x64)
            Exceptions.SetException(_peFile);

            // Set the Relocations.
            Relocation.SetRelocations(_peFile);

            // Set the Digital Signature information.
            Signature.SetDigSignature(_peFile);

            // Set the Bound Import directory.
            DebugBoundImport.SetBoundImport(_peFile);

            // Set the Delay Import descriptor.
            DebugBoundImport.SetDelayImport(_peFile);

            // Set the TLS directory.
            TlsDirectory.SetTlsDirectory(_peFile);

            // Set the Load Config Directory
            LoadConfig.SetLoadConfig(_peFile);

            // Set the Data Directory View
            DirectoryView.SetDirectoryView(_peFile);
        }