Skip to content

Instantly share code, notes, and snippets.

@mid-kid
Last active November 5, 2024 23:14
Show Gist options
  • Save mid-kid/52114a0360e8c90cd626bbeebe93a102 to your computer and use it in GitHub Desktop.
Save mid-kid/52114a0360e8c90cd626bbeebe93a102 to your computer and use it in GitHub Desktop.
#!/usr/bin/env -S sh -c 'f="$1";shift;sed 1d "$f" | cc -no-pie -o "$f.elf" -xassembler - && ./"$f.elf" "$@"' -
.intel_syntax noprefix
__USER32_CS = 35
__USER_DS = 43
__USER_CS = 51
.global main
main:
push rbp
mov rbp, rsp
mov ax, __USER_DS
mov ds, ax
lea rdi, [rip + s_main]
lea rsi, [rip + main]
call printf
mov eax, 15 # ah = 00, al = 0fh
mov [rip + save_rsp], rsp
ljmp [rip + 1f]
1:
.long offset 1f
.word __USER32_CS
1:
.code32
aaa # ah = 01, al = 05 (ax = 105h, 261)
ljmp [1f]
1:
.long offset 2f
.word __USER_CS
.code64
2:
mov rsp, [rip + save_rsp]
lea rdi, [rip + s_aaa]
mov esi, eax
call printf
xor eax, eax
pop rbp
ret
s_main:
.asciz "main: 0x%016lx\n"
s_aaa:
.asciz "aaa: %d\n"
.bss
save_rsp: .zero 8
.section .note.GNU-stack,"",@progbits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment