Skip to content

Commit f8a3a70

Browse files
author
bitform
committed
Fixed bug in executables with no imports/exports
I now check for the existance of imports/exports in the data directory.
1 parent 65ebaea commit f8a3a70

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

PETools/Get-PEHeader.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,11 @@ $code = @"
665665

666666
function Get-Exports()
667667
{
668+
669+
if ($NTHeader.OptionalHeader.DataDirectory[0].VirtualAddress -eq 0) {
670+
Write-Verbose 'Module does not contain any exports'
671+
return
672+
}
668673

669674
# List all function Rvas in the export table
670675
$ExportPointer = [IntPtr] ($PEBaseAddr.ToInt64() + $NtHeader.OptionalHeader.DataDirectory[0].VirtualAddress)
@@ -759,6 +764,11 @@ $code = @"
759764

760765
function Get-Imports()
761766
{
767+
if ($NTHeader.OptionalHeader.DataDirectory[1].VirtualAddress -eq 0) {
768+
Write-Verbose 'Module does not contain any imports'
769+
return
770+
}
771+
762772
$FirstImageImportDescriptorPtr = [IntPtr] ($PEBaseAddr.ToInt64() + $NtHeader.OptionalHeader.DataDirectory[1].VirtualAddress)
763773
if ($OnDisk) { $FirstImageImportDescriptorPtr = Convert-RVAToFileOffset $FirstImageImportDescriptorPtr }
764774
$ImportDescriptorPtr = $FirstImageImportDescriptorPtr

0 commit comments

Comments
 (0)