-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInjector.cpp
More file actions
162 lines (142 loc) · 2.87 KB
/
Copy pathInjector.cpp
File metadata and controls
162 lines (142 loc) · 2.87 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
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
#include "stdafx.h"
void* my_memcpy(void * _Dst, const void * _Src, size_t _Size)
{
return memcpy(_Dst, _Src, _Size);
}
DWORD InjectedFunction::Call(LPVOID lpStackTop, LPDWORD lpReturnValue, DWORD dwMaxArgSize)
{
if (lpStdcallFunction)
{
typedef DWORD(INJECT_STDCALL *StdcallNoArg)();
StdcallNoArg pf = static_cast<StdcallNoArg>(lpStdcallFunction);
if (szArgSize <= dwMaxArgSize)
{
DWORD returnValue;
DWORD mszArgSize = szArgSize;
__asm {
sub esp, mszArgSize;
lea eax, [esp];
push mszArgSize;
push lpStackTop;
push eax;
call my_memcpy;
add esp, 12;
mov eax, pf;
call eax;
mov returnValue, eax;
}
return returnValue;
}
else if (szArgSize == dwMaxArgSize + 4)
{
DWORD returnValue = *lpReturnValue;
DWORD mszArgSize = szArgSize;
__asm {
push returnValue;
sub esp, dwMaxArgSize;
lea eax, [esp];
push dwMaxArgSize;
push lpStackTop;
push eax;
call my_memcpy;
add esp, 12;
mov eax, pf;
call eax;
mov returnValue, eax;
}
return returnValue;
}
//Error
return 0;
}
else if (lpCdeclFunction)
{
typedef DWORD(INJECT_CDECL *CdeclNoArg)();
CdeclNoArg pf = static_cast<CdeclNoArg>(lpCdeclFunction);
if (szArgSize <= dwMaxArgSize)
{
DWORD returnValue;
DWORD mszArgSize = szArgSize;
LPDWORD lpModifiedReturned;
__asm {
push ecx;
push edx;
sub esp, mszArgSize;
lea eax, [esp];
mov lpModifiedReturned, eax;
push mszArgSize;
push lpStackTop;
push eax;
call my_memcpy;
add esp, 12;
mov eax, pf;
call eax;
push mszArgSize;
push lpModifiedReturned;
push lpStackTop;
call my_memcpy;
add esp, 12;
mov returnValue, eax;
add esp, mszArgSize;
pop edx;
pop ecx;
}
return returnValue;
}
else if (szArgSize == dwMaxArgSize + 4)
{
DWORD returnValue = *lpReturnValue;
DWORD mszArgSize = szArgSize;
LPDWORD lpModifiedReturned;
__asm {
push ecx;
push edx;
push returnValue;
sub esp, dwMaxArgSize;
lea eax, [esp];
mov lpModifiedReturned, eax;
push dwMaxArgSize;
push lpStackTop;
push eax;
call my_memcpy;
add esp, 12;
mov eax, pf;
call eax;
push dwMaxArgSize;
push lpModifiedReturned;
push lpStackTop;
call my_memcpy;
add esp, 12;
add esp, dwMaxArgSize;
pop returnValue;
pop edx;
pop ecx
}
return returnValue;
}
//Error
return 0;
}
return 0;
}
void Injector::Run(LPVOID lpStackTop)
{
DWORD returnValue = 0;
for (auto&& f : info->injectedBefore)
{
f.Call(lpStackTop, &returnValue, info->dwMaxArgSize);
}
returnValue = info->replaced.Call(lpStackTop, &returnValue, info->dwMaxArgSize);
__asm {
mov returnValue, eax
}
{
for (auto&& f : info->injectedAfter)
{
returnValue = f.Call(lpStackTop, &returnValue, info->dwMaxArgSize);
}
}
__asm {
mov eax, returnValue
}
}