Skip to content

Instantly share code, notes, and snippets.

@akkartik
Created August 29, 2018 06:36
Show Gist options
  • Save akkartik/3e6669576f4a23b2b33e43fabc423829 to your computer and use it in GitHub Desktop.
Save akkartik/3e6669576f4a23b2b33e43fabc423829 to your computer and use it in GitHub Desktop.
attempt to read argc
; attempt to read argc
;
; Build and run on 32-bit Linux:
; $ nasm -f elf x.s
; $ gcc -Wall -s -nostdlib x.o -o x
; $ ./x; echo $?
; 77 # expected: 1
; $ ./x abc; echo $?
; 73 # expected: 2
; $ ./x abc def; echo $?
; 69 # expected: 3
;
; The return values change from binary to binary (ASLR). But the difference is
; always the total size of argv (in bytes, including nulls)
BITS 32
GLOBAL _start
SECTION .text
_start:
mov ebx, [esp+4]
mov eax, 1
int 0x80
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment