Skip to content

Instantly share code, notes, and snippets.

@sum-catnip
Created May 30, 2022 11:44
Show Gist options
  • Save sum-catnip/8d76d922c2eec503d2b19aaea951a46d to your computer and use it in GitHub Desktop.
Save sum-catnip/8d76d922c2eec503d2b19aaea951a46d to your computer and use it in GitHub Desktop.
powershell script that compiles a nasm .asm file (needs BITS32/64 at the start) into a c style array. only dependency is nasm.
<#
compiles an asm file into a c-style byte array
#>
param (
# path to asm file
[parameter(mandatory=$true)]
[string]$path
)
$nasm = "$env:LOCALAPPDATA\bin\NASM\nasm.exe"
if (-not (test-path $nasm)) {
write-error "nasm.exe not found in appdata. install nasm for local user to continue."
exit 1
}
$tempfile = "$env:TEMP\shellcode.bin"
& $nasm $path -f bin -o $tempfile
'{ ' + ((format-hex $tempfile | select -expand bytes | % { '0x{0:x2}' -f $_ }) -join ', ') + ' }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment