Skip to content

Commit 635cf21

Browse files
committed
BT BATTLES INJECTION
0 parents  commit 635cf21

File tree

4 files changed

+161
-0
lines changed

4 files changed

+161
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vs/
2+
out/

CMakeLists.txt

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
cmake_minimum_required(VERSION 3.17)
2+
project(B2FW-SDK VERSION 1.0 LANGUAGES CXX)
3+
4+
include(FetchContent)
5+
set(CMAKE_CXX_STANDARD 20)
6+
7+
#Get the git diff ID thing and make a compile def for it
8+
EXECUTE_PROCESS(
9+
COMMAND git rev-parse --short HEAD
10+
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
11+
OUTPUT_VARIABLE "SDK_BUILD_VERSION"
12+
ERROR_QUIET
13+
OUTPUT_STRIP_TRAILING_WHITESPACE)
14+
15+
add_compile_definitions(SDK_BUILD_TAG=0.0.1)
16+
add_compile_definitions(SDK_BUILD_VERSION=${SDK_BUILD_VERSION})
17+
add_compile_definitions(_ITERATOR_DEBUG_LEVEL=0)
18+
19+
#Fetch & Install PolyHook2
20+
FetchContent_Declare(
21+
plh
22+
GIT_REPOSITORY https://github.com/stevemk14ebr/PolyHook_2_0.git
23+
GIT_TAG master
24+
)
25+
FetchContent_GetProperties(plh)
26+
if(NOT plh_POPULATED)
27+
FetchContent_Populate(plh)
28+
set(POLYHOOK_BUILD_DLL ON)
29+
add_subdirectory(${plh_SOURCE_DIR} ${plh_BINARY_DIR})
30+
endif()
31+
32+
FetchContent_Declare(
33+
json
34+
GIT_REPOSITORY https://github.com/nlohmann/json.git
35+
GIT_TAG master
36+
)
37+
FetchContent_GetProperties(json)
38+
if(NOT json_POPULATED)
39+
FetchContent_Populate(json)
40+
add_subdirectory(${json_SOURCE_DIR} ${json_BINARY_DIR})
41+
include_directories(${json_SOURCE_DIR}/include)
42+
endif()
43+
44+
FetchContent_Declare(
45+
menum
46+
GIT_REPOSITORY https://github.com/Neargye/magic_enum.git
47+
GIT_TAG master
48+
)
49+
FetchContent_GetProperties(menum)
50+
if(NOT menum_POPULATED)
51+
FetchContent_Populate(menum)
52+
add_subdirectory(${menum_SOURCE_DIR} ${menum_BINARY_DIR})
53+
endif()
54+
55+
add_subdirectory(proxy)

proxy/CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
add_library(winhttp SHARED)
2+
target_sources(winhttp PRIVATE
3+
"${CMAKE_CURRENT_LIST_DIR}/main.cpp"
4+
)

proxy/main.cpp

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
#include <shlobj_core.h>
2+
#include <stdio.h>
3+
#include <string>
4+
#include <Windows.h>
5+
6+
static HMODULE WinHttp;
7+
static bool(__stdcall* oWinHttpGetIEProxyConfigForCurrentUser)(void*);
8+
9+
#define EXPORT comment(linker, "/EXPORT:" __FUNCTION__ "=" __FUNCDNAME__)
10+
11+
extern "C" __declspec(dllexport) bool __stdcall WinHttpGetIEProxyConfigForCurrentUser(void* proxyConFig) {
12+
int result = oWinHttpGetIEProxyConfigForCurrentUser(proxyConFig);
13+
return result;
14+
}
15+
16+
void initialize(HINSTANCE hinstDLL) {// allocate console window; find original winhttp dll file; find and load it;
17+
// store handle to dll file; find original handle version
18+
AllocConsole();
19+
FILE* dummy;
20+
freopen_s(&dummy, "CONIN$", "r", stdin);
21+
freopen_s(&dummy, "CONOUT$", "w", stderr);
22+
freopen_s(&dummy, "CONOUT$", "w", stdout);
23+
24+
//Find original wininet.dll
25+
char sys32Path[MAX_PATH];
26+
27+
memset(sys32Path, 0, MAX_PATH);
28+
29+
#if INTPTR_MAX == INT64_MAX
30+
SHGetFolderPathA(nullptr, CSIDL_SYSTEM, nullptr, SHGFP_TYPE_CURRENT, sys32Path);
31+
#elif INTPTR_MAX == INT32_MAX
32+
SHGetFolderPathA(nullptr, CSIDL_SYSTEMX86, nullptr, SHGFP_TYPE_CURRENT, sys32Path);
33+
#endif
34+
35+
std::string sys32Str(sys32Path);
36+
std::string winhttpPath = sys32Str + "\\Winhttp.dll";
37+
38+
WinHttp = LoadLibraryA(winhttpPath.c_str());
39+
if (WinHttp == NULL) {
40+
MessageBoxA(0, "Failed to find Winhttp.dll in System32", "Proxy Error", MB_OK);
41+
exit(1);
42+
}
43+
else {
44+
printf("Loaded original wininet\n");
45+
46+
}
47+
48+
oWinHttpGetIEProxyConfigForCurrentUser = (bool(__stdcall*)(void*))GetProcAddress(WinHttp, "WinHttpGetIEProxyConfigForCurrentUser");
49+
if (oWinHttpGetIEProxyConfigForCurrentUser == NULL) {
50+
MessageBoxA(0, "Failed to find WinHttpGetIEProxyConfigForCurrentUser", "Proxy Error", MB_OK);
51+
exit(1);
52+
}
53+
}
54+
55+
56+
// Implement dll main
57+
BOOL WINAPI DllMain(
58+
HINSTANCE hinstDLL, // handle to DLL module
59+
DWORD fdwReason, // reason for calling function
60+
LPVOID lpvReserved) // reserved
61+
{
62+
// Perform actions based on the reason for calling.
63+
switch (fdwReason)
64+
{
65+
case DLL_PROCESS_ATTACH:
66+
// Initialize once for each new process.
67+
// Return FALSE to fail DLL load.
68+
// Write code here
69+
initialize(hinstDLL);
70+
break;
71+
72+
case DLL_THREAD_ATTACH:
73+
// Do thread-specific initialization.
74+
break;
75+
76+
case DLL_THREAD_DETACH:
77+
// Do thread-specific cleanup.
78+
break;
79+
80+
case DLL_PROCESS_DETACH:
81+
82+
if (lpvReserved != nullptr)
83+
{
84+
break; // do not do cleanup if process termination scenario
85+
}
86+
87+
// Perform any necessary cleanup.
88+
break;
89+
}
90+
return TRUE; // Successful DLL_PROCESS_ATTACH.
91+
}
92+
93+
//WinHttpGetIEProxyConfigForCurrentUser
94+
95+
/*
96+
1. Write the function
97+
2. Tell linker don't change function name
98+
3. Original function
99+
*/
100+

0 commit comments

Comments
 (0)