我在C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\crt\src\gs_support.c中找到了这个函数
0xBB40E64E=3141592654=PI
- 当平台不是 win64 时,为什么 DEFAULT_SECURITY_COOKIE
设置为此值?
为什么systemtime
、ProcessId
、ThreadId
、TickCount
之间有很多异或运算,等等
数字 0x00002B992DDFA232 是什么意思?
#ifdef _WIN64
#define DEFAULT_SECURITY_COOKIE 0x00002B992DDFA232
#else
#define DEFAULT_SECURITY_COOKIE 0xBB40E64E
#endif
extern UINT_PTR __security_cookie;
extern UINT_PTR __security_cookie_complement;
typedef union {
unsigned __int64 ft_scalar;
FILETIME ft_struct;
} FT;
void __cdecl __security_init_cookie(void)
{
UINT_PTR cookie;
FT systime={0};
LARGE_INTEGER perfctr;
if (__security_cookie != DEFAULT_SECURITY_COOKIE
#if defined (_X86_)
&& (__security_cookie & 0xFFFF0000) != 0
#endif
)
{
__security_cookie_complement = ~__security_cookie;
return;
}
GetSystemTimeAsFileTime(&systime.ft_struct);
#if defined (_WIN64)
cookie = systime.ft_scalar;
#else
cookie = systime.ft_struct.dwLowDateTime;
cookie ^= systime.ft_struct.dwHighDateTime;
#endif
cookie ^= GetCurrentProcessId();
cookie ^= GetCurrentThreadId();
cookie ^= GetTickCount();
QueryPerformanceCounter(&perfctr);
#if defined (_WIN64)
cookie ^= perfctr.QuadPart;
#else
cookie ^= perfctr.LowPart;
cookie ^= perfctr.HighPart;
#endif
#if defined (_WIN64)
cookie &= 0x0000FFFFffffFFFFi64;
#endif
if (cookie == DEFAULT_SECURITY_COOKIE)
{
cookie = DEFAULT_SECURITY_COOKIE + 1;
}
#if defined (_X86_)
else if ((cookie & 0xFFFF0000) == 0)
{
cookie |= ( (cookie|0x4711) << 16);
}
#endif
__security_cookie = cookie;
__security_cookie_complement = ~cookie;
}
我是一名优秀的程序员,十分优秀!