Created
June 9, 2024 21:34
-
-
Save totekuh/d4dd6a4d4c30fc4798caa78a116faaf6 to your computer and use it in GitHub Desktop.
Assembly (ASM) source to invoke a message box on Windows x64
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BITS 64 | |
; Assembly with NASM for 64-bit | |
; nasm -f win64 -o messagebox.o messagebox.asm | |
; Linking for 64-bit with MinGW | |
; x86_64-w64-mingw32-ld -o messagebox.exe messagebox.o -lkernel32 -luser32 | |
extern MessageBoxA | |
extern ExitProcess | |
section .data | |
title db 'whatever', 0 | |
content db 'hack the planet 31337', 0 | |
section .text | |
global main | |
main: | |
; Prepare arguments for MessageBoxA | |
push 0 ; MB_OK | |
mov rax, rsp ; Pointer to MB_OK | |
push rax ; Push pointer to MB_OK for the MessageBoxA call | |
mov r9, rax ; UType = MB_OK (4th argument) | |
pop rax ; Clean the stack (remove MB_OK pointer) | |
lea r8, [rel title] ; lpCaption (3rd argument) | |
lea rdx, [rel content] ; lpText (2nd argument) | |
xor rcx, rcx ; hWnd = NULL (1st argument) | |
; Call MessageBoxA | |
call MessageBoxA | |
; Clean the stack | |
add rsp, 8 ; Clean up after push | |
; ExitProcess call | |
xor ecx, ecx ; uExitCode = 0 | |
call ExitProcess |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment