fix: bug, syntax

This commit is contained in:
Dobin Rutishauser
2025-06-08 19:03:21 +02:00
parent 3b22f977ec
commit a9663d81a7
+7 -7
View File
@@ -37,7 +37,7 @@ class SuperPe():
def __init__(self, infile: str): def __init__(self, infile: str):
self.filepath: str = infile self.filepath: str = infile
self.pe_sections: List[PeSection] = [] self.pe_sections: List[PeSection] = []
self.pe = pefile.PE(infile, fast_load=False) self.pe: pefile.PE = pefile.PE(infile, fast_load=False)
for section in self.pe.sections: for section in self.pe.sections:
self.pe_sections.append(PeSection(section)) self.pe_sections.append(PeSection(section))
@@ -101,7 +101,9 @@ class SuperPe():
if sect.Characteristics & pefile.SECTION_CHARACTERISTICS['IMAGE_SCN_MEM_EXECUTE']: if sect.Characteristics & pefile.SECTION_CHARACTERISTICS['IMAGE_SCN_MEM_EXECUTE']:
if entrypoint >= sect.VirtualAddress and entrypoint <= sect.VirtualAddress + sect.Misc_VirtualSize: if entrypoint >= sect.VirtualAddress and entrypoint <= sect.VirtualAddress + sect.Misc_VirtualSize:
return sect return sect
return None
# there should always be a code section. Always.
raise Exception("pehelper::get_code_section(): Code section not found")
def get_code_section_data(self) -> bytes: def get_code_section_data(self) -> bytes:
@@ -109,7 +111,7 @@ class SuperPe():
return bytes(sect.get_data()) return bytes(sect.get_data())
def get_rwx_section(self) -> pefile.SectionStructure: def get_rwx_section(self) -> Optional[pefile.SectionStructure]:
# rwx section # rwx section
entrypoint = self.pe.OPTIONAL_HEADER.AddressOfEntryPoint entrypoint = self.pe.OPTIONAL_HEADER.AddressOfEntryPoint
for section in self.pe.sections: for section in self.pe.sections:
@@ -241,7 +243,7 @@ class SuperPe():
## IAT ## IAT
def get_vaddr_of_iatentry(self, func_name: str) -> int: def get_vaddr_of_iatentry(self, func_name: str) -> Optional[int]:
iat = self.get_iat_entries() iat = self.get_iat_entries()
for dll_name in iat: for dll_name in iat:
for entry in iat[dll_name]: for entry in iat[dll_name]:
@@ -365,8 +367,6 @@ class SuperPe():
def get_code_rangemanager(self) -> RangeManager: def get_code_rangemanager(self) -> RangeManager:
code_section = self.get_code_section() code_section = self.get_code_section()
if code_section == None:
raise Exception('Could not find code section in input PE file!')
code_section_size = code_section.Misc_VirtualSize code_section_size = code_section.Misc_VirtualSize
# Restrictions for putting data into .text: # Restrictions for putting data into .text:
@@ -434,4 +434,4 @@ def find_first_utf16_string_offset(data, min_len=8):
current_string = bytearray() current_string = bytearray()
start_offset = None # Reset start offset for the next string start_offset = None # Reset start offset for the next string
return None # No string found that meets the criteria return None # No string found that meets the criteria