source: dev/branches/egtra/ab5.0/abdev/OldWindowsHelperImpl.cpp@ 779

Last change on this file since 779 was 778, checked in by イグトランス (egtra), 14 years ago

XP以前対応途中(Win98でabdevが起動するところまで)

File size: 3.4 KB
RevLine 
[778]1#include "stdafx.h"
2
3static OSVERSIONINFO GetVersionEx2()
4{
5 OSVERSIONINFO vi = {sizeof vi};
6 GetVersionEx(&vi);
7 return vi;
8}
9
10static OSVERSIONINFO const vi = GetVersionEx2();
11
12#define KERNEL32 (GetModuleHandle(TEXT("kernel32")))
13
14#define GET_PROC_ADDRESS(hmod, functionName) reinterpret_cast<decltype(functionName)*>(GetProcAddress((hmod), #functionName))
15
16extern "C"
17{
18 BOOL WINAPI IsDebuggerPresent_Helper()
19 {
20 if (auto IsDebuggerPresent_Real = GET_PROC_ADDRESS(KERNEL32, IsDebuggerPresent))
21 {
22 return IsDebuggerPresent_Real();
23 }
24 else
25 {
26 return FALSE;
27 }
28 }
29
30 void* WINAPI EncodePointer_Helper(void* p)
31 {
32 static bool first = false;
33 if (!first)
34 {
35 ::MessageBox(nullptr, "test", "", 0);
36 first = true;
37 }
38 if (auto EncodePointer_Real = GET_PROC_ADDRESS(KERNEL32, EncodePointer))
39 {
40 return EncodePointer_Real(p);
41 }
42 else
43 {
44 return reinterpret_cast<void*>(reinterpret_cast<DWORD>(p) ^ GetCurrentProcessId());
45 }
46 }
47
48 void* WINAPI DecodePointer_Helper(void* p)
49 {
50 if (auto DecodePointer_Real = GET_PROC_ADDRESS(KERNEL32, DecodePointer))
51 {
52 return DecodePointer_Real(p);
53 }
54 else
55 {
56 return reinterpret_cast<void*>(reinterpret_cast<DWORD>(p) ^ GetCurrentProcessId());
57 }
58 }
59
60 BOOL WINAPI IsProcessorFeaturePresent_Helper(DWORD feture)
61 {
62 if (auto IsProcessorFeaturePresent_Real = GET_PROC_ADDRESS(KERNEL32, IsProcessorFeaturePresent))
63 {
64 return IsProcessorFeaturePresent_Real(feture);
65 }
66 else
67 {
68 assert(feture == PF_NX_ENABLED); // ATLから呼ばれる
69 return FALSE;
70 }
71 }
72
73 BOOL WINAPI HeapSetInformation_Helper(HANDLE hHeap, HEAP_INFORMATION_CLASS hic, void* information, SSIZE_T informationLength)
74 {
75 if (auto HeapSetInformation_Real = GET_PROC_ADDRESS(KERNEL32, HeapSetInformation))
76 {
77 return HeapSetInformation_Real(hHeap, hic, information, informationLength);
78 }
79 else
80 {
81 return TRUE;
82 }
83 }
84
85 BOOL WINAPI InitializeCriticalSectionAndSpinCount_Helper(LPCRITICAL_SECTION lpcs, DWORD spinCount)
86 {
87 __try
88 {
89 if (auto InitializeCriticalSectionAndSpinCount_Real = GET_PROC_ADDRESS(KERNEL32, InitializeCriticalSectionAndSpinCount))
90 {
91 OSVERSIONINFO vi = {sizeof vi};
92 ::GetVersionEx(&vi);
93 BOOL ret = InitializeCriticalSectionAndSpinCount_Real(lpcs, spinCount);
94 return vi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS
95 ? TRUE
96 : ret;
97 }
98 else
99 {
100 ::InitializeCriticalSection(lpcs);
101 return TRUE;
102 }
103 }
104 __except(EXCEPTION_EXECUTE_HANDLER)
105 {
106 }
107 return FALSE;
108 }
109
110 // Interlocked(Push|Pop)EntrySListは、NXが有効な場合のみ呼ばれる。
111 // Windows XP以前はNX対応していないためInterlocked(Push|Pop)EntrySListが呼ばれることはない。
112 // そのため、GET_PROC_ADDRESSがnullptrを返すことはないと仮定している。
113 // なお、Interlocked(Push|Pop)EntrySListもWindows XPから搭載されている。
114
115 PSLIST_ENTRY WINAPI InterlockedPushEntrySList_Helper(PSLIST_HEADER head, PSLIST_ENTRY entry)
116 {
117 auto InterlockedPushEntrySList_Real = GET_PROC_ADDRESS(KERNEL32, InterlockedPushEntrySList);
118 assert(InterlockedPushEntrySList_Real != nullptr);
119 return InterlockedPushEntrySList_Real(head, entry);
120 }
121
122 PSLIST_ENTRY WINAPI InterlockedPopEntrySList_Helper(PSLIST_HEADER head)
123 {
124 auto InterlockedPopEntrySList_Real = GET_PROC_ADDRESS(KERNEL32, InterlockedPopEntrySList);
125 assert(InterlockedPopEntrySList_Real != nullptr);
126 return InterlockedPopEntrySList_Real(head);
127 }
128}
Note: See TracBrowser for help on using the repository browser.