mirror of
https://github.com/dobin/SuperMega
synced 2026-06-02 17:27:10 +00:00
refactor: remove source_style enum, do it with directories
This commit is contained in:
+25
-30
@@ -1,6 +1,7 @@
|
||||
from jinja2 import Template
|
||||
import shutil
|
||||
import logging
|
||||
from typing import List
|
||||
|
||||
from helper import *
|
||||
from observer import observer
|
||||
@@ -10,6 +11,17 @@ from model.settings import Settings
|
||||
logger = logging.getLogger("Assembler")
|
||||
|
||||
|
||||
def get_template_names() -> List[str]:
|
||||
templates = []
|
||||
for filename in os.listdir(PATH_CARRIER):
|
||||
if filename.startswith("."):
|
||||
continue
|
||||
if filename == "common" or filename == "decoder":
|
||||
continue
|
||||
templates.append(filename)
|
||||
return templates
|
||||
|
||||
|
||||
def create_c_from_template(settings: Settings, payload_len: int):
|
||||
logger.info("--( Create C from template: {} -> {}".format(
|
||||
PATH_DECODER, settings.main_c_path))
|
||||
@@ -24,34 +36,17 @@ def create_c_from_template(settings: Settings, payload_len: int):
|
||||
'XOR_KEY': config.xor_key,
|
||||
})
|
||||
|
||||
# C Template: peb_walk
|
||||
if settings.source_style == FunctionInvokeStyle.peb_walk:
|
||||
with open(settings.template_path, 'r', encoding='utf-8') as file:
|
||||
template_content = file.read()
|
||||
observer.add_text_file("main_c_template", template_content)
|
||||
# Choose correct template
|
||||
dirpath = PATH_CARRIER + settings.carrier_name + "/template.c"
|
||||
with open(dirpath, 'r', encoding='utf-8') as file:
|
||||
template_content = file.read()
|
||||
observer.add_text_file("main_c_template", template_content)
|
||||
|
||||
template = Template(template_content)
|
||||
rendered_template = template.render({
|
||||
'plugin_decoder': plugin_decoder,
|
||||
'PAYLOAD_LEN': payload_len,
|
||||
})
|
||||
with open(settings.main_c_path, "w", encoding='utf-8') as file:
|
||||
file.write(rendered_template)
|
||||
observer.add_text_file("main_c_rendered", rendered_template)
|
||||
|
||||
# C Template: iat_reuse
|
||||
elif settings.source_style == FunctionInvokeStyle.iat_reuse:
|
||||
with open(PATH_IAT_REUSE + "template.c", 'r', encoding='utf-8') as file:
|
||||
template_content = file.read()
|
||||
observer.add_text_file("main_c_template", template_content)
|
||||
template = Template(template_content)
|
||||
rendered_template = template.render({
|
||||
'plugin_decoder': plugin_decoder,
|
||||
'PAYLOAD_LEN': payload_len,
|
||||
})
|
||||
with open(settings.main_c_path, "w", encoding='utf-8') as file:
|
||||
file.write(rendered_template)
|
||||
observer.add_text_file("main_c_rendered", rendered_template)
|
||||
|
||||
else:
|
||||
raise Exception("Invalid source style: {}".format(settings.source_style))
|
||||
template = Template(template_content)
|
||||
rendered_template = template.render({
|
||||
'plugin_decoder': plugin_decoder,
|
||||
'PAYLOAD_LEN': payload_len,
|
||||
})
|
||||
with open(settings.main_c_path, "w", encoding='utf-8') as file:
|
||||
file.write(rendered_template)
|
||||
observer.add_text_file("main_c_rendered", rendered_template)
|
||||
|
||||
Reference in New Issue
Block a user