mirror of
https://github.com/dobin/SuperMega
synced 2026-06-03 01:27:11 +00:00
refactor: make log/observer nice
This commit is contained in:
+3
-3
@@ -22,7 +22,7 @@ def asm_to_shellcode(asm_in: FilePath, build_exe: FilePath, shellcode_out: FileP
|
||||
if not os.path.isfile(build_exe):
|
||||
raise Exception("Compiling failed")
|
||||
code = extract_code_from_exe_file(build_exe)
|
||||
observer.add_code("carrier_shc", code)
|
||||
observer.add_code_file("carrier_shc", code)
|
||||
with open(shellcode_out, 'wb') as f:
|
||||
f.write(code)
|
||||
|
||||
@@ -35,7 +35,7 @@ def merge_loader_payload(
|
||||
):
|
||||
logger.info("--[ Merge stager with payload -> {}".format(
|
||||
shellcode_out))
|
||||
observer.add_code("payload_shc", payload_data)
|
||||
observer.add_code_file("payload_shc", payload_data)
|
||||
|
||||
with open(shellcode_in, 'rb') as input1:
|
||||
data_stager = input1.read()
|
||||
@@ -55,5 +55,5 @@ def merge_loader_payload(
|
||||
# append them
|
||||
data = data_stager + payload_data
|
||||
output.write(data)
|
||||
observer.add_code("loader_shc", data)
|
||||
observer.add_code_file("loader_shc", data)
|
||||
|
||||
+7
-7
@@ -36,7 +36,7 @@ def compile_dev(
|
||||
if not os.path.isfile(asm_out):
|
||||
raise Exception("Error: Compiling failed")
|
||||
file_to_lf(asm_out)
|
||||
observer.add_text("carrier_asm_orig", file_readall_text(asm_out))
|
||||
observer.add_text_file("carrier_asm_orig", file_readall_text(asm_out))
|
||||
|
||||
# Assembly cleanup (masm_shc)
|
||||
asm_clean_file = asm_out + ".clean"
|
||||
@@ -55,7 +55,7 @@ def compile_dev(
|
||||
# Move to destination we expect
|
||||
shutil.move(asm_clean_file, asm_out)
|
||||
if config.debug:
|
||||
observer.add_text("carrier_asm_cleanup", file_readall_text(asm_out))
|
||||
observer.add_text_file("carrier_asm_cleanup", file_readall_text(asm_out))
|
||||
|
||||
|
||||
def compile(
|
||||
@@ -81,7 +81,7 @@ def compile(
|
||||
if not os.path.isfile(asm_out):
|
||||
raise Exception("Error: Compiling failed")
|
||||
file_to_lf(asm_out)
|
||||
observer.add_text("carrier_asm_orig", file_readall_text(asm_out))
|
||||
observer.add_text_file("carrier_asm_orig", file_readall_text(asm_out))
|
||||
|
||||
# DataReuse first
|
||||
asmFileParser = ReusedataAsmFileParser(asm_out)
|
||||
@@ -96,7 +96,7 @@ def compile(
|
||||
raise Exception("Error: Fixup failed")
|
||||
|
||||
if config.debug:
|
||||
observer.add_text("carrier_asm_fixup", file_readall_text(asm_out))
|
||||
observer.add_text_file("carrier_asm_fixup", file_readall_text(asm_out))
|
||||
|
||||
# Assembly cleanup (masm_shc)
|
||||
asm_clean_file = asm_out + ".clean"
|
||||
@@ -114,7 +114,7 @@ def compile(
|
||||
|
||||
if source_style == SourceStyle.iat_reuse:
|
||||
fixup_iat_reuse(asm_clean_file, carrier)
|
||||
observer.add_text("carrier_asm_updated", file_readall_text(asm_clean_file))
|
||||
observer.add_text_file("carrier_asm_updated", file_readall_text(asm_clean_file))
|
||||
|
||||
if not exe_host.has_all_carrier_functions(carrier):
|
||||
logger.error("Error: Not all carrier functions are available in the target exe")
|
||||
@@ -123,7 +123,7 @@ def compile(
|
||||
# Move to destination we expect
|
||||
shutil.move(asm_clean_file, asm_out)
|
||||
if config.debug:
|
||||
observer.add_text("carrier_asm_cleanup", file_readall_text(asm_out))
|
||||
observer.add_text_file("carrier_asm_cleanup", file_readall_text(asm_out))
|
||||
|
||||
|
||||
def bytes_to_asm_db(byte_data: bytes) -> bytes:
|
||||
@@ -224,4 +224,4 @@ def fixup_iat_reuse(filename: FilePath, carrier: Carrier):
|
||||
asmfile.writelines(lines)
|
||||
|
||||
if config.debug:
|
||||
observer.add_text("carrier_asm_iat_patch", file_readall_text(filename))
|
||||
observer.add_text_file("carrier_asm_iat_patch", file_readall_text(filename))
|
||||
|
||||
+2
-2
@@ -67,8 +67,8 @@ def inject_exe(
|
||||
in_code = code[peinj.shellcodeOffsetRel:peinj.shellcodeOffsetRel+shellcode_len]
|
||||
jmp_code = code[peinj.backdoorOffsetRel:peinj.backdoorOffsetRel+12]
|
||||
if config.debug:
|
||||
observer.add_code("exe_extracted_loader", in_code)
|
||||
observer.add_code("exe_extracted_jmp", jmp_code)
|
||||
observer.add_code_file("exe_extracted_loader", in_code)
|
||||
observer.add_code_file("exe_extracted_jmp", jmp_code)
|
||||
#if in_code != shellcode:
|
||||
# raise Exception("Shellcode injection error")
|
||||
|
||||
|
||||
+6
-6
@@ -57,7 +57,7 @@ def create_c_from_template(
|
||||
if use_templates:
|
||||
with open(PATH_PEB_WALK + "template.c", 'r', encoding='utf-8') as file:
|
||||
template_content = file.read()
|
||||
observer.add_text("main_c_template", template_content)
|
||||
observer.add_text_file("main_c_template", template_content)
|
||||
|
||||
template = Template(template_content)
|
||||
rendered_template = template.render({
|
||||
@@ -68,12 +68,12 @@ def create_c_from_template(
|
||||
})
|
||||
with open(main_c_file, "w", encoding='utf-8') as file:
|
||||
file.write(rendered_template)
|
||||
observer.add_text("main_c_rendered", rendered_template)
|
||||
observer.add_text_file("main_c_rendered", rendered_template)
|
||||
|
||||
# TODO PEB
|
||||
shutil.copy(PATH_PEB_WALK + "peb_lookup.h", f"{build_dir}/peb_lookup.h")
|
||||
else:
|
||||
observer.add_text("main_c", file_readall_text(PATH_PEB_WALK + "main.c"))
|
||||
observer.add_text_file("main_c", file_readall_text(PATH_PEB_WALK + "main.c"))
|
||||
shutil.copy(PATH_PEB_WALK + "main.c", main_c_file)
|
||||
# TODO PEB
|
||||
shutil.copy(PATH_PEB_WALK + "peb_lookup.h", f"{build_dir}/peb_lookup.h")
|
||||
@@ -82,7 +82,7 @@ def create_c_from_template(
|
||||
if use_templates:
|
||||
with open(PATH_IAT_REUSE + "template.c", 'r', encoding='utf-8') as file:
|
||||
template_content = file.read()
|
||||
observer.add_text("main_c_template", template_content)
|
||||
observer.add_text_file("main_c_template", template_content)
|
||||
template = Template(template_content)
|
||||
rendered_template = template.render({
|
||||
'plugin_allocator': plugin_allocator,
|
||||
@@ -92,7 +92,7 @@ def create_c_from_template(
|
||||
})
|
||||
with open(main_c_file, "w", encoding='utf-8') as file:
|
||||
file.write(rendered_template)
|
||||
observer.add_text("main_c_rendered", rendered_template)
|
||||
observer.add_text_file("main_c_rendered", rendered_template)
|
||||
else:
|
||||
observer.add_text("main_c", file_readall_text(PATH_IAT_REUSE + "main.c"))
|
||||
observer.add_text_file("main_c", file_readall_text(PATH_IAT_REUSE + "main.c"))
|
||||
shutil.copy(PATH_IAT_REUSE + "main.c", main_c_file)
|
||||
Reference in New Issue
Block a user