From 9c89ddce1a736f63e655ae07da0b3855b34b8702 Mon Sep 17 00:00:00 2001 From: Clement Rouault Date: Thu, 17 Sep 2015 16:08:14 +0200 Subject: [PATCH] Add PESection : IMAGE_SECTION_HEADER with a name easy to read --- pe_parse.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pe_parse.py b/pe_parse.py index bc01364..3609dd0 100644 --- a/pe_parse.py +++ b/pe_parse.py @@ -123,6 +123,8 @@ def PEFile(baseaddr, target=None): self.hook.disable() self.hook = None return True + + class PEFile(object): def __init__(self): @@ -163,14 +165,22 @@ def PEFile(baseaddr, target=None): return create_structure_at(self._IMAGE_EXPORT_DIRECTORY, export_directory_addr) #return self._IMAGE_EXPORT_DIRECTORY.from_address(export_directory_addr) + class PESection(ctypes_structure_transformer(IMAGE_SECTION_HEADER)): + @utils.fixedpropety + def name(self): + return ctypes.c_char_p(ctypes.addressof(self.Name)).value + + def __repr__(self): + return "".format(self.name) + @utils.fixedpropety def sections(self): nt_header = self.get_NT_HEADER() nb_section = nt_header.FileHeader.NumberOfSections base_section = ctypes.addressof(nt_header) + ctypes.sizeof(nt_header) - IMAGE_SECTION_H = ctypes_structure_transformer(IMAGE_SECTION_HEADER) - sections_array = create_structure_at(IMAGE_SECTION_H * nb_section, base_section) - return (sections_array) + #IMAGE_SECTION_H = ctypes_structure_transformer(IMAGE_SECTION_HEADER) + sections_array = create_structure_at(self.PESection * nb_section, base_section) + return list(sections_array) @utils.fixedpropety def exports(self):