-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtemplate.cpp
More file actions
77 lines (66 loc) · 2.24 KB
/
Copy pathtemplate.cpp
File metadata and controls
77 lines (66 loc) · 2.24 KB
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
#define QT_VERSION_MAJOR 5
#define QT_VERSION_MINOR 15
#define QT_VERSION_PATCH 5
#include "pch.h"
#include <windows.h>
#include <shlobj.h>
#include <string>
#include <vector>
#include <filesystem>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <detours.h>
#include <fstream>
#include <sstream>
#include <WinInet.h>
#include <commdlg.h>
#pragma comment(lib, "detours.lib")
#define _CRT_SECURE_NO_DEPRECATE
#pragma warning(disable : 4996)
// ?renderText@QGLWidget@QT@@QEAAXNNNAEBVQString@2@AEBVQFont@2@@Z
#pragma comment(linker, "/export:?renderText@QGLWidget@QT@@QEAAXNNNAEBVQString@2@AEBVQFont@2@@Z=tmpB458.?renderText@QGLWidget@QT@@QEAAXNNNAEBVQString@2@AEBVQFont@2@@Z,@499")
/*
1. find the target function and get the adress
2. add the originalFunction and DetourAttach
3. add the typedef and OriginalFunctionType
4. edit the redirect function
*/
typedef void(__fastcall *OriginalFunctionType)(double, double);
OriginalFunctionType originalFunction = nullptr;
void __fastcall MyFunction(double a1, double a2)
{
HWND hwnd = GetActiveWindow();
MessageBox(NULL, L"DLL HOOK", L"Tips", MB_OK);
originalFunction(a1, a2);
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
if (ul_reason_for_call == DLL_PROCESS_ATTACH)
{
// Get the address of the original function
originalFunction = (void(__fastcall *)(double, double))GetProcAddress(GetModuleHandle(L"DLLNAME"), "?renderText@QGLWidget@QT@@QEAAXNNNAEBVQString@2@AEBVQFont@2@@Z");
if (originalFunction != nullptr)
{
// Detour the original function
DetourRestoreAfterWith();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID &)originalFunction, MyFunction);
DetourTransactionCommit();
}
}
else if (ul_reason_for_call == DLL_PROCESS_DETACH)
{
// Restore the original function
if (originalFunction != nullptr)
{
DetourRestoreAfterWith();
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(PVOID &)originalFunction, MyFunction);
DetourTransactionCommit();
}
}
return TRUE;
}