feature: calculate offset into .rdata (tmp)

This commit is contained in:
Dobin
2024-03-03 16:58:44 +00:00
parent d3a750288e
commit 286ad055d3
3 changed files with 43 additions and 2 deletions
+14
View File
@@ -8,6 +8,7 @@ from helper import hexdump
logger = logging.getLogger("superpe")
class PeSection():
def __init__(self, pefile_section: pefile.SectionStructure):
self.name: str = pefile_section.Name.rstrip(b'\x00').decode("utf-8")
@@ -16,6 +17,7 @@ class PeSection():
self.virt_addr: int = pefile_section.VirtualAddress
self.virt_size: int = pefile_section.Misc_VirtualSize
class SuperPe():
IMAGE_DIRECTORY_ENTRY_SECURITY = 4
IMAGE_DIRECTORY_ENTRY_BASERELOC = 5
@@ -88,6 +90,18 @@ class SuperPe():
return bytes(sect.get_data())
def get_section_data(self, sect_name) -> bytes:
sect = self.get_section_by_name_b(sect_name)
return bytes(sect.get_data())
def get_section_by_name_b(self, name):
for sect in self.pe.sections:
if sect.Name.decode().lower().startswith(name.lower()):
return sect
return None
def write_code_section_data(self, data: bytes):
sect = self.get_code_section()
self.pe.set_bytes_at_offset(sect.PointerToRawData, data)