Skip to content

Commit

Permalink
Adds PE32+ support to copydlldeps.py
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasWitzel authored and mabrand committed Mar 21, 2024
1 parent 930777f commit b09ee24
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tools/copydlldeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,20 @@ def get_imports(file):
f.seek(60)
pe_header_offset = struct.unpack('<L', f.read(4))[0]

# Is it PE32 or PE32+ ?
f.seek(pe_header_offset + 24)
pe_magic = struct.unpack('<H', f.read(2))[0]

# Get sizes of tables we need.
f.seek(pe_header_offset + 6)
number_of_sections = struct.unpack('<H', f.read(2))[0]
f.seek(pe_header_offset + 116)

# Determine position of the "NumberOfRvaAndSizes" field
if pe_magic == 0x20b:
f.seek(pe_header_offset + 132) # PE32+
else:
f.seek(pe_header_offset + 116) # PE32

number_of_data_directory_entries = struct.unpack('<L', f.read(4))[0]
data_directory_offset = f.tell() # it's right after the number of entries

Expand All @@ -59,7 +69,7 @@ def get_imports(file):
section_descriptor_data = f.read(40)
name, size, va, rawsize, offset = \
struct.unpack('<8sLLLL', section_descriptor_data[:24])
sections.append({'min': va, 'max': va+rawsize, 'offset': offset})
sections.append({'name': name, 'min': va, 'max': va+rawsize, 'offset': offset})

def seek_to_rva(rva):
for s in sections:
Expand Down

0 comments on commit b09ee24

Please sign in to comment.