diff --git a/app/views_project.py b/app/views_project.py index a761134..415774e 100644 --- a/app/views_project.py +++ b/app/views_project.py @@ -48,17 +48,17 @@ def project(name): if os.path.exists(exe_path): is_built = True - exports = None + exports = [] is_64 = False is_dotnet = False - # Only when we selected an input file + # when we selected an input file if project.settings.inject_exe_in != "": superpe = SuperPe(project.settings.inject_exe_in) is_64 = superpe.is_64() is_dotnet = superpe.is_dotnet() if superpe.is_dll(): - exports = [ "", "BZ2_blockSort" ] + exports = superpe.get_exports() project_dir = os.path.dirname(os.path.abspath(project.settings.inject_exe_out)) log_files = get_logfiles(project.settings.main_dir) diff --git a/pe/superpe.py b/pe/superpe.py index 2790a3a..f0183cc 100644 --- a/pe/superpe.py +++ b/pe/superpe.py @@ -48,7 +48,7 @@ class SuperPe(): self.ptrSize = 8 - def is_dll(self): + def is_dll(self) -> bool: return self.filepath.endswith(".dll") @@ -57,7 +57,6 @@ class SuperPe(): def is_dotnet(self) -> bool: - # DotNet or not # https://stackoverflow.com/questions/45574925/is-there-a-way-to-check-if-an-exe-is-dot-net-with-python-pefile entry = self.pe.OPTIONAL_HEADER.DATA_DIRECTORY[14] if entry.VirtualAddress != 0 and entry.Size != 0: @@ -235,6 +234,18 @@ class SuperPe(): i += 1 + def get_exports(self) -> List[str]: + """Return a list of exported functions (names) from the PE file""" + d = [pefile.DIRECTORY_ENTRY["IMAGE_DIRECTORY_ENTRY_EXPORT"]] + self.pe.parse_data_directories(directories=d) + if self.pe.DIRECTORY_ENTRY_EXPORT.symbols == 0: + return [] + res = [] + for e in self.pe.DIRECTORY_ENTRY_EXPORT.symbols: + res.append(e.name.decode()) + return res + + ## Helpers def get_entrypoint(self) -> int: