feat: Linux compatibility (looking for NASM in PATH) (#1)

* feat: Linux compatibility (looking for NASM in PATH)
* just a tiny bit of cleanup/normalizing to my goofy code formatting
This commit is contained in:
tuxuser
2024-02-21 01:06:53 +01:00
committed by GitHub
parent dc4deac268
commit 93e65366ce

18
main.py
View File

@@ -1,6 +1,7 @@
import os
import sys
import ctypes
import shutil
import struct
import subprocess
@@ -31,7 +32,6 @@ def p16(value):
#------------------------------------------------------------------------------
BASE_PATH = os.path.join(os.path.dirname(__file__))
NASM_PATH = os.path.join(BASE_PATH, "nasm.exe")
ENDGAME_PATH = os.path.join(BASE_PATH, "ENDGAME")
#
@@ -78,15 +78,25 @@ def compile_shellcode(shellcode_filepath, debug=False):
"""
assert shellcode_filepath.endswith(".asm")
# Run nasm.exe and capture the output and errors
command = [NASM_PATH, shellcode_filepath]
# for Windows-based systems just use the local nasm.exe included in the repo
if os.name == "nt":
nasm_executable = os.path.join(BASE_PATH, "nasm.exe")
# for POSIX systems (linux, macOS) look for nasm in the system path
elif os.name == "posix":
if not shutil.which("nasm"):
raise FileNotFoundError("NASM cannot be found in PATH")
nasm_executable = "nasm"
command = [nasm_executable, shellcode_filepath]
if debug:
command.insert(1, "-dDEBUG")
# run nasm and capture the output and errors
print("[*] Assembling shellcode... ", end="")
result = subprocess.run(command, capture_output=True)
# Check the return code of the command
# check the return code to determine if compilation succeeded
if result.returncode == 0:
output = result.stdout.decode()
if output.strip():