-
Notifications
You must be signed in to change notification settings - Fork 2
/
nolibc.cpp
85 lines (72 loc) · 1.17 KB
/
nolibc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* nolibc.cpp by LightShow */
#ifndef __NO_LIBC__
#define __NO_LIBC__
#include <windows.h>
#pragma comment(linker, "/OPT:NOWIN98")
void * operator new( unsigned int cb )
{
if (!cb) cb++;
return (void*)GlobalAlloc(GPTR,cb);
}
void operator delete( void * p )
{
if(p!=NULL) GlobalFree(p);
}
extern "C" void WinMainCRTStartup()
{
WinMain(0,0,NULL,0);
ExitProcess(0);
}
extern "C" int rand()
{
static int lastrand=3489715357;
__asm
{
mov eax,[lastrand]
mov edx,eax
rcr edx,11
adc eax,17
xor ax,dx
imul eax,edx
xor eax,edx
mov [lastrand],eax
and eax,0xffff
}
return (int)lastrand;
}
extern "C" int _fltused;
int _fltused;
// visual C++ _ftol
extern "C" void __declspec(naked) _ftol()
{
_asm
{
push edx
push eax
fistp qword ptr [esp]
pop eax
pop edx
ret
}
}
// visual C++ _CIpow
extern "C" void __declspec(naked) _CIpow()
{
_asm
{
fxch st(1)
fyl2x
fld st(0)
frndint
fsubr st(1),st(0)
fxch st(1)
fchs
f2xm1
fld1
faddp st(1),st(0)
fscale
fstp st(1)
ret
}
}
#endif