I wonder if one could write a header file containing definitions that would make the following possible. char main[] = { movl(1, eax), movl(1, ebx), movl(message, esi), movl(13, edx), syscall(), movl(60, eax), xorl(ebx, ebx), syscall(), }; Obviously there are some technical difficulties like handling literal values and code sections, but it could be a fun hack, and I've love to see what someone could come up with.
Main is usually a function – when is it not?
11–20 of 62 posts
Re: Main is usually a function – when is it not?
#12Next challenge... make it a real string! https://0xcd80.wordpress.com/2011/04/29/linux-x86-shellcodin... https://code.google.com/p/alpha3/
const char main[] =
"UH\x89\xe5\xb8\1\0\0\0\xbb\1\0\0\0g\x8d"
"5\x10\0\0\0\xba\r\0\0\0\xf\5\xb8\x3c\0\0\0"
"1\xdb\xf\5Hello World!\n]\xc3";Re: Main is usually a function – when is it not?
#13Reminds me of this 'Hello World': http://stackoverflow.com/questions/15182496/why-does-this-co... I bet these two ideas would go well together.
The seed for the random number generator is not executed though.
Re: Main is usually a function – when is it not?
#14Re: Main is usually a function – when is it not?
#15I recall from somewhere: int main = 0; This code compiles (cleanly!), but segfaults.
I think that sets the address of main to NULL, so it segfaults as soon as `_start` jumps to `main`. It's known for being one of the smallest compilable C programs. EDIT: Your original post contained int main=0;
Re: Main is usually a function – when is it not?
#16I wonder if one could write a header file containing definitions that would make the following possible. char main[] = { movl(1, eax), movl(1, ebx), movl(message, esi), movl(13, edx), syscall(), movl(60, eax), xorl(ebx, ebx), syscall(), }; Obviously there are some technical difficulties like handling literal values and code sections, but it could be a fun hack, and I've love to see what someone could come up with.
It's possible, but once you're not obfuscating the code - and already depending on OS details when you assume that global data can be executable, whether const or not - I think you may as well just use the inline assembler feature of your compiler. Well, if there is one... MSVC bizarrely doesn't support on x86-64 what was a perfectly good feature on x86.
Re: Main is usually a function – when is it not?
#17Re: Main is usually a function – when is it not?
#18Wouldn't this be considered academic fraud? His coworker turning in code that he didn't write?
Re: Main is usually a function – when is it not?
#19Next challenge... make it a real string! https://0xcd80.wordpress.com/2011/04/29/linux-x86-shellcodin... https://code.google.com/p/alpha3/
const char main[] = "UH\x89\xe5\xb8\1\0\0\0\xbb\1\0\0\0g\x8d" "5\x10\0\0\0\xba\r\0\0\0\xf\5\xb8\x3c\0\0\0" "1\xdb\xf\5Hello World!\n]\xc3";