-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAoDll.cpp
206 lines (166 loc) · 4.3 KB
/
AoDll.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// AoDll.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "detours.h"
#include <string>
#include <comutil.h>
#include "AoDll.h"
#pragma comment(lib, "comsuppw.lib")
using namespace std;
//
//// Methods
//
VOID WINAPI MyRecvData(BSTR recvData); // My DataHandler Method
VOID WINAPI MySendData(BSTR* sendData); // My SendData Method
int WINAPI MyLoop(); // My Loop Method
//
//// Auxiliar Methods
//
string ConvertWCSToMBS(const wchar_t* pstr, long wslen);
BSTR ConvertStringToBSTR(const std::string & str);
BOOL StartsWith(BSTR sValue, const WCHAR* pszSubValue);
string ConvertBSTRToString(BSTR bstr);
VOID SendToClient(string message);
VOID SendToServer(string message);
//
//// Pointer Functions Declarations
//
typedef VOID(WINAPI *PRecvData)(BSTR data); //Pointer Definition - Takes BSTR and returns VOID
PRecvData PFunctionRecv = (PRecvData)0x655B10; //Pointer to where the original HandleData() starts
typedef VOID(WINAPI *PSendData)(BSTR* data); //Pointer Definition - Takes BSTR* and returns VOID
PSendData PFunctionSend = (PSendData)0x6A21C0; //Pointer to where the original SendData() starts
typedef int(WINAPI *PLoop)();
HMODULE dllModule = LoadLibraryA("MSVBVM60.DLL"); // The Address for the Loop Function.
PLoop PFunctionLoop = (PLoop)GetProcAddress(dllModule, "rtcDoEvents"); // We get it dinamically as it is a Windows Function
//
//// Main Methods
//
void Hooks()
{
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)PFunctionRecv, &MyRecvData); // Hook DataHandle() to MyRecvData()
DetourAttach(&(PVOID&)PFunctionSend, &MySendData); // Hook SendData() to MySendData()
DetourAttach(&(PVOID&)PFunctionLoop, &MyLoop); // Hook DoEvents AKA Loop() to MyLoop()
DetourTransactionCommit();
}
VOID WINAPI MyRecvData(BSTR dataRecv)
{
__asm PUSHAD;
__asm PUSHFD;
//
//// Prints paquets in Recv(Paquets from server to client)
//
OutputDebugStringW(ConvertStringToBSTR("Recv: " + ConvertBSTRToString(dataRecv)));
//
//// Returns control to the Original Function
//
PFunctionRecv(dataRecv);
__asm POPFD;
__asm POPAD;
}
VOID WINAPI MySendData(BSTR* dataSend)
{
__asm PUSHAD;
__asm PUSHFD;
//
//// Prints paquets in Send(Paquets from Client to Server)
//
OutputDebugStringW(ConvertStringToBSTR("Send: " + ConvertBSTRToString(*dataSend)));
//
//// Returns control to the Original Function
//
PFunctionSend(dataSend);
__asm POPFD;
__asm POPAD;
}
int WINAPI MyLoop()
{
__asm PUSHAD;
__asm PUSHFD;
//
//// Returns control to the Original Function
//
PFunctionLoop();
__asm POPFD;
__asm POPAD;
}
VOID SendToClient(string message)
{
try
{
//
//// Create Packet
//
BSTR recvPacket = ConvertStringToBSTR(message);
OutputDebugStringW(ConvertStringToBSTR("SendToClient: " + ConvertBSTRToString(recvPacket)));
//
//// Send Packet
//
PFunctionRecv(recvPacket);
//
//// Free Packet
//
SysFreeString(recvPacket);
}
catch (int e)
{
}
}
VOID SendToServer(string message)
{
try
{
//
//// Create Packet
//
BSTR convertedSend = ConvertStringToBSTR(message);
OutputDebugStringW(ConvertStringToBSTR("SendToServer: " + ConvertBSTRToString(convertedSend)));
//
//// Send Packet
//
PFunctionSend(&convertedSend);
//
//// Free Packet
//
SysFreeString(convertedSend);
}
catch (int e)
{
}
}
//
//// Auxiliar Methods
//
BOOL StartsWith(BSTR sValue, const WCHAR* pszSubValue)
{
if (!sValue)
return FALSE;
return wcsncmp(sValue, pszSubValue, wcslen(pszSubValue)) == 0;
}
string ConvertWCSToMBS(const wchar_t* pstr, long wslen)
{
int len = ::WideCharToMultiByte(CP_ACP, 0, pstr, wslen, NULL, 0, NULL, NULL);
std::string dblstr(len, '\0');
len = ::WideCharToMultiByte(CP_ACP, 0 /* no flags */,
pstr, wslen /* not necessary NULL-terminated */,
&dblstr[0], len,
NULL, NULL /* no default char */);
return dblstr;
}
string ConvertBSTRToString(BSTR bstr)
{
int wslen = ::SysStringLen(bstr);
return ConvertWCSToMBS((wchar_t*)bstr, wslen);
}
BSTR ConvertStringToBSTR(const std::string & str)
{
int wslen = ::MultiByteToWideChar(CP_ACP, 0 /* no flags */,
str.data(), str.length(),
NULL, 0);
BSTR wsdata = ::SysAllocStringLen(NULL, wslen);
::MultiByteToWideChar(CP_ACP, 0 /* no flags */,
str.data(), str.length(),
wsdata, wslen);
return wsdata;
}