Skip to content

Commit 898aa79

Browse files
committed
Add debug code to detect called functions
1 parent 0f6f175 commit 898aa79

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

Wrappers/wrapper.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <fstream>
2222
#include "Logging\Logging.h"
2323

24+
//#define TROUBLESHOOT_ORDINAL_PROCS
25+
2426
namespace dsound
2527
{
2628
extern volatile FARPROC GetDeviceID_var;
@@ -33,6 +35,52 @@ namespace ddraw
3335

3436
#define VISIT_PROCS_BLANK(visit)
3537

38+
#ifdef TROUBLESHOOT_ORDINAL_PROCS
39+
40+
extern "C" void __stdcall ProcForwarder(const char* name)
41+
{
42+
// Show the function name in a MessageBox
43+
MessageBoxA(nullptr, "Function Called", name, MB_OK | MB_ICONINFORMATION);
44+
}
45+
46+
#define CREATE_PROC_STUB(procName, unused) \
47+
volatile FARPROC procName ## _var = nullptr; \
48+
extern "C" void __stdcall procName ## _forward() \
49+
{ \
50+
ProcForwarder(#procName); \
51+
} \
52+
extern "C" __declspec(naked) void __stdcall procName() \
53+
{ \
54+
__asm mov edi, edi \
55+
__asm pushfd \
56+
__asm pushad \
57+
__asm call procName ## _forward \
58+
__asm popad \
59+
__asm popfd \
60+
__asm jmp procName ## _var \
61+
} \
62+
volatile FARPROC procName ## _funct = (FARPROC)*procName;
63+
64+
#define CREATE_PROC_STUB_SHARED(procName, procName_shared, unused) \
65+
volatile FARPROC procName ## _var = nullptr; \
66+
extern "C" void __stdcall procName_shared ## _forward() \
67+
{ \
68+
ProcForwarder(#procName_shared); \
69+
} \
70+
extern "C" __declspec(naked) void __stdcall procName_shared() \
71+
{ \
72+
__asm mov edi, edi \
73+
__asm pushfd \
74+
__asm pushad \
75+
__asm call procName_shared ## _forward \
76+
__asm popad \
77+
__asm popfd \
78+
__asm jmp procName ## _var \
79+
} \
80+
volatile FARPROC procName ## _funct = (FARPROC)*procName_shared;
81+
82+
#else
83+
3684
#define CREATE_PROC_STUB(procName, unused) \
3785
volatile FARPROC procName ## _var = nullptr; \
3886
extern "C" __declspec(naked) void __stdcall procName() \
@@ -51,6 +99,8 @@ namespace ddraw
5199
} \
52100
volatile FARPROC procName ## _funct = (FARPROC)*procName_shared;
53101

102+
#endif
103+
54104
#define CREATE_PROC_STUB_ORDINALS(procName, num, prodAddr) \
55105
CREATE_PROC_STUB(procName, prodAddr)
56106

0 commit comments

Comments
 (0)