-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.cpp
148 lines (124 loc) · 4 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "main.h"
void Main(void)
{
HMODULE hObs;
MODULEINFO qObs = { 0 };
if (!NModule::bCaptureModule< HMODULE >(&hObs, &qObs, L"obs.dll"))
{
return;
}
NOBS::pOsWcsToUtf8Ptr = (NOBS::OsWcsToUtf8Ptr_t)GetProcAddress(hObs, "os_wcs_to_utf8_ptr");
if (!NOBS::pOsWcsToUtf8Ptr)
{
return;
}
uintptr_t uiWinCapture;
MODULEINFO qWinCapture = { 0 };
if (!NModule::bCaptureModule< uintptr_t >(&uiWinCapture, &qWinCapture, L"win-capture.dll"))
{
return;
}
const uint8_t kuchSignature[34] = { 0x48, 0x89, 0x5C, 0x24, 0x0, 0x57, 0x48, 0x81, 0xEC, 0x0, 0x0, 0x0, 0x0, 0x48, 0x8B, 0x05, 0x0, 0x0, 0x0, 0x0, 0x48, 0x33, 0xC4, 0x48, 0x89, 0x84, 0x24, 0x0, 0x0, 0x0, 0x0, 0x45, 0x33, 0xC9 };
const char kchMask[35] = "xxxx?xxxx????xxx????xxxxxxx????xxx";
NOBS::uiGetHookPath = NPattern::uiFindPattern(uiWinCapture, qWinCapture.SizeOfImage, kuchSignature, kchMask);
if (!NOBS::uiGetHookPath)
{
return;
}
char *chpHookPathX86 = ((NOBS::GetHookPath_t)NOBS::uiGetHookPath)(false);
if (!chpHookPathX86)
{
return;
}
std::wstring wstHookPathX86 = NString::wstStringToWString(std::string(chpHookPathX86, strlen(chpHookPathX86) + 1));
char *chpHookPathX64 = ((NOBS::GetHookPath_t)NOBS::uiGetHookPath)(true);
if (!chpHookPathX64)
{
return;
}
std::wstring wstHookPathX64 = NString::wstStringToWString(std::string(chpHookPathX64, strlen(chpHookPathX64) + 1));
if (!NFile::bDirectory(NString::stWStringToString(NPath::kwstHookPath).c_str()))
{
if (!CreateDirectory(NPath::kwstHookPath.c_str(), 0))
{
int32_t iMessage = MessageBox(GetActiveWindow(), L"Please run OBS as administrator to create the directory", L"Information", MB_OK);
if (iMessage == IDOK)
{
ExitProcess(0);
}
}
}
std::vector< uint8_t > vuchBytesX86[2];
std::vector< uint8_t > vuchBytesX64[2];
uint32_t uiLastError;
if (NFile::bReadFile(wstHookPathX86, vuchBytesX86[0], &uiLastError) && NFile::bReadFile(wstHookPathX64, vuchBytesX64[0], &uiLastError))
{
if ((NFile::bReadFile(NPath::kwstHookPathX86, vuchBytesX86[1], &uiLastError) || uiLastError == ERROR_FILE_NOT_FOUND) &&
((vuchBytesX86[0].size() != vuchBytesX86[1].size()) || (memcmp((void*)&vuchBytesX86[0][0], (void*)&vuchBytesX86[1][0], vuchBytesX86[0].size()) != 0)))
{
if (!CopyFile(wstHookPathX86.c_str(), NPath::kwstHookPathX86.c_str(), FALSE))
{
int32_t iMessage = MessageBox(GetActiveWindow(), L"Please run OBS as administrator to copy the files", L"Information", MB_OK);
if (iMessage == IDOK)
{
ExitProcess(0);
}
}
}
if ((NFile::bReadFile(NPath::kwstHookPathX64, vuchBytesX64[1], &uiLastError) || uiLastError == ERROR_FILE_NOT_FOUND) &&
((vuchBytesX64[0].size() != vuchBytesX64[1].size()) || (memcmp((void*)&vuchBytesX64[0][0], (void*)&vuchBytesX64[1][0], vuchBytesX64[0].size()) != 0)))
{
if (!CopyFile(wstHookPathX64.c_str(), NPath::kwstHookPathX64.c_str(), FALSE))
{
int32_t iMessage = MessageBox(GetActiveWindow(), L"Please run OBS as administrator to copy the files", L"Information", MB_OK);
if (iMessage == IDOK)
{
ExitProcess(0);
}
}
}
}
else
{
///...
}
NOBS::pGetHookPath = (NOBS::GetHookPath_t)NDetour::pDetourFunction((void*)NOBS::uiGetHookPath, (void*)NOBS::Hook_GetHookPath, 13);
if (!NOBS::pGetHookPath)
{
return;
}
return;
}
BOOL APIENTRY DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved)
{
if (dwReason == DLL_PROCESS_ATTACH)
{
DisableThreadLibraryCalls(hModule);
HANDLE hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)Main, 0, 0, 0);
if (!hThread)
{
return FALSE;
}
CloseHandle(hThread);
}
return TRUE;
}
extern "C" __declspec(dllexport) bool LoadPlugin(void)
{
return true;
}
extern "C" __declspec(dllexport) void UnloadPlugin(void)
{
if (NOBS::pGetHookPath)
{
NDetour::RemoveDetourFunction((void*)NOBS::uiGetHookPath, (void*)NOBS::pGetHookPath, 13);
}
}
extern "C" __declspec(dllexport) const wchar_t *GetPluginName(void)
{
return L"OBS-CS:GO";
}
extern "C" __declspec(dllexport) const wchar_t *GetPluginDescription(void)
{
return L"OBS-CS:GO";
}