Hardcoding main() as main[]

MosaicFuneral 0 Tallied Votes 140 Views Share

Useless novelty code.

#include <stdio.h>

#if !(defined __i386__ || defined _M_IX86)
  #error Unknown target platform.
#endif

int rerun = 0;

int real_code()
{
    if(rerun) return(0);

    printf("Yo...");

    rerun++;
    return(0);
}

#ifdef _MSC_VER
#pragma warning(disable : 4309)
extern "C"
#endif
char main[] = { 0x55,       /*push %ebp*/
                0x89, 0xE5, /*mov  %ebp, %esp*/
                0xE8, (char)(((&real_code)()>>24)&0xFF),
                      (char)(((&real_code)()>>16)&0xFF),
                      (char)(((&real_code)()>>8)&0xFF),
                      (char)((&real_code)()&0xFF), /*call real_code*/
                0x33, 0xC0, /*xorl %eax, %eax*/
                0xC9,       /*leave*/
                0xC3 };     /*ret*/