Skip to content

Instantly share code, notes, and snippets.

@iamtakingiteasy
Last active December 11, 2019 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamtakingiteasy/ffbd9ae6dcdf969f75923dda956dd47b to your computer and use it in GitHub Desktop.
Save iamtakingiteasy/ffbd9ae6dcdf969f75923dda956dd47b to your computer and use it in GitHub Desktop.
// baka.c
// $ make baka && ./baka
char main[] __attribute__((section(".text#"))) = {
0x48, 0xc7, 0xc0, 0x01, 0x00, 0x00, 0x00, 0x48, 0xc7, 0xc7, 0x01, 0x00, 0x00, 0x00, 0x48, 0x8d,
0x35, 0x0a, 0x00, 0x00, 0x00, 0x48, 0xc7, 0xc2, 0x0c, 0x00, 0x00, 0x00, 0x0f, 0x05, 0xc3, 0x48,
0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x62, 0x61, 0x6b, 0x61, 0x0a
};
movq $1, %rax
movq $1, %rdi
leaq hellobaka(%rip), %rsi
movq $12, %rdx
syscall
ret
hellobaka: .ascii "Hello, baka\n"
#!/bin/sh
as baka.s -o baka.o
ld -T linker.ld --oformat binary -o baka.bin baka.o
od -t x1 -An baka.bin | sed 's/.\([a-z0-9]\{2\}\)/0x\1, /g;s/^/ /g;s/ $//g;1{s/^/char main[] __attribute__((section(".text#"))) = {\n/;};${s/,$/\n};/g}'
SECTIONS {
.text : {
*(.*)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment