diff --git a/app/templates/project.html b/app/templates/project.html index 414b75c..94fdccd 100644 --- a/app/templates/project.html +++ b/app/templates/project.html @@ -86,10 +86,18 @@
- x64: {{ is_64 }} / Dotnet: {{ is_dotnet}}
+ {% if is_64 %} + x64: {{ is_64 }} + {% else %} + x64: {{ is_64 }} + {% endif %} + / Dotnet: {{ is_dotnet}}
.text: {{ code_sect_size}}
.rodata: {{ data_sect_size}} (max: {{ data_sect_largest_gap_size}})
+ {% if not has_rodata_section %} + No .rodata section
+ {% endif %} {% if unresolved_dlls|length > 0 %}
@@ -129,7 +137,6 @@
- diff --git a/app/views.py b/app/views.py index 7c1e3c2..d0518e3 100644 --- a/app/views.py +++ b/app/views.py @@ -19,8 +19,14 @@ def index(): @views.route("/exes/") def exe_view(exe_name): - path = "{}/{}".format(PATH_EXES, exe_name) - superpe = SuperPe(path) + # TODO + filepath = "{}{}".format(PATH_EXES, exe_name) + if not os.path.exists(filepath): + filepath = "{}{}".format(PATH_EXES_MORE, exe_name) + if not os.path.exists(filepath): + return "File not found: {}".format(exe_name) + + superpe = SuperPe(filepath) return render_template('exe.html', superpe=superpe, diff --git a/app/views_project.py b/app/views_project.py index b98f2bf..33d5a59 100644 --- a/app/views_project.py +++ b/app/views_project.py @@ -71,15 +71,25 @@ def project(name): # when we selected an input file if project.settings.inject_exe_in != "" and os.path.exists(project.settings.inject_exe_in): superpe = SuperPe(project.settings.inject_exe_in) + #if not superpe.is_64(): + # # return 500 + # return "Error: Binary {} is not 64bit".format(project.settings.inject_exe_in), 500 + is_64 = superpe.is_64() is_dotnet = superpe.is_dotnet() if superpe.is_dll(): exports = superpe.get_exports_full() code_sect_size = superpe.get_code_section().Misc_VirtualSize - data_sect_size = superpe.get_section_by_name(".rdata").virt_size - exehost = ExeHost(project.settings.inject_exe_in) - exehost.init() - data_sect_largest_gap_size = exehost.get_rdata_relocmanager().find_largest_gap() + if superpe.get_section_by_name(".rdata") != None: + data_sect_size = superpe.get_section_by_name(".rdata").virt_size + else: + logger.warn("No .rdata section found in {}".format(project.settings.inject_exe_in)) + + has_rodata_section = superpe.has_rodata_section() + if has_rodata_section: + exehost = ExeHost(project.settings.inject_exe_in) + exehost.init() + data_sect_largest_gap_size = exehost.get_rdata_relocmanager().find_largest_gap() unresolved_dlls = pe.dllresolver.unresolved_dlls(superpe) @@ -120,6 +130,7 @@ def project(name): data_sect_largest_gap_size=data_sect_largest_gap_size, payload_len=payload_len, unresolved_dlls=unresolved_dlls, + has_rodata_section=has_rodata_section, has_remote=has_remote, ) diff --git a/model/exehost.py b/model/exehost.py index bc67c4c..9534aeb 100644 --- a/model/exehost.py +++ b/model/exehost.py @@ -35,7 +35,9 @@ class ExeHost(): self.superpe = SuperPe(self.filepath) if not self.superpe.is_64(): - raise Exception("Binary is not 64bit: {}".format(self.filepath)) + logger.warn("Binary is not 64bit: {}".format(self.filepath)) + return + #raise Exception("Binary is not 64bit: {}".format(self.filepath)) # image base self.image_base = self.superpe.pe.OPTIONAL_HEADER.ImageBase diff --git a/pe/superpe.py b/pe/superpe.py index e8dc82d..5f3619c 100644 --- a/pe/superpe.py +++ b/pe/superpe.py @@ -107,6 +107,10 @@ class SuperPe(): return section return None + + def has_rodata_section(self) -> bool: + return self.get_section_by_name(".rdata") + def write_code_section_data(self, data: bytes): sect = self.get_code_section() @@ -201,7 +205,6 @@ class SuperPe(): self.pe.set_dword_at_rva(addr + relocsSize + 4, sizeOfReloc) logger.info(f'Adding {len(relocs)} relocations for Page RVA 0x{pageRva:X} - size of block: 0x{sizeOfReloc:X}') - i = 0 for reloc in relocs: reloc_offset = (reloc - pageRva) diff --git a/supermega.py b/supermega.py index aa7246e..e6d5a9c 100644 --- a/supermega.py +++ b/supermega.py @@ -135,6 +135,9 @@ def start_real(settings: Settings): # Load our input project = Project(settings) project.init() + # check if 64 bit + if not project.exe_host.superpe.is_64(): + raise Exception("Binary is not 64bit: {}".format(project.settings.inject_exe_in)) logger.warning("--I FunctionInvokeStyle: {} Inject Mode: {} DecoderStyle: {}".format( project.settings.source_style.value, @@ -150,6 +153,16 @@ def start_real(settings: Settings): c_in = settings.main_c_path, asm_out = settings.main_asm_path, carrier = project.carrier) + + # we have the required IAT entries in carrier.iat_requests + # Check if all are available, or abort (early check) + if settings.source_style == FunctionInvokeStyle.iat_reuse: + functions = [] + for iat in project.carrier.iat_requests: + if project.exe_host.get_vaddr_of_iatentry(iat.name) == None: + functions.append(iat.name) + if len(functions) > 0: + raise Exception("IAT entry not found: {}".format(", ".join(functions))) # Assemble: Assemble .asm to .shc (ASM -> SHC) if settings.generate_shc_from_asm: