Last active
December 11, 2019 20:15
-
-
Save iamtakingiteasy/ffbd9ae6dcdf969f75923dda956dd47b to your computer and use it in GitHub Desktop.
This file contains 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
// 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 | |
}; |
This file contains 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
movq $1, %rax | |
movq $1, %rdi | |
leaq hellobaka(%rip), %rsi | |
movq $12, %rdx | |
syscall | |
ret | |
hellobaka: .ascii "Hello, baka\n" |
This file contains 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
#!/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}' |
This file contains 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
SECTIONS { | |
.text : { | |
*(.*) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment