Skip to content

Instantly share code, notes, and snippets.

@DogParty
DogParty / Quine ASM
Last active August 29, 2015 14:15
A self-replicating 64bit assembly program for OS X. Save as g and run with "as g -o g.o; ld g.o -e _m; ./a.out"
.section __DATA,__data # OSX specific form of ".section data"
SOURCE: # .incbin copies files into applications byte-for-byte
.incbin "g" # so this is loading the source's bytes into a var called SOURCE
SIZE = . - SOURCE # . here points to the byte after SOURCE in memory
# so . - SOURCE returns the length of SOURCE in mem
.section __TEXT,__text
.globl _main # entry point. also OSX needs _ before the function
_main:
movl $0x2000004, %eax # x64 needs to pad syscalls w 0x2000000 so 4 is sys_write
movl $1, %edi # with sys_write in eax, moving 1 into edi says write to console