Freeglut hell

This commit is contained in:
Bottersnike 2023-02-15 05:25:32 +00:00
parent be903943bb
commit c37ed01bb5
Signed by: Bottersnike
SSH Key Fingerprint: SHA256:3g0ghwd4dNX1k1RX8qazbiT+3RIYn/daeBevHZVCiU0
9 changed files with 69 additions and 24 deletions

View File

@ -150,7 +150,9 @@ void tea_hook_test(char* fmt, ...) {
int mxkMain();
DWORD WINAPI MxkThreadProc(LPVOID lpParameter) { mxkMain(); };
void spawn_pcp_processes(void) { CreateThread(NULL, 0, &MxkThreadProc, NULL, 0, NULL); }
void spawn_pcp_processes(void) {
// CreateThread(NULL, 0, &MxkThreadProc, NULL, 0, NULL);
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) {
if (ul_reason_for_call != DLL_PROCESS_ATTACH) return TRUE;

View File

@ -372,13 +372,16 @@ void hook_gui() {
hook("User32.dll", "ChangeDisplaySettingsExW", FakeChangeDisplaySettingsExW,
(void**)&TrueChangeDisplaySettingsExW);
hook("D3d9.dll", "Direct3DCreate9", FakeDirect3DCreate9, (void**)&TrueDirect3DCreate9);
// Hooked as a way to identify use of GLUT
hook("FREEGLUT.DLL", "glutInitDisplayMode", Fake_glutInitDisplayMode,
(void**)&True_glutInitDisplayMode);
hook("FREEGLUT.DLL", "glutFullScreen", Fake_glutFullScreen, (void**)&True_glutFullScreen);
hook("FREEGLUT.DLL", "glutPositionWindow", Fake_glutPositionWindow,
(void**)&True_glutPositionWindow);
hook("FREEGLUT.DLL", "glutReshapeWindow", Fake_glutReshapeWindow,
(void**)&True_glutReshapeWindow);
hook("FREEGLUT.DLL", "glutSwapBuffers", Fake_glutSwapBuffers, (void**)&True_glutSwapBuffers);
if (PathFileExistsA("FREEGLUT.DLL")) {
// Hooked as a way to identify use of GLUT
hook("FREEGLUT.DLL", "glutInitDisplayMode", Fake_glutInitDisplayMode,
(void**)&True_glutInitDisplayMode);
hook("FREEGLUT.DLL", "glutFullScreen", Fake_glutFullScreen, (void**)&True_glutFullScreen);
hook("FREEGLUT.DLL", "glutPositionWindow", Fake_glutPositionWindow,
(void**)&True_glutPositionWindow);
hook("FREEGLUT.DLL", "glutReshapeWindow", Fake_glutReshapeWindow,
(void**)&True_glutReshapeWindow);
hook("FREEGLUT.DLL", "glutSwapBuffers", Fake_glutSwapBuffers,
(void**)&True_glutSwapBuffers);
}
}

View File

@ -33,5 +33,8 @@ shared_library(
include_directories: [
openssl_inc,
],
dependencies: [cimgui.get_variable('cimgui_dep'), freeglut_lib]
dependencies: [
cimgui.get_variable('cimgui_dep'),
# freeglut_lib, # forces the use of freeglut.dll!
]
)

View File

@ -55,7 +55,6 @@ void parse_cmdline(int argc, char* argv[]) {
int main(int argc, char* argv[]) {
load_mice_config();
fprintf(stderr, "Argc: %d\n", argc);
CHAR workDir[MAX_PATH + 1];
GetCurrentDirectory(MAX_PATH, workDir);
fprintf(stderr, "Work dir: %s\n", workDir);

View File

@ -214,7 +214,6 @@ void load_mice_config() {
if (MiceConfig.keys.board_count > JVS_IO_MAX) MiceConfig.keys.board_count = JVS_IO_MAX;
char *text = MiceConfig.keys.keys;
printf("Text: %s\n", text);
if (text) {
char *copy = (char *)malloc(strlen(text) + 1);
memcpy_s(copy, strlen(text) + 1, text, strlen(text) + 1);

View File

@ -33,7 +33,7 @@ bool remote_call(HANDLE process, LPVOID function, LPCSTR argument, DWORD* result
HANDLE remote_thread =
CreateRemoteThread(process, NULL, 0, (LPTHREAD_START_ROUTINE)function, arg_addr, 0, NULL);
if (remote_thread == NULL) {
if (remote_thread == INVALID_HANDLE_VALUE) {
fprintf(stderr, "Fatal: CreateRemoteThread failed: %03x\n", GetLastError());
return false;
}
@ -99,16 +99,14 @@ HANDLE start_and_inject(LPCSTR path, LPSTR cmdline, LPCSTR inject, BOOL debug_wa
// Start the binary
flags |= CREATE_SUSPENDED;
if (!CreateProcessA(path, cmdline, NULL, NULL, FALSE, flags, NULL, NULL,
&startupInfo, &processInformation)) {
if (!CreateProcessA(path, cmdline, NULL, NULL, FALSE, flags, NULL, NULL, &startupInfo,
&processInformation)) {
fprintf(stderr, "Fatal: CreateProcessA failed: %03x\n", GetLastError());
goto abort;
}
if (debug_wait) {
if (debug_wait)
if (!inject_debug_wait(processInformation.hProcess)) goto abort;
}
// Sleep(5000);
if (!inject_dll(processInformation.hProcess, inject)) goto abort;
if (extra_injections != NULL && extra_injections[0] != '\0') {
@ -140,15 +138,15 @@ HANDLE start_and_inject(LPCSTR path, LPSTR cmdline, LPCSTR inject, BOOL debug_wa
return processInformation.hProcess;
abort:
if (processInformation.hProcess) {
if (!CloseHandle(processInformation.hThread))
if (processInformation.hProcess && processInformation.hProcess != INVALID_HANDLE_VALUE) {
if (!CloseHandle(processInformation.hThread) && GetLastError() != ERROR_INVALID_HANDLE)
fprintf(stderr, "Fatal: CloseHandle(hProcess) failed: %03x\n", GetLastError());
if (!TerminateProcess(processInformation.hProcess, 1))
fprintf(stderr, "Fatal: TerminateProcess failed: %03x\n", GetLastError());
}
if (processInformation.hThread) {
if (!CloseHandle(processInformation.hThread))
if (processInformation.hThread && processInformation.hThread != INVALID_HANDLE_VALUE) {
if (!CloseHandle(processInformation.hThread) && GetLastError() != ERROR_INVALID_HANDLE)
fprintf(stderr, "Fatal: CloseHandle(hThread) failed: %03x\n", GetLastError());
}

View File

@ -0,0 +1,38 @@
#include "freeglut.h"
#include <Windows.h>
HMODULE hFreeGLUT = 0;
#define WRAP(procName, ret) \
if (!hFreeGLUT) hFreeGLUT = LoadLibraryA("freeglut.dll"); \
if (hFreeGLUT == INVALID_HANDLE_VALUE) return ret; \
return ((decltype(procName)*)(GetProcAddress(hFreeGLUT, #procName)))
void FGAPIENTRY glutPassiveMotionFunc(void (*callback)(int, int)) {
WRAP(glutPassiveMotionFunc, )(callback);
}
void FGAPIENTRY glutKeyboardUpFunc(void (*callback)(unsigned char, int, int)) {
WRAP(glutKeyboardUpFunc, )(callback);
}
void FGAPIENTRY glutMouseFunc(void (*callback)(int, int, int, int)) {
WRAP(glutMouseFunc, )(callback);
}
void FGAPIENTRY glutKeyboardFunc(void (*callback)(unsigned char, int, int)) {
WRAP(glutKeyboardFunc, )(callback);
}
void FGAPIENTRY glutSpecialFunc(void (*callback)(int, int, int)) {
WRAP(glutSpecialFunc, )(callback);
}
void FGAPIENTRY glutMotionFunc(void (*callback)(int, int)) { WRAP(glutMotionFunc, )(callback); }
int FGAPIENTRY glutGet(unsigned int query) { WRAP(glutGet, -1)(query); }
void FGAPIENTRY glutReshapeFunc(void (*callback)(int, int)) { WRAP(glutReshapeFunc, )(callback); }
int FGAPIENTRY glutGetModifiers(void) { WRAP(glutGetModifiers, -1)(); }
void FGAPIENTRY glutSpecialUpFunc(void (*callback)(int, int, int)) {
WRAP(glutSpecialUpFunc, )(callback);
}
void FGAPIENTRY glutMouseWheelFunc(void (*callback)(int, int, int, int)) {
WRAP(glutMouseWheelFunc, )(callback);
}

View File

@ -78,7 +78,9 @@
/* Link with Win32 shared freeglut lib */
# if FREEGLUT_LIB_PRAGMAS
# pragma comment (lib, "freeglut.lib")
// Disabled! We're going to to load freeglut in at runtime!
// # pragma comment (lib, "freeglut.lib")
# define FGAPI extern
# endif
# endif

View File

@ -15,6 +15,7 @@ if get_option('opengl2').enabled()
endif
if get_option('glut').enabled()
sources += 'backends/imgui_impl_glut.cpp'
sources += 'backends/GL/freeglut.cpp'
endif
if get_option('dx11').enabled()
sources += 'backends/imgui_impl_dx11.cpp'