mirror of
https://github.com/dobin/SuperMega
synced 2026-06-03 01:27:11 +00:00
45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
import logging
|
|
|
|
from model import *
|
|
from config import config
|
|
from observer import observer
|
|
from pe.pehelper import *
|
|
from helper import *
|
|
|
|
logger = logging.getLogger("Assembler")
|
|
|
|
|
|
def asm_to_shellcode(asm_in: FilePath, build_exe: FilePath) -> bytes:
|
|
"""Takes ASM source file asm_in, compiles it into build_exe, extracts its code section and write into shellcode_out"""
|
|
logger.info("-[ Assemble to exe: {} -> {}".format(asm_in, build_exe))
|
|
run_process_checkret([
|
|
config.get("path_ml64"),
|
|
asm_in,
|
|
"/link",
|
|
"/OUT:{}".format(build_exe),
|
|
"/entry:AlignRSP" # "/entry:main",
|
|
])
|
|
if not os.path.isfile(build_exe):
|
|
raise Exception("Compiling failed")
|
|
code = extract_code_from_exe_file(build_exe)
|
|
return code
|
|
|
|
|
|
def encode_payload(payload: bytes, decoder_style: DecoderStyle) -> bytes:
|
|
if decoder_style == DecoderStyle.PLAIN_1:
|
|
return bytes(payload)
|
|
elif decoder_style == DecoderStyle.XOR_1:
|
|
xor_key = config.xor_key
|
|
logger.info("---[ XOR payload with key 0x{:X}".format(xor_key))
|
|
xored = bytes([byte ^ xor_key for byte in payload])
|
|
return bytes(xored)
|
|
elif decoder_style == DecoderStyle.XOR_2:
|
|
xor_key = config.xor_key2
|
|
logger.info("---[ XOR2 payload with key {}".format(xor_key))
|
|
xored = bytearray(payload)
|
|
for i in range(len(xored)):
|
|
xored[i] ^= xor_key[i % 2]
|
|
return bytes(xored)
|
|
else:
|
|
raise Exception("Unknown decoder style")
|