Showing
15 changed files
with
565 additions
and
0 deletions
vnr/CMakeLists.txt
0 → 100644
1 | +cmake_minimum_required(VERSION 2.8) | ||
2 | + | ||
3 | +set(CMAKE_CONFIGURATION_TYPES Debug Release) | ||
4 | + | ||
5 | +project(vnr) | ||
6 | + | ||
7 | +set(WDK_HOME "C:\\WinDDK\\7600.16385.1" CACHE FILEPATH "path to the Windows DDK directory") | ||
8 | + | ||
9 | +add_definitions( | ||
10 | + -DUNICODE | ||
11 | + -D_UNICODE | ||
12 | +) | ||
13 | + | ||
14 | +include_directories(${PROJECT_SOURCE_DIR}) | ||
15 | + | ||
16 | +set(common_src | ||
17 | + ${PROJECT_SOURCE_DIR}/ith/common/const.h | ||
18 | + ${PROJECT_SOURCE_DIR}/ith/common/defs.h | ||
19 | + ${PROJECT_SOURCE_DIR}/ith/common/except.h | ||
20 | + ${PROJECT_SOURCE_DIR}/ith/common/growl.h | ||
21 | + ${PROJECT_SOURCE_DIR}/ith/common/memory.h | ||
22 | + ${PROJECT_SOURCE_DIR}/ith/common/types.h | ||
23 | +) | ||
24 | + | ||
25 | +set(import_src | ||
26 | + ${PROJECT_SOURCE_DIR}/ith/import/mono/funcinfo.h | ||
27 | + ${PROJECT_SOURCE_DIR}/ith/import/mono/types.h | ||
28 | + ${PROJECT_SOURCE_DIR}/ith/import/ppsspp/funcinfo.h | ||
29 | +) | ||
30 | + | ||
31 | +add_subdirectory(ith/hook) | ||
32 | +add_subdirectory(ith/host) | ||
33 | +add_subdirectory(ith/sys) |
vnr/ccutil/ccmacro.h
0 → 100644
1 | +#ifndef CCMACRO_H | ||
2 | +#define CCMACRO_H | ||
3 | + | ||
4 | +// ccmacro.h | ||
5 | +// 12/9/2011 jichi | ||
6 | + | ||
7 | +#define CC_UNUSED(_var) (void)(_var) | ||
8 | +#define CC_NOP CC_UNUSED(0) | ||
9 | + | ||
10 | +#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96) | ||
11 | +# define CC_LIKELY(expr) __builtin_expect(!!(expr), true) | ||
12 | +# define CC_UNLIKELY(expr) __builtin_expect(!!(expr), false) | ||
13 | +#else | ||
14 | +# define CC_LIKELY(x) (x) | ||
15 | +# define CC_UNLIKELY(x) (x) | ||
16 | +#endif | ||
17 | + | ||
18 | +#define CC_MIN(x, y) ((x) < (y) ? (x) : (y)) | ||
19 | +#define CC_MAX(x, y) ((x) < (y) ? (y) : (x)) | ||
20 | + | ||
21 | +#endif // CCMACRO_H |
vnr/ccutil/ccutil.pri
0 → 100644
vnr/config.pri
0 → 100644
This diff is collapsed. Click to expand it.
vnr/copy_vnr.cmd
0 → 100644
1 | +@echo off | ||
2 | +setlocal | ||
3 | +if [%1] == [] ( | ||
4 | + echo usage: copy_vnr <path-to-Sakura-directory> | ||
5 | + goto :EOF | ||
6 | +) | ||
7 | +xcopy %1\config.pri . /S /Y /I | ||
8 | +xcopy %1\cpp\libs\ccutil ccutil /S /Y /I | ||
9 | +xcopy %1\cpp\libs\cpputil cpputil /S /Y /I | ||
10 | +xcopy %1\cpp\libs\disasm disasm /S /Y /I /EXCLUDE:exclude.txt | ||
11 | +xcopy %1\cpp\plugins\ith ith /S /Y /I | ||
12 | +xcopy %1\cpp\libs\memdbg memdbg /S /Y /I | ||
13 | +xcopy %1\cpp\libs\ntdll ntdll /S /Y /I | ||
14 | +xcopy %1\cpp\libs\ntinspect ntinspect /S /Y /I | ||
15 | +xcopy %1\cpp\libs\winmaker winmaker /S /Y /I | ||
16 | +xcopy %1\cpp\libs\winmutex winmutex /S /Y /I | ||
17 | +xcopy %1\cpp\libs\winversion winversion /S /Y /I | ||
18 | +xcopy %1\cpp\libs\winseh winseh /S /Y /I | ||
19 | + | ||
20 | +endlocal |
vnr/winmutex/winmutex
0 → 100644
vnr/winmutex/winmutex.h
0 → 100644
1 | +#pragma once | ||
2 | +// winmutex.h | ||
3 | +// 12/11/2011 jichi | ||
4 | + | ||
5 | +#include <windows.h> | ||
6 | + | ||
7 | +#ifdef _MSC_VER | ||
8 | +# pragma warning(disable:4800) // C4800: forcing value to bool | ||
9 | +#endif // _MSC_VER | ||
10 | + | ||
11 | +// Mutex lock | ||
12 | +// The interface of this class is consistent with the mutex class | ||
13 | + | ||
14 | +template <typename _Mutex> | ||
15 | + class win_mutex_lock | ||
16 | + { | ||
17 | + typedef win_mutex_lock<_Mutex> _Self; | ||
18 | + win_mutex_lock(const _Self&); | ||
19 | + _Self &operator=(const _Self&); | ||
20 | + | ||
21 | + _Mutex &_M_mutex; | ||
22 | + bool _M_locked; | ||
23 | + public: | ||
24 | + typedef _Mutex mutex_type; | ||
25 | + typedef typename _Mutex::native_handle_type native_handle_type; | ||
26 | + explicit win_mutex_lock(mutex_type &mutex) | ||
27 | + : _M_mutex(mutex), _M_locked(false) { lock(); } | ||
28 | + ~win_mutex_lock() { if (_M_locked) _M_mutex.unlock(); } | ||
29 | + mutex_type &mutex() { return _M_mutex; } | ||
30 | + //bool isLock() const { return _M_locked; } | ||
31 | + native_handle_type native_handle() { return _M_mutex.native_handle(); } | ||
32 | + void unlock() { _M_mutex.unlock(); _M_locked = false; } | ||
33 | + void lock() { _M_mutex.lock(); _M_locked = true; } | ||
34 | + bool tryLock() { return _M_locked = _M_mutex.tryLock(); } | ||
35 | + }; | ||
36 | + | ||
37 | +// Mutex | ||
38 | + | ||
39 | +template <typename _Mutex, size_t _Irql = 0> | ||
40 | + class win_mutex | ||
41 | + { | ||
42 | + typedef win_mutex<_Mutex> _Self; | ||
43 | + typedef _Mutex __native_type; | ||
44 | + enum { __minimal_irql = _Irql }; | ||
45 | + __native_type _M_mutex; | ||
46 | + | ||
47 | + win_mutex(const _Self&); | ||
48 | + _Self &operator=(const _Self&); | ||
49 | + private: | ||
50 | + win_mutex() {} | ||
51 | + typedef __native_type *native_handle_type; | ||
52 | + native_handle_type native_handle() { return &_M_mutex; } | ||
53 | + static size_t minimal_irql() { return __minimal_irql; } | ||
54 | + | ||
55 | + void unlock() {} | ||
56 | + void lock() {} | ||
57 | + bool try_lock() {} | ||
58 | + }; | ||
59 | + | ||
60 | +template <> | ||
61 | + class IHFSERVICE win_mutex<CRITICAL_SECTION> | ||
62 | + { | ||
63 | + typedef win_mutex<CRITICAL_SECTION> _Self; | ||
64 | + typedef CRITICAL_SECTION __native_type; | ||
65 | + enum { __minimal_irql = 0 }; | ||
66 | + win_mutex(const _Self&); | ||
67 | + _Self &operator=(const _Self&); | ||
68 | + | ||
69 | + __native_type _M_mutex; | ||
70 | + public: | ||
71 | + typedef __native_type *native_handle_type; | ||
72 | + native_handle_type native_handle() { return &_M_mutex; } | ||
73 | + static size_t minimal_irql() { return __minimal_irql; } | ||
74 | + | ||
75 | + win_mutex() { ::InitializeCriticalSection(&_M_mutex); } | ||
76 | + ~win_mutex() { ::DeleteCriticalSection(&_M_mutex); } | ||
77 | + void lock() { ::EnterCriticalSection(&_M_mutex); } | ||
78 | + void unlock() { ::LeaveCriticalSection(&_M_mutex); } | ||
79 | + bool try_lock() { return ::TryEnterCriticalSection(&_M_mutex); } | ||
80 | + }; | ||
81 | + | ||
82 | +// Conditional variable | ||
83 | + | ||
84 | +template <typename _Cond> | ||
85 | + class win_mutex_cond | ||
86 | + { | ||
87 | + typedef win_mutex_cond<_Cond> _Self; | ||
88 | + typedef _Cond __native_type; | ||
89 | + win_mutex_cond(const _Self&); | ||
90 | + _Self &operator=(const _Self&); | ||
91 | + | ||
92 | + __native_type _M_cond; | ||
93 | + public: | ||
94 | + enum wait_status { no_timeout = 0, timeout }; | ||
95 | + typedef __native_type *native_handle_type; | ||
96 | + | ||
97 | + win_mutex_cond() {} | ||
98 | + native_handle_type native_handle() { return &_M_cond; } | ||
99 | + | ||
100 | + void notify_one() {} | ||
101 | + void notify_all() {} | ||
102 | + | ||
103 | + template <typename _Mutex> | ||
104 | + void wait(_Mutex &mutex) {} | ||
105 | + | ||
106 | + template <typename _Mutex, typename _Pred> | ||
107 | + void wait(_Mutex &mutex, _Pred pred) {} | ||
108 | + | ||
109 | + template <typename _Mutex> | ||
110 | + wait_status wait_for(_Mutex &mutex, int msecs) {} | ||
111 | + | ||
112 | + template <typename _Mutex, typename _Pred> | ||
113 | + wait_status wait_for(_Mutex &mutex, int msecs, _Pred pred) {} | ||
114 | + }; | ||
115 | + | ||
116 | +// Note: Conditional variables are NOT availabe on Windows XP/2003 | ||
117 | +// See: http://en.cppreference.com/w/cpp/thread/condition_variable | ||
118 | +// See: http://msdn.microsoft.com/en-us/library/windows/desktop/ms686903%28v=vs.85%29.aspx | ||
119 | +template <> | ||
120 | + class win_mutex_cond<CONDITION_VARIABLE> | ||
121 | + { | ||
122 | + typedef win_mutex_cond<CONDITION_VARIABLE> _Self; | ||
123 | + typedef CONDITION_VARIABLE __native_type; | ||
124 | + win_mutex_cond(const _Self&); | ||
125 | + _Self &operator=(const _Self&); | ||
126 | + | ||
127 | + __native_type _M_cond; | ||
128 | + public: | ||
129 | + enum wait_status { no_timeout = 0, timeout }; | ||
130 | + typedef __native_type *native_handle_type; | ||
131 | + native_handle_type native_handle() { return &_M_cond; } | ||
132 | + | ||
133 | + win_mutex_cond() { ::InitializeConditionVariable(&_M_cond); } | ||
134 | + | ||
135 | + void notify_one() { ::WakeConditionVariable(&_M_cond); } | ||
136 | + void notify_all() { ::WakeAllConditionVariable(&_M_cond); } | ||
137 | + | ||
138 | + template <typename _Mutex> | ||
139 | + void wait(_Mutex &mutex) | ||
140 | + { ::SleepConditionVariableCS(&_M_cond, mutex.native_handle(), INFINITE); } | ||
141 | + | ||
142 | + template <typename _Mutex, typename _Pred> | ||
143 | + void wait(_Mutex &mutex, _Pred pred) | ||
144 | + { while (!pred()) wait(mutex); } | ||
145 | + | ||
146 | + template <typename _Mutex> | ||
147 | + wait_status wait_for(_Mutex &mutex, int msecs) | ||
148 | + { return ::SleepConditionVariableCS(&_M_cond, mutex.native_handle(), msecs) ? no_timeout : timeout; } | ||
149 | + | ||
150 | + template <typename _Mutex, typename _Pred> | ||
151 | + wait_status wait_for(_Mutex &mutex, int msecs, _Pred pred) | ||
152 | + { | ||
153 | + auto start = ::GetTickCount(); | ||
154 | + while (!pred()) { | ||
155 | + auto now = ::GetTickCount(); | ||
156 | + msecs -= now - start; | ||
157 | + if (msecs <= 0) | ||
158 | + return timeout; | ||
159 | + start = now; | ||
160 | + wait_for(mutex, msecs); | ||
161 | + } | ||
162 | + return no_timeout; | ||
163 | + } | ||
164 | + }; | ||
165 | + | ||
166 | +// EOF |
vnr/winmutex/winmutex.pri
0 → 100644
vnr/winseh/Makefile
0 → 100644
1 | +# Makefile | ||
2 | +# 12/13/2013 jichi | ||
3 | +# This file is for Windows only. | ||
4 | +# Compile SAFESEH table from the ASM file. | ||
5 | +# See: http://stackoverflow.com/questions/19722308/exception-handler-not-called-in-c | ||
6 | +# See: ::http://stackoverflow.com/questions/12019689/custom-seh-handler-with-safeseh | ||
7 | +# See: http://msdn.microsoft.com/en-us/library/16aexws6.aspx | ||
8 | + | ||
9 | +BUILDDIR = ../../../build | ||
10 | +OBJ = $(BUILDDIR)/safeseh.obj | ||
11 | + | ||
12 | +ML = ml | ||
13 | +CFLAGS = | ||
14 | + | ||
15 | +.PHONY: all compile clean | ||
16 | + | ||
17 | +all: compile | ||
18 | + | ||
19 | +compile: $(OBJ) | ||
20 | + | ||
21 | +$(OBJ): safeseh.asm | ||
22 | + $(ML) $(CFLAGS) -Fo $@ -c -safeseh $^ | ||
23 | + | ||
24 | +clean: | ||
25 | + | ||
26 | +# EOF |
vnr/winseh/safeseh.asm
0 → 100644
1 | +; safeseh.asm | ||
2 | +; 12/13/2013 jichi | ||
3 | +; see: http://stackoverflow.com/questions/12019689/custom-seh-handler-with-safeseh | ||
4 | +; see: http://code.metager.de/source/xref/WebKit/Source/WebCore/platform/win/makesafeseh.asm | ||
5 | +; see: http://jpassing.com/2008/05/20/fun-with-low-level-seh/ | ||
6 | +.386 | ||
7 | +.model flat, stdcall | ||
8 | +option casemap :none | ||
9 | + | ||
10 | +; The symbol name can be found out using: dumpbin /symbols winseh.obj | ||
11 | +extern _seh_handler:near ; defined in winseh.cc | ||
12 | + | ||
13 | +_seh_asm_handler proto | ||
14 | +.safeseh _seh_asm_handler | ||
15 | + | ||
16 | +.code | ||
17 | +_seh_asm_handler proc | ||
18 | +jmp _seh_handler | ||
19 | +_seh_asm_handler endp | ||
20 | + | ||
21 | +end |
vnr/winseh/winseh.cc
0 → 100644
1 | +// winseh.cc | ||
2 | +// 12/13/2013 jichi | ||
3 | + | ||
4 | +#include "winseh/winseh.h" | ||
5 | +#include "ntdll/ntdll.h" | ||
6 | +//#include <cstdio> | ||
7 | + | ||
8 | +// - Global variables - | ||
9 | + | ||
10 | +seh_dword_t seh_esp[seh_capacity], | ||
11 | + seh_eip[seh_capacity], | ||
12 | + seh_eh[seh_capacity]; | ||
13 | +seh_dword_t seh_count; | ||
14 | + | ||
15 | +// - Exception handlers - | ||
16 | + | ||
17 | +// VC 2013: http://msdn.microsoft.com/en-us/library/b6sf5kbd.aspx | ||
18 | +// typedef EXCEPTION_DISPOSITION (*PEXCEPTION_ROUTINE) ( | ||
19 | +// _In_ PEXCEPTION_RECORD ExceptionRecord, | ||
20 | +// _In_ ULONG64 EstablisherFrame, | ||
21 | +// _Inout_ PCONTEXT ContextRecord, | ||
22 | +// _Inout_ PDISPATCHER_CONTEXT DispatcherContext | ||
23 | +// ); | ||
24 | +// | ||
25 | +// winnt.h: http://www.codemachine.com/downloads/win81/ntdef.h | ||
26 | +// typedef | ||
27 | +// __drv_sameIRQL | ||
28 | +// __drv_functionClass(EXCEPTION_ROUTINE) | ||
29 | +// EXCEPTION_DISPOSITION | ||
30 | +// NTAPI | ||
31 | +// EXCEPTION_ROUTINE ( | ||
32 | +// _Inout_ struct _EXCEPTION_RECORD *ExceptionRecord, | ||
33 | +// _In_ PVOID EstablisherFrame, | ||
34 | +// _In_ struct _CONTEXT *ContextRecord, | ||
35 | +// _In_ PVOID DispatcherContext | ||
36 | +// ); | ||
37 | +extern "C" EXCEPTION_DISPOSITION _seh_handler( // extern C is needed to avoid name hashing in C++ | ||
38 | + _In_ PEXCEPTION_RECORD ExceptionRecord, | ||
39 | + _In_ PVOID EstablisherFrame, // does not work if I use ULONG64 | ||
40 | + _Inout_ PCONTEXT ContextRecord, | ||
41 | + _In_ PVOID DispatcherContext) // PDISPATCHER_CONTEXT is not declared in windows.h | ||
42 | +{ | ||
43 | + //assert(::seh_count > 0); | ||
44 | + ContextRecord->Esp = ::seh_esp[::seh_count - 1]; | ||
45 | + ContextRecord->Eip = ::seh_eip[::seh_count - 1]; | ||
46 | + //printf("seh_handler:%i,%x,%x\n", ::seh_count, ContextRecord->Esp, ContextRecord->Eip); | ||
47 | + return ::seh_eh[::seh_count - 1] ? | ||
48 | + reinterpret_cast<PEXCEPTION_ROUTINE>(::seh_eh[::seh_count - 1])(ExceptionRecord, EstablisherFrame, ContextRecord, DispatcherContext) : | ||
49 | + ExceptionContinueExecution; | ||
50 | +} | ||
51 | + | ||
52 | +// EOF |
vnr/winseh/winseh.h
0 → 100644
1 | +#pragma once | ||
2 | + | ||
3 | +// winseh.h | ||
4 | +// 12/13/2013 jichi | ||
5 | +// See: http://code.metager.de/source/xref/WebKit/Source/WebCore/platform/win/makesafeseh.asm | ||
6 | +// See: http://jpassing.com/2008/05/20/fun-with-low-level-seh/ | ||
7 | + | ||
8 | +#ifdef _MSC_VER | ||
9 | +# pragma warning (disable:4733) // C4733: Inline asm assigning to 'FS:0' : handler not registered as safe handler | ||
10 | +#endif // _MSC_VER | ||
11 | + | ||
12 | +#define SEH_RAISE (*(int*)0 = 0) // raise C000005, for debugging only | ||
13 | + | ||
14 | +// Maximum number of nested SEH | ||
15 | +// Default nested function count is 100, see: http://stackoverflow.com/questions/8656089/solution-for-fatal-error-maximum-function-nesting-level-of-100-reached-abor | ||
16 | +#ifndef SEH_CAPACITY | ||
17 | +# define SEH_CAPACITY 100 | ||
18 | +#endif // SEH_CAPACITY | ||
19 | + | ||
20 | +enum { seh_capacity = SEH_CAPACITY }; | ||
21 | + | ||
22 | +typedef unsigned long seh_dword_t; // DWORD in <windows.h> | ||
23 | + | ||
24 | +// 12/13/2013 jichi | ||
25 | +// The list implementation is not thread-safe | ||
26 | +extern seh_dword_t seh_esp[seh_capacity], // LPVOID, current stack | ||
27 | + seh_eip[seh_capacity], // LPVOID, current IP address | ||
28 | + seh_eh[seh_capacity]; // EXCEPTION_ROUTINE, current exception handler function address | ||
29 | +extern seh_dword_t seh_count; // current number of exception handlers | ||
30 | +extern seh_dword_t seh_handler; //extern PEXCEPTION_ROUTINE seh_handler; | ||
31 | + | ||
32 | +/** | ||
33 | + * Push SEH handler | ||
34 | + * @param _label exception recover label which should be the same as seh_pop_ | ||
35 | + * @param _eh EXCEPTION_ROUTINE or 0 | ||
36 | + * @param _r1 scalar register name, such as eax | ||
37 | + * @param _r2 counter register name, such as ecx | ||
38 | + * | ||
39 | + * Note: __asm prefix is needed to allow inlining macro | ||
40 | + * I didn't pushad and popad which seems to be not needed | ||
41 | + * | ||
42 | + * For SEH, see: | ||
43 | + * http://www.codeproject.com/Articles/82701/Win32-Exceptions-OS-Level-Point-of-View | ||
44 | + * http://sploitfun.blogspot.com/2012/08/seh-exploit-part1.html | ||
45 | + * http://sploitfun.blogspot.com/2012/08/seh-exploit-part2.html | ||
46 | + * | ||
47 | + * fs:0x0 on Windows is the pointer to ExceptionList | ||
48 | + * http://stackoverflow.com/questions/4657661/what-lies-at-fs0x0-on-windows | ||
49 | + * | ||
50 | + * EPB and ESP | ||
51 | + * http://stackoverflow.com/questions/1395591/what-is-exactly-the-base-pointer-and-stack-pointer-to-what-do-they-point | ||
52 | + */ | ||
53 | +#define seh_push_(_label, _eh, _r1, _r2) \ | ||
54 | + { \ | ||
55 | + __asm mov _r1, _eh /* move new handler address */ \ | ||
56 | + __asm mov _r2, seh_count /* get current seh counter */ \ | ||
57 | + __asm mov dword ptr seh_eh[_r2*4], _r1 /* set recover exception hander */ \ | ||
58 | + __asm mov _r1, _label /* move jump label address */ \ | ||
59 | + __asm mov dword ptr seh_eip[_r2*4], _r1 /* set recover eip as the jump label */ \ | ||
60 | + __asm push seh_handler /* push new safe seh handler */ \ | ||
61 | + __asm push fs:[0] /* push old fs:0 */ \ | ||
62 | + __asm mov dword ptr seh_esp[_r2*4], esp /* safe current stack address */ \ | ||
63 | + __asm mov fs:[0], esp /* change fs:0 to the current stack */ \ | ||
64 | + __asm inc seh_count /* increase number of seh */ \ | ||
65 | + } | ||
66 | + //TODO: get sizeof dword instead of hardcode 4 | ||
67 | + | ||
68 | +/** | ||
69 | + * Restore old SEH handler | ||
70 | + * @param _label exception recover label which should be the same as seh_push_ | ||
71 | + */ | ||
72 | +#define seh_pop_(_label) \ | ||
73 | + { \ | ||
74 | + __asm _label: /* the exception recover label */ \ | ||
75 | + __asm pop dword ptr fs:[0] /* restore old fs:0 */ \ | ||
76 | + __asm add esp, 4 /* pop seh_handler */ \ | ||
77 | + __asm dec seh_count /* decrease number of seh */ \ | ||
78 | + } | ||
79 | + | ||
80 | +#define seh_pop() seh_pop_(seh_exit) | ||
81 | +#define seh_push() seh_push_(seh_exit, 0, eax, ecx) // use ecx as counter better than ebx | ||
82 | + | ||
83 | +/** | ||
84 | + * @param _eh EXCEPTION_ROUTINE or 0 | ||
85 | + */ | ||
86 | +#define seh_push_eh(_eh) seh_push_(seh_exit, _eh, eax, ecx) | ||
87 | + | ||
88 | +/** | ||
89 | + * Wrap the code block with SEH handler | ||
90 | + * @param* any code block. The colon for the last expression is optional. | ||
91 | + */ | ||
92 | +#define seh_with(...) \ | ||
93 | + { \ | ||
94 | + seh_push() \ | ||
95 | + __VA_ARGS__ \ | ||
96 | + ; \ | ||
97 | + seh_pop() \ | ||
98 | + } | ||
99 | + | ||
100 | +/** | ||
101 | + * Wrap the code block with SEH handler | ||
102 | + * @param _eh EXCEPTION_ROUTINE or 0 | ||
103 | + * @param* any code block. The colon for the last expression is optional. | ||
104 | + */ | ||
105 | +#define seh_with_eh(_eh, ...) \ | ||
106 | + { \ | ||
107 | + seh_push_eh(_eh) \ | ||
108 | + __VA_ARGS__ \ | ||
109 | + ; \ | ||
110 | + seh_pop() \ | ||
111 | + } | ||
112 | + | ||
113 | +// EOF | ||
114 | + | ||
115 | +//#define seh_push_front() \ | ||
116 | +// { \ | ||
117 | +// __asm mov eax, seh_exit \ | ||
118 | +// __asm mov seh_eip, eax \ | ||
119 | +// __asm push seh_handler \ | ||
120 | +// __asm push fs:[0] \ | ||
121 | +// __asm mov seh_esp, esp \ | ||
122 | +// __asm mov fs:[0], esp \ | ||
123 | +// } | ||
124 | +// | ||
125 | +//#define seh_pop_front() \ | ||
126 | +// { \ | ||
127 | +// __asm seh_exit: \ | ||
128 | +// __asm mov eax, [esp] \ | ||
129 | +// __asm mov fs:[0], eax \ | ||
130 | +// __asm add esp, 8 \ | ||
131 | +// } | ||
132 | +// | ||
133 | +//#define seh_push_back() \ | ||
134 | +// { \ | ||
135 | +// __asm mov eax, seh_exit \ | ||
136 | +// __asm mov ecx, seh_capacity - 1 \ | ||
137 | +// __asm mov DWORD PTR seh_eip[ecx*4], eax \ | ||
138 | +// __asm push seh_handler \ | ||
139 | +// __asm push fs:[0] \ | ||
140 | +// __asm mov DWORD PTR seh_esp[ecx*4], esp \ | ||
141 | +// __asm mov fs:[0], esp \ | ||
142 | +// } | ||
143 | +// | ||
144 | +//#define seh_pop_back() \ | ||
145 | +// { \ | ||
146 | +// __asm seh_exit: \ | ||
147 | +// __asm mov eax, [esp] \ | ||
148 | +// __asm mov fs:[0], eax \ | ||
149 | +// __asm add esp, 8 \ | ||
150 | +// } |
vnr/winseh/winseh_safe.cc
0 → 100644
1 | +// winseh_safe.cc | ||
2 | +// 12/13/2013 jichi | ||
3 | +// See: http://stackoverflow.com/questions/12019689/custom-seh-handler-with-safeseh | ||
4 | + | ||
5 | +#include "winseh/winseh.h" | ||
6 | + | ||
7 | +extern "C" int __stdcall _seh_asm_handler(); | ||
8 | +seh_dword_t seh_handler = reinterpret_cast<seh_dword_t>(_seh_asm_handler); | ||
9 | + | ||
10 | +// EOF |
vnr/winseh/winseh_safe.pri
0 → 100644
1 | +# winseh_safe.pri | ||
2 | +# 12/13/2013 jichi | ||
3 | +# | ||
4 | +# Need link with with SEH assembly | ||
5 | +# See: http://stackoverflow.com/questions/12019689/custom-seh-handler-with-safeseh | ||
6 | +# See: http://stackoverflow.com/questions/19722308/exception-handler-not-called-in-c | ||
7 | +win32 { | ||
8 | +#include(../../../config.pri) | ||
9 | + | ||
10 | +# Disable buffer security check: http://msdn.microsoft.com/en-us/library/8dbf701c.aspx | ||
11 | +#QMAKE_CXXFLAGS += /GS- | ||
12 | + | ||
13 | +LIBS += safeseh.obj # compiled from safeseh.asm using ml -safeseh | ||
14 | + | ||
15 | +DEFINES += WITH_LIB_WINSEH | ||
16 | + | ||
17 | +DEPENDPATH += $$PWD | ||
18 | + | ||
19 | +HEADERS += $$PWD/winseh.h | ||
20 | +SOURCES += \ | ||
21 | + $$PWD/winseh.cc \ | ||
22 | + $$PWD/winseh_safe.cc | ||
23 | + | ||
24 | +OTHER_FILES += \ | ||
25 | + $$PWD/safeseh.asm \ | ||
26 | + $$PWD/Makefile | ||
27 | +} | ||
28 | + | ||
29 | +# EOF |
vnr/winseh/winseh_unsafe.cc
0 → 100644
1 | +// winseh_unsafe.cc | ||
2 | +// 12/13/2013 jichi | ||
3 | +// See: http://stackoverflow.com/questions/19722308/exception-handler-not-called-in-c | ||
4 | + | ||
5 | +#include "winseh/winseh.h" | ||
6 | +#include <windows.h> | ||
7 | + | ||
8 | +extern "C" EXCEPTION_DISPOSITION _seh_handler(PEXCEPTION_RECORD, PVOID, PCONTEXT, PVOID); | ||
9 | +seh_dword_t seh_handler = reinterpret_cast<seh_dword_t>(_seh_handler); | ||
10 | + | ||
11 | +// EOF |
-
Please register or login to post a comment