3 ms·
Not so much "obfuscated C" as it is "embedding a binary into a C program". You can still do something similar with modern compilers: char code[] = { /* put
by userbinator 6y ago
Not so much "obfuscated C" as it is "embedding a binary into a C program". You can still do something similar with modern compilers:
char code[] = { /* put your bytes here */ };
((void(*)())code)();
I believe it is technically UB, but it does exactly what you'd think it does, and if compilers started doing funny things with it, you wouldn't be able to write things like JITs at all. A tiny demonstration of this can be found at the bottom of C4x86: https://github.com/EarlGray/c4/blob/master/c4x86.c https://github.com/EarlGray/c4/blob/master/c4x86.c
- monocasa 6y agoI think something like this gets disallowed these days as .rodata and .data gets mapped NX.
- ache7 6y agoUsing compiler hints, data can be placed directly in the code section. Works on x86/x86_64 Linux: char main[] __attribute__ ((section(".text"))) = "\xe8\x0d\0\0\0Hello world!\n" #ifdef __x86_64__ "\x31\xc0\x8d\x50\x0d\xff\xc0\x89\xc7\x5e\x0f\x05\x31\xff\x8d\x47\x3c\x0f\x05"; #else "\x31\xdb\x8d\x53\x0d\x59\x8d\x43\x04\x43\xcd\x80\x31\xdb\x8d\x43\x01\xcd\x80"; #endif
- hinoki 6y agoI wonder if there have been any entries that use return oriented programming? I wasn’t able to find one...
- andreareina 6y agoMight have to make code const: http://jroweboy.github.io/c/asm/2015/01/26/when-is-main-not-a-function.html http://jroweboy.github.io/c/asm/2015/01/26/when-is-main-not-...
- lifthrasiir 6y ago> Not so much "obfuscated C" as it is "embedding a binary into a C program". The meaning of "obfuscated C" as the contest requires was not well-defined at that time and had to be amended for a very long time. There are at least 5 more entries that abused and subsequently changed the rules at that time [1] [2] [3] [4] [5]. ([6] is an exception; this kind of abuse of the rules is allowed and now common.) > [...] if compilers started doing funny things with it, you wouldn't be able to write things like JITs at all. Well, see [7]. [1] https://www.ioccc.org/1987/biggar/hint.html https://www.ioccc.org/1987/biggar/hint.html [2] https://www.ioccc.org/1988/spinellis.hint https://www.ioccc.org/1988/spinellis.hint [3] https://www.ioccc.org/1989/jar.1.hint https://www.ioccc.org/1989/jar.1.hint [4] https://www.ioccc.org/1993/lmfjyh.hint https://www.ioccc.org/1993/lmfjyh.hint [5] https://www.ioccc.org/1994/smr.hint https://www.ioccc.org/1994/smr.hint [6] https://www.ioccc.org/1995/spinellis.hint https://www.ioccc.org/1995/spinellis.hint [7] https://www.ioccc.org/2011/richards/hint.html https://www.ioccc.org/2011/richards/hint.html
- StavrosK 6y agoThe IOCCC can use a UX improvement where they have, for each entry, pages with an introduction, the hints page, how the thing works, the actual code and what happens when you run it (including output). As it stands, it's very interesting to read but most examples are hard to run and I always end up going away unfulfilled.
- LainIwakura 6y agoThis is why I do these write ups, I want to document the most obtuse pieces of code I can and explain the logic in a clear way =) I'll be writing more so be on the look out!
- StavrosK 6y agoYour writeup was extremely interesting and helpful, thank you!
- szc 6y agoI have been working to improve the usability for this years winning entries. For some entries it doesn't work well to "inline" the C code.
- 0xTJ 6y agoCalling that "technically UB" is putting it lightly.
- im3w1l 6y agoWhat would be blessed way of doing it? Inline assembly jumping to it?
- segfaultbuserr 6y agoIn other words, this type of behavior can be summarized as: Instead of waiting for other people to exploit your program in C, why not to execute some shellcode and pwn yourself while you're at it... /joke