2006-10-06 08:20:41 +02:00
|
|
|
#include "crt.h"
|
|
|
|
|
|
|
|
#define atexitBufferSize 32
|
|
|
|
|
|
|
|
char pureCallMessage[] = "PURE function call!";
|
|
|
|
|
2006-12-02 09:47:11 +01:00
|
|
|
char *__argv[2];
|
|
|
|
int __argc;
|
2006-10-06 08:20:41 +02:00
|
|
|
|
|
|
|
void (__cdecl *atExitList[atexitBufferSize])();
|
|
|
|
int atExitFnNum = 0;
|
2006-12-02 09:47:11 +01:00
|
|
|
int main(int argc, char *argv[]);
|
2006-10-06 08:20:41 +02:00
|
|
|
|
|
|
|
void exit()
|
|
|
|
{ int i;
|
|
|
|
|
|
|
|
for ( i = atExitFnNum - 1; i >= 0; i-- )
|
|
|
|
atExitList[i]();
|
|
|
|
|
|
|
|
__asm
|
|
|
|
{
|
|
|
|
mov eax, -1
|
|
|
|
int 0x40
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
int __cdecl atexit( void (__cdecl *func )( void ))
|
|
|
|
{
|
|
|
|
//
|
|
|
|
if ( atExitFnNum < atexitBufferSize )
|
|
|
|
{
|
|
|
|
//
|
|
|
|
atExitList[atExitFnNum++] = func;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int __cdecl _purecall()
|
|
|
|
{
|
|
|
|
exit();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma section(".CRT$XCA",long,read,write)
|
|
|
|
#pragma section(".CRT$XCZ",long,read,write)
|
|
|
|
typedef void (__cdecl *_PVFV)(void);
|
|
|
|
__declspec(allocate(".CRT$XCA")) _PVFV __xc_a[1] = { 0 };
|
|
|
|
__declspec(allocate(".CRT$XCZ")) _PVFV __xc_z[1] = { 0 };
|
|
|
|
//
|
|
|
|
#pragma comment(linker, "/merge:.CRT=.rdata")
|
|
|
|
//
|
|
|
|
void crtStartUp()
|
|
|
|
{_PVFV *pbegin;
|
|
|
|
|
|
|
|
_asm {fninit};
|
|
|
|
|
|
|
|
for ( pbegin = __xc_a; pbegin < __xc_z; pbegin++ )
|
|
|
|
{
|
|
|
|
//
|
|
|
|
if ( *pbegin != 0 )
|
|
|
|
(**pbegin)();
|
|
|
|
}
|
2006-12-02 09:47:11 +01:00
|
|
|
__argc = 2;
|
|
|
|
__argv[0] = *((char **)0x20);
|
|
|
|
__argv[1] = *((char **)0x1C);
|
|
|
|
main(__argc, __argv);
|
2006-10-06 08:20:41 +02:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
|