From 93e65366ce9666a8571fcbffdd23a26b55cc8976 Mon Sep 17 00:00:00 2001 From: tuxuser <462620+tuxuser@users.noreply.github.com> Date: Wed, 21 Feb 2024 01:06:53 +0100 Subject: [PATCH] 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 --- main.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 38e0a5b..bf7f94f 100644 --- a/main.py +++ b/main.py @@ -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():