1
+ #include " d3d_Hook.hpp"
2
+
3
+ #include < MinHook.h>
4
+
5
+ bool Hook::Init ()
6
+ {
7
+ const std::string Title = E (" SKYPE TERMINAL CALLING" );
8
+
9
+ WNDCLASSEX Window;
10
+
11
+ Window.cbSize = sizeof (WNDCLASSEX);
12
+ Window.style = CS_HREDRAW | CS_VREDRAW;
13
+
14
+ Window.lpfnWndProc = DefWindowProcA;
15
+ Window.cbClsExtra = NULL ;
16
+ Window.cbWndExtra = NULL ;
17
+ Window.hInstance = SAFE_CALL (GetModuleHandleA)(nullptr );
18
+ Window.hIcon = NULL ;
19
+ Window.hCursor = NULL ;
20
+ Window.hbrBackground = NULL ;
21
+ Window.lpszMenuName = NULL ;
22
+ Window.lpszClassName = Title.c_str ();
23
+ Window.hIconSm = NULL ;
24
+
25
+ SAFE_CALL (RegisterClassExA)(&Window);
26
+
27
+ HWND WindowA = CreateWindowA (Window.lpszClassName , Title.c_str (), WS_OVERLAPPEDWINDOW, 0 , 0 , 100 , 100 , 0 , 0 , Window.hInstance , 0 );
28
+
29
+ HMODULE D3D11_DLL;
30
+ if ((D3D11_DLL = SAFE_CALL (GetModuleHandleA)(E (" d3d11.dll" ))) == NULL )
31
+ {
32
+ SAFE_CALL (DestroyWindow)(WindowA);
33
+ SAFE_CALL (UnregisterClassA)(Window.lpszClassName , Window.hInstance );
34
+
35
+ return false ;
36
+ }
37
+
38
+ void * D3D11CreateDeviceAndSwapChain;
39
+
40
+ if ((D3D11CreateDeviceAndSwapChain = SAFE_CALL (GetProcAddress)(D3D11_DLL, E (" D3D11CreateDeviceAndSwapChain" ))) == NULL )
41
+ {
42
+ SAFE_CALL (DestroyWindow)(WindowA);
43
+ SAFE_CALL (UnregisterClassA)(Window.lpszClassName , Window.hInstance );
44
+
45
+ return false ;
46
+ }
47
+
48
+ D3D_FEATURE_LEVEL featureLevel;
49
+ const D3D_FEATURE_LEVEL featureLevels[] = { D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_11_0 };
50
+ DXGI_RATIONAL refreshRate;
51
+ refreshRate.Numerator = 60 ;
52
+ refreshRate.Denominator = 1 ;
53
+
54
+ DXGI_MODE_DESC bufferDesc;
55
+ bufferDesc.Width = 100 ;
56
+ bufferDesc.Height = 100 ;
57
+ bufferDesc.RefreshRate = refreshRate;
58
+ bufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
59
+ bufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
60
+ bufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
61
+
62
+ DXGI_SAMPLE_DESC sampleDesc;
63
+ sampleDesc.Count = 1 ;
64
+ sampleDesc.Quality = 0 ;
65
+
66
+ DXGI_SWAP_CHAIN_DESC swapChainDesc;
67
+ swapChainDesc.BufferDesc = bufferDesc;
68
+ swapChainDesc.SampleDesc = sampleDesc;
69
+ swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
70
+ swapChainDesc.BufferCount = 1 ;
71
+ swapChainDesc.OutputWindow = WindowA;
72
+ swapChainDesc.Windowed = 1 ;
73
+ swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
74
+ swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
75
+
76
+ IDXGISwapChain* swapChain;
77
+ ID3D11Device* device;
78
+ ID3D11DeviceContext* context;
79
+
80
+ if (((long (__stdcall*)(
81
+ IDXGIAdapter*,
82
+ D3D_DRIVER_TYPE,
83
+ HMODULE,
84
+ UINT,
85
+ const D3D_FEATURE_LEVEL*,
86
+ UINT,
87
+ UINT,
88
+ const DXGI_SWAP_CHAIN_DESC*,
89
+ IDXGISwapChain**,
90
+ ID3D11Device**,
91
+ D3D_FEATURE_LEVEL*,
92
+ ID3D11DeviceContext**))(D3D11CreateDeviceAndSwapChain))(0 , D3D_DRIVER_TYPE_HARDWARE, 0 , 0 , featureLevels, 2 , D3D11_SDK_VERSION, &swapChainDesc, &swapChain, &device, &featureLevel, &context) < 0 )
93
+ {
94
+ SAFE_CALL (DestroyWindow)(WindowA);
95
+ SAFE_CALL (UnregisterClassA)(Window.lpszClassName , Window.hInstance );
96
+
97
+ return false ;
98
+ }
99
+
100
+ g_methodsTable = (uint64_t *)calloc (205 , sizeof (uint64_t ));
101
+
102
+ memcpy (g_methodsTable, *(uint64_t **)swapChain, 18 * sizeof (uint64_t ));
103
+ memcpy (g_methodsTable + 18 , *(uint64_t **)device, 43 * sizeof (uint64_t ));
104
+ memcpy (g_methodsTable + 18 + 43 , *(uint64_t **)context, 144 * sizeof (uint64_t ));
105
+
106
+ MH_Initialize ();
107
+
108
+ swapChain->Release ();
109
+ swapChain = 0 ;
110
+
111
+ device->Release ();
112
+ device = 0 ;
113
+
114
+ context->Release ();
115
+ context = 0 ;
116
+
117
+ SAFE_CALL (DestroyWindow)(WindowA);
118
+ SAFE_CALL (UnregisterClassA)(Window.lpszClassName , Window.hInstance );
119
+
120
+ return true ;
121
+ }
122
+
123
+ bool Hook::Present (void ** hk_originalFunction, void * hk_hookedPresent)
124
+ {
125
+ if (!hk_originalFunction || !hk_hookedPresent)
126
+ return false ;
127
+
128
+ void * target = (void *)g_methodsTable[8 ];
129
+
130
+ if (!target)
131
+ return false ;
132
+
133
+ if (MH_CreateHook (target, hk_hookedPresent, hk_originalFunction) != MH_OK || MH_EnableHook (target) != MH_OK)
134
+ {
135
+ return false ;
136
+ }
137
+
138
+ return true ;
139
+ }
0 commit comments