-
Notifications
You must be signed in to change notification settings - Fork 0
/
qtfile.mustache
155 lines (141 loc) · 5.15 KB
/
qtfile.mustache
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
149
150
151
152
153
154
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include "zmq.hpp"
#include <windows.h>
#include <detours.h>
#include <QtCore/QObject>
#include <QtCore/qobjectdefs.h>
typedef int (WINAPI qt_metacall_signature)(QMetaObject::Call _c, int _id, void **_a);
#define METACALL(function, _c, _id, _a, ret_var) __asm {\
__asm mov ecx, _this\
__asm push _a\
__asm push _id\
__asm push _c\
__asm call function\
__asm mov ret_var, eax\
}
zmq::context_t *context;
zmq::socket_t *sock;
{{#classes}}
{{#do}}
qt_metacall_signature* {{metacall_address_name}} = (qt_metacall_signature*)(void*){{metacall_function_address}};
qt_metacall_signature* {{metacall_address_name}}_super = {{#indirection}}*{{/indirection}}(qt_metacall_signature{{#indirection}}*{{/indirection}}*){{metacall_super_function_address}};
int WINAPI {{metacall_hook_name}}(QMetaObject::Call _c, int _id, void **_a) {
void *_this;
int ret_id;
__asm mov _this, ecx
METACALL({{metacall_address_name}}_super, _c, _id, _a, ret_id)
if (ret_id < 0) {
return ret_id;
} else {
if (_c == QMetaObject::InvokeMetaMethod){
std::stringstream oss;
std::string s;
zmq::message_t *message;
switch (ret_id) {
{{#methods}}
case {{id}}:
oss<<"{{name}}::{{signature}} called";
s = oss.str();
//logfile<<(GetTickCount()-start)/1000.0<<"s: {{name}}::{{signature}} called"<<std::endl;
message = new zmq::message_t(s.length());
memcpy((void *)message->data(), s.c_str(), s.length());
sock->send(*message);
delete message;
break;
{{/methods}}
}
}
METACALL({{metacall_address_name}}, _c, _id, _a, _id)
return _id;
}
}
{{/do}}
{{/classes}}
BOOL DllProcessAttach(HINSTANCE hinst) {
LONG errCode;
if (NO_ERROR != (errCode = DetourTransactionBegin())) {
switch (errCode) {
case ERROR_INVALID_OPERATION:
std::cout<<"DetourTransactionBegin failed. A pending transaction already exists."<<std::endl;
break;
}
return FALSE;
}
DisableThreadLibraryCalls(hinst);
if (NO_ERROR != (errCode = DetourUpdateThread(GetCurrentThread()))) {
switch (errCode) {
case ERROR_NOT_ENOUGH_MEMORY:
std::cout<<"DetourUpdateThread failed. Not enough memory to record identity of thread."<<std::endl;
break;
}
DetourTransactionAbort();
return FALSE;
}
{{#classes}}
{{#do}}
if (NO_ERROR != (errCode = DetourAttach(&(PVOID&){{metacall_address_name}}, &{{metacall_hook_name}}))) {
switch (errCode) {
case ERROR_INVALID_BLOCK:
std::cout<<"DetourAttach failed. The function referenced is too small to be detoured."<<std::endl;
break;
case ERROR_INVALID_HANDLE:
std::cout<<"DetourAttach failed. The ppPointer parameter is null or points to a null pointer."<<std::endl;
break;
case ERROR_INVALID_OPERATION:
std::cout<<"DetourAttach failed. No pending transaction exists."<<std::endl;
break;
case ERROR_NOT_ENOUGH_MEMORY:
std::cout<<"DetourAttach failed. Not enough memory exists to complete the operation."<<std::endl;
break;
}
DetourTransactionAbort();
return FALSE;
}
{{/do}}
{{/classes}}
if (NO_ERROR != (errCode = DetourTransactionCommit())) {
switch (errCode) {
case ERROR_INVALID_DATA:
std::cout<<"DetourTransactionCommit failed. Target function was changed by third party between steps of the transaction."<<std::endl;
break;
case ERROR_INVALID_OPERATION:
std::cout<<"DetourTransactionCommit failed. No pending transaction exists."<<std::endl;
break;
default:
std::cout<<"DetourTransactionCommit failed. Other error."<<std::endl;
break;
}
DetourTransactionAbort();
return FALSE;
}
return TRUE;
}
BOOL DllProcessDetach() {
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
{{#classes}}{{#do}}
DetourDetach(&(PVOID&){{metacall_address_name}}, {{metacall_hook_name}});{{/do}}{{/classes}}
DetourTransactionCommit();
return TRUE;
}
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved)
{
switch (dwReason) {
case DLL_PROCESS_ATTACH:
context = new zmq::context_t(1);
sock = new zmq::socket_t(*context, ZMQ_PUSH);
sock->connect("tcp://localhost:5556");
return DllProcessAttach(hinst);
case DLL_PROCESS_DETACH:
//if (context) {
//delete context;
//}
//logfile.close();
return DllProcessDetach();
default:
return TRUE;
}
}