Created
December 7, 2020 12:16
-
-
Save paxbun/3096efcfabe266269fe4e6508b35946c to your computer and use it in GitHub Desktop.
Windows API example
This file contains hidden or 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
; Copyright (c) 2020 Chanjung Kim. All rights reserved. | |
.data | |
text db "Hello, world!", 0 | |
caption db "My title", 0 | |
.code | |
extern GetStdHandle: proc | |
extern ReadConsoleA: proc | |
extern WriteConsoleA: proc | |
extern MessageBoxA: proc | |
mainCRTStartup proc | |
; char buffer[20]; | |
; DWORD read, written; | |
sub rsp, 104 | |
; ReadConsoleA(GetStdHandle(STD_INPUT_HANDLE), &buffer, 20, &read, 0); | |
mov QWORD PTR 32[rsp], 0 | |
lea r9, DWORD PTR 100[rsp] | |
mov r8d, 20 | |
lea rdx, DWORD PTR 76[rsp] | |
mov ecx, -10 | |
call GetStdHandle | |
mov rcx, rax | |
call ReadConsoleA | |
; for (size_t i = 0; i < 5; ++i) | |
for1begin: | |
xor r10, r10 | |
for1cond: | |
cmp r10, 5 | |
jge for1end | |
; { | |
for1body: | |
mov QWORD PTR 64[rsp], r10 | |
; WriteConsoleA(GetStdHandle(STD_OUTPUT_HANDLE), buffer, read, &written, 0); | |
mov QWORD PTR 32[rsp], 0 | |
lea r9, DWORD PTR 96[rsp] | |
mov r8d, DWORD PTR 100[rsp] | |
lea rdx, DWORD PTR 76[rsp] | |
mov ecx, -11 | |
call GetStdHandle | |
mov rcx, rax | |
call WriteConsoleA | |
mov r10, QWORD PTR 64[rsp] | |
inc r10 | |
jmp for1cond | |
; } | |
for1end: | |
; MessageBoxA(NULL, "Hello, world!", "My title", MB_OK); | |
xor r9d, r9d | |
lea r8, caption | |
lea rdx, text | |
xor ecx, ecx | |
call MessageBoxA | |
; return 0; | |
xor rax, rax | |
add rsp, 104 | |
ret | |
mainCRTStartup endp | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment