diff --git a/phases/templater.py b/phases/templater.py index 14a6ac8..ec0fe54 100644 --- a/phases/templater.py +++ b/phases/templater.py @@ -23,6 +23,7 @@ def create_c_from_template( alloc_style: AllocStyle, exec_style: ExecStyle, decoder_style: DecoderStyle, + payload_len: int, ): plugin_allocator = "" plugin_decoder = "" @@ -31,6 +32,9 @@ def create_c_from_template( filepath = "plugins/allocator/{}.c".format(alloc_style.value) with open(filepath, "r", encoding='utf-8') as file: plugin_allocator = file.read() + plugin_allocator = Template(plugin_allocator).render({ + 'PAYLOAD_LEN': payload_len, + }) filepath = "plugins/decoder/{}.c".format(decoder_style.value) with open(filepath, "r", encoding='utf-8') as file: diff --git a/plugins/allocator/rwx_1.c b/plugins/allocator/rwx_1.c index fb6ffa8..559bb4b 100644 --- a/plugins/allocator/rwx_1.c +++ b/plugins/allocator/rwx_1.c @@ -1 +1 @@ - char *dest = VirtualAlloc(NULL, 4096, 0x3000, 0x40); \ No newline at end of file + char *dest = VirtualAlloc(NULL, {{PAYLOAD_LEN}}, 0x3000, 0x40); \ No newline at end of file diff --git a/r2helper.py b/r2helper.py index 98abe88..9f6938c 100644 --- a/r2helper.py +++ b/r2helper.py @@ -19,6 +19,11 @@ def r2_disas(data: bytes): f.write(data) code_len = len(data) + if code_len > 0x2000: + ret['text'] = "Code too long for r2: {}".format(code_len) + ret['color'] = "Code too long for r2: {}".format(code_len) + return ret + r2 = r2pipe.open(filename, flags=['-2']) r2.cmd('aaa') diff --git a/supermega.py b/supermega.py index 2b8e671..111b488 100644 --- a/supermega.py +++ b/supermega.py @@ -125,6 +125,7 @@ def start(): alloc_style = project.alloc_style, exec_style = project.exec_style, decoder_style= project.decoder_style, + payload_len = len(project.payload_data), ) # Compile: IAT_REUSE loader C -> ASM if project.generate_asm_from_c: @@ -153,6 +154,7 @@ def start(): alloc_style = project.alloc_style, exec_style = project.exec_style, decoder_style= project.decoder_style, + payload_len = len(project.payload_data), ) # Compile: PEB_WALK C -> ASM if project.generate_asm_from_c: