├── .gitattributes
├── .gitignore
├── LICENSE
├── Lua Executor.sln
├── Lua Executor
├── Lua Executor.vcxproj
├── Lua Executor.vcxproj.filters
├── Lua Executor.vcxproj.user
├── detours
│ └── detours.h
├── dllmain.cpp
├── framework.h
├── includes.h
└── shell.h
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Compiled Object files
5 | *.slo
6 | *.lo
7 | *.o
8 | *.obj
9 |
10 | # Precompiled Headers
11 | *.gch
12 | *.pch
13 |
14 | # Compiled Dynamic libraries
15 | *.so
16 | *.dylib
17 | *.dll
18 |
19 | # Fortran module files
20 | *.mod
21 | *.smod
22 |
23 | # Compiled Static libraries
24 | *.lai
25 | *.la
26 | *.a
27 | *.lib
28 |
29 | # Executables
30 | *.exe
31 | *.out
32 | *.app
33 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 H4xton
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Lua Executor.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.0.31606.5
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lua Executor", "Lua Executor\Lua Executor.vcxproj", "{5C9A6191-F7A9-44EC-9450-F0C4AA14D2EF}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|x64 = Debug|x64
11 | Debug|x86 = Debug|x86
12 | Release|x64 = Release|x64
13 | Release|x86 = Release|x86
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {5C9A6191-F7A9-44EC-9450-F0C4AA14D2EF}.Debug|x64.ActiveCfg = Debug|x64
17 | {5C9A6191-F7A9-44EC-9450-F0C4AA14D2EF}.Debug|x64.Build.0 = Debug|x64
18 | {5C9A6191-F7A9-44EC-9450-F0C4AA14D2EF}.Debug|x86.ActiveCfg = Debug|Win32
19 | {5C9A6191-F7A9-44EC-9450-F0C4AA14D2EF}.Debug|x86.Build.0 = Debug|Win32
20 | {5C9A6191-F7A9-44EC-9450-F0C4AA14D2EF}.Release|x64.ActiveCfg = Release|x64
21 | {5C9A6191-F7A9-44EC-9450-F0C4AA14D2EF}.Release|x64.Build.0 = Release|x64
22 | {5C9A6191-F7A9-44EC-9450-F0C4AA14D2EF}.Release|x86.ActiveCfg = Release|Win32
23 | {5C9A6191-F7A9-44EC-9450-F0C4AA14D2EF}.Release|x86.Build.0 = Release|Win32
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | GlobalSection(ExtensibilityGlobals) = postSolution
29 | SolutionGuid = {BC7835EB-B778-4B95-8059-B3D135BFA23E}
30 | EndGlobalSection
31 | EndGlobal
32 |
--------------------------------------------------------------------------------
/Lua Executor/Lua Executor.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 | 16.0
23 | Win32Proj
24 | {5c9a6191-f7a9-44ec-9450-f0c4aa14d2ef}
25 | LuaExecutor
26 | 10.0
27 |
28 |
29 |
30 | DynamicLibrary
31 | true
32 | v143
33 | Unicode
34 |
35 |
36 | DynamicLibrary
37 | false
38 | v143
39 | true
40 | Unicode
41 |
42 |
43 | DynamicLibrary
44 | true
45 | v143
46 | Unicode
47 |
48 |
49 | DynamicLibrary
50 | false
51 | v143
52 | true
53 | Unicode
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | true
75 |
76 |
77 | false
78 |
79 |
80 | true
81 |
82 |
83 | false
84 |
85 |
86 |
87 | Level3
88 | true
89 | WIN32;_DEBUG;LUAEXECUTOR_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)
90 | true
91 | Use
92 | pch.h
93 |
94 |
95 | Windows
96 | true
97 | false
98 |
99 |
100 |
101 |
102 | Level3
103 | true
104 | true
105 | true
106 | WIN32;NDEBUG;LUAEXECUTOR_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)
107 | true
108 | Use
109 | pch.h
110 |
111 |
112 | Windows
113 | true
114 | true
115 | true
116 | false
117 |
118 |
119 |
120 |
121 | Level3
122 | true
123 | _DEBUG;LUAEXECUTOR_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)
124 | true
125 | Use
126 | pch.h
127 |
128 |
129 | Windows
130 | true
131 | false
132 |
133 |
134 |
135 |
136 | Level3
137 | true
138 | true
139 | true
140 | NDEBUG;LUAEXECUTOR_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)
141 | true
142 | NotUsing
143 | pch.h
144 |
145 |
146 | Windows
147 | true
148 | true
149 | true
150 | false
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
--------------------------------------------------------------------------------
/Lua Executor/Lua Executor.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 | Header Files
29 |
30 |
31 |
32 |
33 | Source Files
34 |
35 |
36 |
--------------------------------------------------------------------------------
/Lua Executor/Lua Executor.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | true
5 |
6 |
--------------------------------------------------------------------------------
/Lua Executor/detours/detours.h:
--------------------------------------------------------------------------------
1 | /////////////////////////////////////////////////////////////////////////////
2 | //
3 | // Core Detours Functionality (detours.h of detours.lib)
4 | //
5 | // Microsoft Research Detours Package, Version 4.0.1
6 | //
7 | // Copyright (c) Microsoft Corporation. All rights reserved.
8 | //
9 |
10 | #pragma once
11 | #ifndef _DETOURS_H_
12 | #define _DETOURS_H_
13 |
14 | #define DETOURS_VERSION 0x4c0c1 // 0xMAJORcMINORcPATCH
15 |
16 | //////////////////////////////////////////////////////////////////////////////
17 | //
18 |
19 | #undef DETOURS_X64
20 | #undef DETOURS_X86
21 | #undef DETOURS_IA64
22 | #undef DETOURS_ARM
23 | #undef DETOURS_ARM64
24 | #undef DETOURS_BITS
25 | #undef DETOURS_32BIT
26 | #undef DETOURS_64BIT
27 |
28 | #if defined(_X86_)
29 | #define DETOURS_X86
30 | #define DETOURS_OPTION_BITS 64
31 |
32 | #elif defined(_AMD64_)
33 | #define DETOURS_X64
34 | #define DETOURS_OPTION_BITS 32
35 |
36 | #elif defined(_IA64_)
37 | #define DETOURS_IA64
38 | #define DETOURS_OPTION_BITS 32
39 |
40 | #elif defined(_ARM_)
41 | #define DETOURS_ARM
42 |
43 | #elif defined(_ARM64_)
44 | #define DETOURS_ARM64
45 |
46 | #else
47 | #error Unknown architecture (x86, amd64, ia64, arm, arm64)
48 | #endif
49 |
50 | #ifdef _WIN64
51 | #undef DETOURS_32BIT
52 | #define DETOURS_64BIT 1
53 | #define DETOURS_BITS 64
54 | // If all 64bit kernels can run one and only one 32bit architecture.
55 | //#define DETOURS_OPTION_BITS 32
56 | #else
57 | #define DETOURS_32BIT 1
58 | #undef DETOURS_64BIT
59 | #define DETOURS_BITS 32
60 | // If all 64bit kernels can run one and only one 32bit architecture.
61 | //#define DETOURS_OPTION_BITS 32
62 | #endif
63 |
64 | #define VER_DETOURS_BITS DETOUR_STRINGIFY(DETOURS_BITS)
65 |
66 | //////////////////////////////////////////////////////////////////////////////
67 | //
68 |
69 | #if (_MSC_VER < 1299)
70 | typedef LONG LONG_PTR;
71 | typedef ULONG ULONG_PTR;
72 | #endif
73 |
74 | ///////////////////////////////////////////////// SAL 2.0 Annotations w/o SAL.
75 | //
76 | // These definitions are include so that Detours will build even if the
77 | // compiler doesn't have full SAL 2.0 support.
78 | //
79 | #ifndef DETOURS_DONT_REMOVE_SAL_20
80 |
81 | #ifdef DETOURS_TEST_REMOVE_SAL_20
82 | #undef _Analysis_assume_
83 | #undef _Benign_race_begin_
84 | #undef _Benign_race_end_
85 | #undef _Field_range_
86 | #undef _Field_size_
87 | #undef _In_
88 | #undef _In_bytecount_
89 | #undef _In_count_
90 | #undef _In_opt_
91 | #undef _In_opt_bytecount_
92 | #undef _In_opt_count_
93 | #undef _In_opt_z_
94 | #undef _In_range_
95 | #undef _In_reads_
96 | #undef _In_reads_bytes_
97 | #undef _In_reads_opt_
98 | #undef _In_reads_opt_bytes_
99 | #undef _In_reads_or_z_
100 | #undef _In_z_
101 | #undef _Inout_
102 | #undef _Inout_opt_
103 | #undef _Inout_z_count_
104 | #undef _Out_
105 | #undef _Out_opt_
106 | #undef _Out_writes_
107 | #undef _Outptr_result_maybenull_
108 | #undef _Readable_bytes_
109 | #undef _Success_
110 | #undef _Writable_bytes_
111 | #undef _Pre_notnull_
112 | #endif
113 |
114 | #if defined(_Deref_out_opt_z_) && !defined(_Outptr_result_maybenull_)
115 | #define _Outptr_result_maybenull_ _Deref_out_opt_z_
116 | #endif
117 |
118 | #if defined(_In_count_) && !defined(_In_reads_)
119 | #define _In_reads_(x) _In_count_(x)
120 | #endif
121 |
122 | #if defined(_In_opt_count_) && !defined(_In_reads_opt_)
123 | #define _In_reads_opt_(x) _In_opt_count_(x)
124 | #endif
125 |
126 | #if defined(_In_opt_bytecount_) && !defined(_In_reads_opt_bytes_)
127 | #define _In_reads_opt_bytes_(x) _In_opt_bytecount_(x)
128 | #endif
129 |
130 | #if defined(_In_bytecount_) && !defined(_In_reads_bytes_)
131 | #define _In_reads_bytes_(x) _In_bytecount_(x)
132 | #endif
133 |
134 | #ifndef _In_
135 | #define _In_
136 | #endif
137 |
138 | #ifndef _In_bytecount_
139 | #define _In_bytecount_(x)
140 | #endif
141 |
142 | #ifndef _In_count_
143 | #define _In_count_(x)
144 | #endif
145 |
146 | #ifndef _In_opt_
147 | #define _In_opt_
148 | #endif
149 |
150 | #ifndef _In_opt_bytecount_
151 | #define _In_opt_bytecount_(x)
152 | #endif
153 |
154 | #ifndef _In_opt_count_
155 | #define _In_opt_count_(x)
156 | #endif
157 |
158 | #ifndef _In_opt_z_
159 | #define _In_opt_z_
160 | #endif
161 |
162 | #ifndef _In_range_
163 | #define _In_range_(x,y)
164 | #endif
165 |
166 | #ifndef _In_reads_
167 | #define _In_reads_(x)
168 | #endif
169 |
170 | #ifndef _In_reads_bytes_
171 | #define _In_reads_bytes_(x)
172 | #endif
173 |
174 | #ifndef _In_reads_opt_
175 | #define _In_reads_opt_(x)
176 | #endif
177 |
178 | #ifndef _In_reads_opt_bytes_
179 | #define _In_reads_opt_bytes_(x)
180 | #endif
181 |
182 | #ifndef _In_reads_or_z_
183 | #define _In_reads_or_z_
184 | #endif
185 |
186 | #ifndef _In_z_
187 | #define _In_z_
188 | #endif
189 |
190 | #ifndef _Inout_
191 | #define _Inout_
192 | #endif
193 |
194 | #ifndef _Inout_opt_
195 | #define _Inout_opt_
196 | #endif
197 |
198 | #ifndef _Inout_z_count_
199 | #define _Inout_z_count_(x)
200 | #endif
201 |
202 | #ifndef _Out_
203 | #define _Out_
204 | #endif
205 |
206 | #ifndef _Out_opt_
207 | #define _Out_opt_
208 | #endif
209 |
210 | #ifndef _Out_writes_
211 | #define _Out_writes_(x)
212 | #endif
213 |
214 | #ifndef _Outptr_result_maybenull_
215 | #define _Outptr_result_maybenull_
216 | #endif
217 |
218 | #ifndef _Writable_bytes_
219 | #define _Writable_bytes_(x)
220 | #endif
221 |
222 | #ifndef _Readable_bytes_
223 | #define _Readable_bytes_(x)
224 | #endif
225 |
226 | #ifndef _Success_
227 | #define _Success_(x)
228 | #endif
229 |
230 | #ifndef _Pre_notnull_
231 | #define _Pre_notnull_
232 | #endif
233 |
234 | #ifdef DETOURS_INTERNAL
235 |
236 | #pragma warning(disable:4615) // unknown warning type (suppress with older compilers)
237 |
238 | #ifndef _Benign_race_begin_
239 | #define _Benign_race_begin_
240 | #endif
241 |
242 | #ifndef _Benign_race_end_
243 | #define _Benign_race_end_
244 | #endif
245 |
246 | #ifndef _Field_size_
247 | #define _Field_size_(x)
248 | #endif
249 |
250 | #ifndef _Field_range_
251 | #define _Field_range_(x,y)
252 | #endif
253 |
254 | #ifndef _Analysis_assume_
255 | #define _Analysis_assume_(x)
256 | #endif
257 |
258 | #endif // DETOURS_INTERNAL
259 | #endif // DETOURS_DONT_REMOVE_SAL_20
260 |
261 | //////////////////////////////////////////////////////////////////////////////
262 | //
263 | #ifndef GUID_DEFINED
264 | #define GUID_DEFINED
265 | typedef struct _GUID
266 | {
267 | DWORD Data1;
268 | WORD Data2;
269 | WORD Data3;
270 | BYTE Data4[ 8 ];
271 | } GUID;
272 |
273 | #ifdef INITGUID
274 | #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
275 | const GUID name \
276 | = { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
277 | #else
278 | #define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
279 | const GUID name
280 | #endif // INITGUID
281 | #endif // !GUID_DEFINED
282 |
283 | #if defined(__cplusplus)
284 | #ifndef _REFGUID_DEFINED
285 | #define _REFGUID_DEFINED
286 | #define REFGUID const GUID &
287 | #endif // !_REFGUID_DEFINED
288 | #else // !__cplusplus
289 | #ifndef _REFGUID_DEFINED
290 | #define _REFGUID_DEFINED
291 | #define REFGUID const GUID * const
292 | #endif // !_REFGUID_DEFINED
293 | #endif // !__cplusplus
294 |
295 | #ifndef ARRAYSIZE
296 | #define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
297 | #endif
298 |
299 | //
300 | //////////////////////////////////////////////////////////////////////////////
301 |
302 | #ifdef __cplusplus
303 | extern "C" {
304 | #endif // __cplusplus
305 |
306 | /////////////////////////////////////////////////// Instruction Target Macros.
307 | //
308 | #define DETOUR_INSTRUCTION_TARGET_NONE ((PVOID)0)
309 | #define DETOUR_INSTRUCTION_TARGET_DYNAMIC ((PVOID)(LONG_PTR)-1)
310 | #define DETOUR_SECTION_HEADER_SIGNATURE 0x00727444 // "Dtr\0"
311 |
312 | extern const GUID DETOUR_EXE_RESTORE_GUID;
313 | extern const GUID DETOUR_EXE_HELPER_GUID;
314 |
315 | #define DETOUR_TRAMPOLINE_SIGNATURE 0x21727444 // Dtr!
316 | typedef struct _DETOUR_TRAMPOLINE DETOUR_TRAMPOLINE, *PDETOUR_TRAMPOLINE;
317 |
318 | /////////////////////////////////////////////////////////// Binary Structures.
319 | //
320 | #pragma pack(push, 8)
321 | typedef struct _DETOUR_SECTION_HEADER
322 | {
323 | DWORD cbHeaderSize;
324 | DWORD nSignature;
325 | DWORD nDataOffset;
326 | DWORD cbDataSize;
327 |
328 | DWORD nOriginalImportVirtualAddress;
329 | DWORD nOriginalImportSize;
330 | DWORD nOriginalBoundImportVirtualAddress;
331 | DWORD nOriginalBoundImportSize;
332 |
333 | DWORD nOriginalIatVirtualAddress;
334 | DWORD nOriginalIatSize;
335 | DWORD nOriginalSizeOfImage;
336 | DWORD cbPrePE;
337 |
338 | DWORD nOriginalClrFlags;
339 | DWORD reserved1;
340 | DWORD reserved2;
341 | DWORD reserved3;
342 |
343 | // Followed by cbPrePE bytes of data.
344 | } DETOUR_SECTION_HEADER, *PDETOUR_SECTION_HEADER;
345 |
346 | typedef struct _DETOUR_SECTION_RECORD
347 | {
348 | DWORD cbBytes;
349 | DWORD nReserved;
350 | GUID guid;
351 | } DETOUR_SECTION_RECORD, *PDETOUR_SECTION_RECORD;
352 |
353 | typedef struct _DETOUR_CLR_HEADER
354 | {
355 | // Header versioning
356 | ULONG cb;
357 | USHORT MajorRuntimeVersion;
358 | USHORT MinorRuntimeVersion;
359 |
360 | // Symbol table and startup information
361 | IMAGE_DATA_DIRECTORY MetaData;
362 | ULONG Flags;
363 |
364 | // Followed by the rest of the IMAGE_COR20_HEADER
365 | } DETOUR_CLR_HEADER, *PDETOUR_CLR_HEADER;
366 |
367 | typedef struct _DETOUR_EXE_RESTORE
368 | {
369 | DWORD cb;
370 | DWORD cbidh;
371 | DWORD cbinh;
372 | DWORD cbclr;
373 |
374 | PBYTE pidh;
375 | PBYTE pinh;
376 | PBYTE pclr;
377 |
378 | IMAGE_DOS_HEADER idh;
379 | union {
380 | IMAGE_NT_HEADERS inh; // all environments have this
381 | #ifdef IMAGE_NT_OPTIONAL_HDR32_MAGIC // some environments do not have this
382 | IMAGE_NT_HEADERS32 inh32;
383 | #endif
384 | #ifdef IMAGE_NT_OPTIONAL_HDR64_MAGIC // some environments do not have this
385 | IMAGE_NT_HEADERS64 inh64;
386 | #endif
387 | #ifdef IMAGE_NT_OPTIONAL_HDR64_MAGIC // some environments do not have this
388 | BYTE raw[sizeof(IMAGE_NT_HEADERS64) +
389 | sizeof(IMAGE_SECTION_HEADER) * 32];
390 | #else
391 | BYTE raw[0x108 + sizeof(IMAGE_SECTION_HEADER) * 32];
392 | #endif
393 | };
394 | DETOUR_CLR_HEADER clr;
395 |
396 | } DETOUR_EXE_RESTORE, *PDETOUR_EXE_RESTORE;
397 |
398 | #ifdef IMAGE_NT_OPTIONAL_HDR64_MAGIC
399 | C_ASSERT(sizeof(IMAGE_NT_HEADERS64) == 0x108);
400 | #endif
401 |
402 | // The size can change, but assert for clarity due to the muddying #ifdefs.
403 | #ifdef _WIN64
404 | C_ASSERT(sizeof(DETOUR_EXE_RESTORE) == 0x688);
405 | #else
406 | C_ASSERT(sizeof(DETOUR_EXE_RESTORE) == 0x678);
407 | #endif
408 |
409 | typedef struct _DETOUR_EXE_HELPER
410 | {
411 | DWORD cb;
412 | DWORD pid;
413 | DWORD nDlls;
414 | CHAR rDlls[4];
415 | } DETOUR_EXE_HELPER, *PDETOUR_EXE_HELPER;
416 |
417 | #pragma pack(pop)
418 |
419 | #define DETOUR_SECTION_HEADER_DECLARE(cbSectionSize) \
420 | { \
421 | sizeof(DETOUR_SECTION_HEADER),\
422 | DETOUR_SECTION_HEADER_SIGNATURE,\
423 | sizeof(DETOUR_SECTION_HEADER),\
424 | (cbSectionSize),\
425 | \
426 | 0,\
427 | 0,\
428 | 0,\
429 | 0,\
430 | \
431 | 0,\
432 | 0,\
433 | 0,\
434 | 0,\
435 | }
436 |
437 | /////////////////////////////////////////////////////////////// Helper Macros.
438 | //
439 | #define DETOURS_STRINGIFY(x) DETOURS_STRINGIFY_(x)
440 | #define DETOURS_STRINGIFY_(x) #x
441 |
442 | ///////////////////////////////////////////////////////////// Binary Typedefs.
443 | //
444 | typedef BOOL (CALLBACK *PF_DETOUR_BINARY_BYWAY_CALLBACK)(
445 | _In_opt_ PVOID pContext,
446 | _In_opt_ LPCSTR pszFile,
447 | _Outptr_result_maybenull_ LPCSTR *ppszOutFile);
448 |
449 | typedef BOOL (CALLBACK *PF_DETOUR_BINARY_FILE_CALLBACK)(
450 | _In_opt_ PVOID pContext,
451 | _In_ LPCSTR pszOrigFile,
452 | _In_ LPCSTR pszFile,
453 | _Outptr_result_maybenull_ LPCSTR *ppszOutFile);
454 |
455 | typedef BOOL (CALLBACK *PF_DETOUR_BINARY_SYMBOL_CALLBACK)(
456 | _In_opt_ PVOID pContext,
457 | _In_ ULONG nOrigOrdinal,
458 | _In_ ULONG nOrdinal,
459 | _Out_ ULONG *pnOutOrdinal,
460 | _In_opt_ LPCSTR pszOrigSymbol,
461 | _In_opt_ LPCSTR pszSymbol,
462 | _Outptr_result_maybenull_ LPCSTR *ppszOutSymbol);
463 |
464 | typedef BOOL (CALLBACK *PF_DETOUR_BINARY_COMMIT_CALLBACK)(
465 | _In_opt_ PVOID pContext);
466 |
467 | typedef BOOL (CALLBACK *PF_DETOUR_ENUMERATE_EXPORT_CALLBACK)(_In_opt_ PVOID pContext,
468 | _In_ ULONG nOrdinal,
469 | _In_opt_ LPCSTR pszName,
470 | _In_opt_ PVOID pCode);
471 |
472 | typedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FILE_CALLBACK)(_In_opt_ PVOID pContext,
473 | _In_opt_ HMODULE hModule,
474 | _In_opt_ LPCSTR pszFile);
475 |
476 | typedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FUNC_CALLBACK)(_In_opt_ PVOID pContext,
477 | _In_ DWORD nOrdinal,
478 | _In_opt_ LPCSTR pszFunc,
479 | _In_opt_ PVOID pvFunc);
480 |
481 | // Same as PF_DETOUR_IMPORT_FUNC_CALLBACK but extra indirection on last parameter.
482 | typedef BOOL (CALLBACK *PF_DETOUR_IMPORT_FUNC_CALLBACK_EX)(_In_opt_ PVOID pContext,
483 | _In_ DWORD nOrdinal,
484 | _In_opt_ LPCSTR pszFunc,
485 | _In_opt_ PVOID* ppvFunc);
486 |
487 | typedef VOID * PDETOUR_BINARY;
488 | typedef VOID * PDETOUR_LOADED_BINARY;
489 |
490 | //////////////////////////////////////////////////////////// Transaction APIs.
491 | //
492 | LONG WINAPI DetourTransactionBegin(VOID);
493 | LONG WINAPI DetourTransactionAbort(VOID);
494 | LONG WINAPI DetourTransactionCommit(VOID);
495 | LONG WINAPI DetourTransactionCommitEx(_Out_opt_ PVOID **pppFailedPointer);
496 |
497 | LONG WINAPI DetourUpdateThread(_In_ HANDLE hThread);
498 |
499 | LONG WINAPI DetourAttach(_Inout_ PVOID *ppPointer,
500 | _In_ PVOID pDetour);
501 |
502 | LONG WINAPI DetourAttachEx(_Inout_ PVOID *ppPointer,
503 | _In_ PVOID pDetour,
504 | _Out_opt_ PDETOUR_TRAMPOLINE *ppRealTrampoline,
505 | _Out_opt_ PVOID *ppRealTarget,
506 | _Out_opt_ PVOID *ppRealDetour);
507 |
508 | LONG WINAPI DetourDetach(_Inout_ PVOID *ppPointer,
509 | _In_ PVOID pDetour);
510 |
511 | BOOL WINAPI DetourSetIgnoreTooSmall(_In_ BOOL fIgnore);
512 | BOOL WINAPI DetourSetRetainRegions(_In_ BOOL fRetain);
513 | PVOID WINAPI DetourSetSystemRegionLowerBound(_In_ PVOID pSystemRegionLowerBound);
514 | PVOID WINAPI DetourSetSystemRegionUpperBound(_In_ PVOID pSystemRegionUpperBound);
515 |
516 | ////////////////////////////////////////////////////////////// Code Functions.
517 | //
518 | PVOID WINAPI DetourFindFunction(_In_ LPCSTR pszModule,
519 | _In_ LPCSTR pszFunction);
520 | PVOID WINAPI DetourCodeFromPointer(_In_ PVOID pPointer,
521 | _Out_opt_ PVOID *ppGlobals);
522 | PVOID WINAPI DetourCopyInstruction(_In_opt_ PVOID pDst,
523 | _Inout_opt_ PVOID *ppDstPool,
524 | _In_ PVOID pSrc,
525 | _Out_opt_ PVOID *ppTarget,
526 | _Out_opt_ LONG *plExtra);
527 | BOOL WINAPI DetourSetCodeModule(_In_ HMODULE hModule,
528 | _In_ BOOL fLimitReferencesToModule);
529 | PVOID WINAPI DetourAllocateRegionWithinJumpBounds(_In_ LPCVOID pbTarget,
530 | _Out_ PDWORD pcbAllocatedSize);
531 |
532 | ///////////////////////////////////////////////////// Loaded Binary Functions.
533 | //
534 | HMODULE WINAPI DetourGetContainingModule(_In_ PVOID pvAddr);
535 | HMODULE WINAPI DetourEnumerateModules(_In_opt_ HMODULE hModuleLast);
536 | PVOID WINAPI DetourGetEntryPoint(_In_opt_ HMODULE hModule);
537 | ULONG WINAPI DetourGetModuleSize(_In_opt_ HMODULE hModule);
538 | BOOL WINAPI DetourEnumerateExports(_In_ HMODULE hModule,
539 | _In_opt_ PVOID pContext,
540 | _In_ PF_DETOUR_ENUMERATE_EXPORT_CALLBACK pfExport);
541 | BOOL WINAPI DetourEnumerateImports(_In_opt_ HMODULE hModule,
542 | _In_opt_ PVOID pContext,
543 | _In_opt_ PF_DETOUR_IMPORT_FILE_CALLBACK pfImportFile,
544 | _In_opt_ PF_DETOUR_IMPORT_FUNC_CALLBACK pfImportFunc);
545 |
546 | BOOL WINAPI DetourEnumerateImportsEx(_In_opt_ HMODULE hModule,
547 | _In_opt_ PVOID pContext,
548 | _In_opt_ PF_DETOUR_IMPORT_FILE_CALLBACK pfImportFile,
549 | _In_opt_ PF_DETOUR_IMPORT_FUNC_CALLBACK_EX pfImportFuncEx);
550 |
551 | _Writable_bytes_(*pcbData)
552 | _Readable_bytes_(*pcbData)
553 | _Success_(return != NULL)
554 | PVOID WINAPI DetourFindPayload(_In_opt_ HMODULE hModule,
555 | _In_ REFGUID rguid,
556 | _Out_ DWORD *pcbData);
557 |
558 | _Writable_bytes_(*pcbData)
559 | _Readable_bytes_(*pcbData)
560 | _Success_(return != NULL)
561 | PVOID WINAPI DetourFindPayloadEx(_In_ REFGUID rguid,
562 | _Out_ DWORD * pcbData);
563 |
564 | DWORD WINAPI DetourGetSizeOfPayloads(_In_opt_ HMODULE hModule);
565 |
566 | ///////////////////////////////////////////////// Persistent Binary Functions.
567 | //
568 |
569 | PDETOUR_BINARY WINAPI DetourBinaryOpen(_In_ HANDLE hFile);
570 |
571 | _Writable_bytes_(*pcbData)
572 | _Readable_bytes_(*pcbData)
573 | _Success_(return != NULL)
574 | PVOID WINAPI DetourBinaryEnumeratePayloads(_In_ PDETOUR_BINARY pBinary,
575 | _Out_opt_ GUID *pGuid,
576 | _Out_ DWORD *pcbData,
577 | _Inout_ DWORD *pnIterator);
578 |
579 | _Writable_bytes_(*pcbData)
580 | _Readable_bytes_(*pcbData)
581 | _Success_(return != NULL)
582 | PVOID WINAPI DetourBinaryFindPayload(_In_ PDETOUR_BINARY pBinary,
583 | _In_ REFGUID rguid,
584 | _Out_ DWORD *pcbData);
585 |
586 | PVOID WINAPI DetourBinarySetPayload(_In_ PDETOUR_BINARY pBinary,
587 | _In_ REFGUID rguid,
588 | _In_reads_opt_(cbData) PVOID pData,
589 | _In_ DWORD cbData);
590 | BOOL WINAPI DetourBinaryDeletePayload(_In_ PDETOUR_BINARY pBinary, _In_ REFGUID rguid);
591 | BOOL WINAPI DetourBinaryPurgePayloads(_In_ PDETOUR_BINARY pBinary);
592 | BOOL WINAPI DetourBinaryResetImports(_In_ PDETOUR_BINARY pBinary);
593 | BOOL WINAPI DetourBinaryEditImports(_In_ PDETOUR_BINARY pBinary,
594 | _In_opt_ PVOID pContext,
595 | _In_opt_ PF_DETOUR_BINARY_BYWAY_CALLBACK pfByway,
596 | _In_opt_ PF_DETOUR_BINARY_FILE_CALLBACK pfFile,
597 | _In_opt_ PF_DETOUR_BINARY_SYMBOL_CALLBACK pfSymbol,
598 | _In_opt_ PF_DETOUR_BINARY_COMMIT_CALLBACK pfCommit);
599 | BOOL WINAPI DetourBinaryWrite(_In_ PDETOUR_BINARY pBinary, _In_ HANDLE hFile);
600 | BOOL WINAPI DetourBinaryClose(_In_ PDETOUR_BINARY pBinary);
601 |
602 | /////////////////////////////////////////////////// Create Process & Load Dll.
603 | //
604 | typedef BOOL (WINAPI *PDETOUR_CREATE_PROCESS_ROUTINEA)(
605 | _In_opt_ LPCSTR lpApplicationName,
606 | _Inout_opt_ LPSTR lpCommandLine,
607 | _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
608 | _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
609 | _In_ BOOL bInheritHandles,
610 | _In_ DWORD dwCreationFlags,
611 | _In_opt_ LPVOID lpEnvironment,
612 | _In_opt_ LPCSTR lpCurrentDirectory,
613 | _In_ LPSTARTUPINFOA lpStartupInfo,
614 | _Out_ LPPROCESS_INFORMATION lpProcessInformation);
615 |
616 | typedef BOOL (WINAPI *PDETOUR_CREATE_PROCESS_ROUTINEW)(
617 | _In_opt_ LPCWSTR lpApplicationName,
618 | _Inout_opt_ LPWSTR lpCommandLine,
619 | _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
620 | _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
621 | _In_ BOOL bInheritHandles,
622 | _In_ DWORD dwCreationFlags,
623 | _In_opt_ LPVOID lpEnvironment,
624 | _In_opt_ LPCWSTR lpCurrentDirectory,
625 | _In_ LPSTARTUPINFOW lpStartupInfo,
626 | _Out_ LPPROCESS_INFORMATION lpProcessInformation);
627 |
628 | BOOL WINAPI DetourCreateProcessWithDllA(_In_opt_ LPCSTR lpApplicationName,
629 | _Inout_opt_ LPSTR lpCommandLine,
630 | _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
631 | _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
632 | _In_ BOOL bInheritHandles,
633 | _In_ DWORD dwCreationFlags,
634 | _In_opt_ LPVOID lpEnvironment,
635 | _In_opt_ LPCSTR lpCurrentDirectory,
636 | _In_ LPSTARTUPINFOA lpStartupInfo,
637 | _Out_ LPPROCESS_INFORMATION lpProcessInformation,
638 | _In_ LPCSTR lpDllName,
639 | _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA);
640 |
641 | BOOL WINAPI DetourCreateProcessWithDllW(_In_opt_ LPCWSTR lpApplicationName,
642 | _Inout_opt_ LPWSTR lpCommandLine,
643 | _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
644 | _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
645 | _In_ BOOL bInheritHandles,
646 | _In_ DWORD dwCreationFlags,
647 | _In_opt_ LPVOID lpEnvironment,
648 | _In_opt_ LPCWSTR lpCurrentDirectory,
649 | _In_ LPSTARTUPINFOW lpStartupInfo,
650 | _Out_ LPPROCESS_INFORMATION lpProcessInformation,
651 | _In_ LPCSTR lpDllName,
652 | _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW);
653 |
654 | #ifdef UNICODE
655 | #define DetourCreateProcessWithDll DetourCreateProcessWithDllW
656 | #define PDETOUR_CREATE_PROCESS_ROUTINE PDETOUR_CREATE_PROCESS_ROUTINEW
657 | #else
658 | #define DetourCreateProcessWithDll DetourCreateProcessWithDllA
659 | #define PDETOUR_CREATE_PROCESS_ROUTINE PDETOUR_CREATE_PROCESS_ROUTINEA
660 | #endif // !UNICODE
661 |
662 | BOOL WINAPI DetourCreateProcessWithDllExA(_In_opt_ LPCSTR lpApplicationName,
663 | _Inout_opt_ LPSTR lpCommandLine,
664 | _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
665 | _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
666 | _In_ BOOL bInheritHandles,
667 | _In_ DWORD dwCreationFlags,
668 | _In_opt_ LPVOID lpEnvironment,
669 | _In_opt_ LPCSTR lpCurrentDirectory,
670 | _In_ LPSTARTUPINFOA lpStartupInfo,
671 | _Out_ LPPROCESS_INFORMATION lpProcessInformation,
672 | _In_ LPCSTR lpDllName,
673 | _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA);
674 |
675 | BOOL WINAPI DetourCreateProcessWithDllExW(_In_opt_ LPCWSTR lpApplicationName,
676 | _Inout_opt_ LPWSTR lpCommandLine,
677 | _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
678 | _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
679 | _In_ BOOL bInheritHandles,
680 | _In_ DWORD dwCreationFlags,
681 | _In_opt_ LPVOID lpEnvironment,
682 | _In_opt_ LPCWSTR lpCurrentDirectory,
683 | _In_ LPSTARTUPINFOW lpStartupInfo,
684 | _Out_ LPPROCESS_INFORMATION lpProcessInformation,
685 | _In_ LPCSTR lpDllName,
686 | _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW);
687 |
688 | #ifdef UNICODE
689 | #define DetourCreateProcessWithDllEx DetourCreateProcessWithDllExW
690 | #else
691 | #define DetourCreateProcessWithDllEx DetourCreateProcessWithDllExA
692 | #endif // !UNICODE
693 |
694 | BOOL WINAPI DetourCreateProcessWithDllsA(_In_opt_ LPCSTR lpApplicationName,
695 | _Inout_opt_ LPSTR lpCommandLine,
696 | _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
697 | _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
698 | _In_ BOOL bInheritHandles,
699 | _In_ DWORD dwCreationFlags,
700 | _In_opt_ LPVOID lpEnvironment,
701 | _In_opt_ LPCSTR lpCurrentDirectory,
702 | _In_ LPSTARTUPINFOA lpStartupInfo,
703 | _Out_ LPPROCESS_INFORMATION lpProcessInformation,
704 | _In_ DWORD nDlls,
705 | _In_reads_(nDlls) LPCSTR *rlpDlls,
706 | _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA);
707 |
708 | BOOL WINAPI DetourCreateProcessWithDllsW(_In_opt_ LPCWSTR lpApplicationName,
709 | _Inout_opt_ LPWSTR lpCommandLine,
710 | _In_opt_ LPSECURITY_ATTRIBUTES lpProcessAttributes,
711 | _In_opt_ LPSECURITY_ATTRIBUTES lpThreadAttributes,
712 | _In_ BOOL bInheritHandles,
713 | _In_ DWORD dwCreationFlags,
714 | _In_opt_ LPVOID lpEnvironment,
715 | _In_opt_ LPCWSTR lpCurrentDirectory,
716 | _In_ LPSTARTUPINFOW lpStartupInfo,
717 | _Out_ LPPROCESS_INFORMATION lpProcessInformation,
718 | _In_ DWORD nDlls,
719 | _In_reads_(nDlls) LPCSTR *rlpDlls,
720 | _In_opt_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW);
721 |
722 | #ifdef UNICODE
723 | #define DetourCreateProcessWithDlls DetourCreateProcessWithDllsW
724 | #else
725 | #define DetourCreateProcessWithDlls DetourCreateProcessWithDllsA
726 | #endif // !UNICODE
727 |
728 | BOOL WINAPI DetourProcessViaHelperA(_In_ DWORD dwTargetPid,
729 | _In_ LPCSTR lpDllName,
730 | _In_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA);
731 |
732 | BOOL WINAPI DetourProcessViaHelperW(_In_ DWORD dwTargetPid,
733 | _In_ LPCSTR lpDllName,
734 | _In_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW);
735 |
736 | #ifdef UNICODE
737 | #define DetourProcessViaHelper DetourProcessViaHelperW
738 | #else
739 | #define DetourProcessViaHelper DetourProcessViaHelperA
740 | #endif // !UNICODE
741 |
742 | BOOL WINAPI DetourProcessViaHelperDllsA(_In_ DWORD dwTargetPid,
743 | _In_ DWORD nDlls,
744 | _In_reads_(nDlls) LPCSTR *rlpDlls,
745 | _In_ PDETOUR_CREATE_PROCESS_ROUTINEA pfCreateProcessA);
746 |
747 | BOOL WINAPI DetourProcessViaHelperDllsW(_In_ DWORD dwTargetPid,
748 | _In_ DWORD nDlls,
749 | _In_reads_(nDlls) LPCSTR *rlpDlls,
750 | _In_ PDETOUR_CREATE_PROCESS_ROUTINEW pfCreateProcessW);
751 |
752 | #ifdef UNICODE
753 | #define DetourProcessViaHelperDlls DetourProcessViaHelperDllsW
754 | #else
755 | #define DetourProcessViaHelperDlls DetourProcessViaHelperDllsA
756 | #endif // !UNICODE
757 |
758 | BOOL WINAPI DetourUpdateProcessWithDll(_In_ HANDLE hProcess,
759 | _In_reads_(nDlls) LPCSTR *rlpDlls,
760 | _In_ DWORD nDlls);
761 |
762 | BOOL WINAPI DetourUpdateProcessWithDllEx(_In_ HANDLE hProcess,
763 | _In_ HMODULE hImage,
764 | _In_ BOOL bIs32Bit,
765 | _In_reads_(nDlls) LPCSTR *rlpDlls,
766 | _In_ DWORD nDlls);
767 |
768 | BOOL WINAPI DetourCopyPayloadToProcess(_In_ HANDLE hProcess,
769 | _In_ REFGUID rguid,
770 | _In_reads_bytes_(cbData) PVOID pvData,
771 | _In_ DWORD cbData);
772 | BOOL WINAPI DetourRestoreAfterWith(VOID);
773 | BOOL WINAPI DetourRestoreAfterWithEx(_In_reads_bytes_(cbData) PVOID pvData,
774 | _In_ DWORD cbData);
775 | BOOL WINAPI DetourIsHelperProcess(VOID);
776 | VOID CALLBACK DetourFinishHelperProcess(_In_ HWND,
777 | _In_ HINSTANCE,
778 | _In_ LPSTR,
779 | _In_ INT);
780 |
781 | //
782 | //////////////////////////////////////////////////////////////////////////////
783 | #ifdef __cplusplus
784 | }
785 | #endif // __cplusplus
786 |
787 | //////////////////////////////////////////////// Detours Internal Definitions.
788 | //
789 | #ifdef __cplusplus
790 | #ifdef DETOURS_INTERNAL
791 |
792 | #define NOTHROW
793 | // #define NOTHROW (nothrow)
794 |
795 | //////////////////////////////////////////////////////////////////////////////
796 | //
797 | #if (_MSC_VER < 1299)
798 | #include
799 | typedef IMAGEHLP_MODULE IMAGEHLP_MODULE64;
800 | typedef PIMAGEHLP_MODULE PIMAGEHLP_MODULE64;
801 | typedef IMAGEHLP_SYMBOL SYMBOL_INFO;
802 | typedef PIMAGEHLP_SYMBOL PSYMBOL_INFO;
803 |
804 | static inline
805 | LONG InterlockedCompareExchange(_Inout_ LONG *ptr, _In_ LONG nval, _In_ LONG oval)
806 | {
807 | return (LONG)::InterlockedCompareExchange((PVOID*)ptr, (PVOID)nval, (PVOID)oval);
808 | }
809 | #else
810 | #pragma warning(push)
811 | #pragma warning(disable:4091) // empty typedef
812 | #include
813 | #pragma warning(pop)
814 | #endif
815 |
816 | #ifdef IMAGEAPI // defined by DBGHELP.H
817 | typedef LPAPI_VERSION (NTAPI *PF_ImagehlpApiVersionEx)(_In_ LPAPI_VERSION AppVersion);
818 |
819 | typedef BOOL (NTAPI *PF_SymInitialize)(_In_ HANDLE hProcess,
820 | _In_opt_ LPCSTR UserSearchPath,
821 | _In_ BOOL fInvadeProcess);
822 | typedef DWORD (NTAPI *PF_SymSetOptions)(_In_ DWORD SymOptions);
823 | typedef DWORD (NTAPI *PF_SymGetOptions)(VOID);
824 | typedef DWORD64 (NTAPI *PF_SymLoadModule64)(_In_ HANDLE hProcess,
825 | _In_opt_ HANDLE hFile,
826 | _In_ LPSTR ImageName,
827 | _In_opt_ LPSTR ModuleName,
828 | _In_ DWORD64 BaseOfDll,
829 | _In_opt_ DWORD SizeOfDll);
830 | typedef BOOL (NTAPI *PF_SymGetModuleInfo64)(_In_ HANDLE hProcess,
831 | _In_ DWORD64 qwAddr,
832 | _Out_ PIMAGEHLP_MODULE64 ModuleInfo);
833 | typedef BOOL (NTAPI *PF_SymFromName)(_In_ HANDLE hProcess,
834 | _In_ LPSTR Name,
835 | _Out_ PSYMBOL_INFO Symbol);
836 |
837 | typedef struct _DETOUR_SYM_INFO
838 | {
839 | HANDLE hProcess;
840 | HMODULE hDbgHelp;
841 | PF_ImagehlpApiVersionEx pfImagehlpApiVersionEx;
842 | PF_SymInitialize pfSymInitialize;
843 | PF_SymSetOptions pfSymSetOptions;
844 | PF_SymGetOptions pfSymGetOptions;
845 | PF_SymLoadModule64 pfSymLoadModule64;
846 | PF_SymGetModuleInfo64 pfSymGetModuleInfo64;
847 | PF_SymFromName pfSymFromName;
848 | } DETOUR_SYM_INFO, *PDETOUR_SYM_INFO;
849 |
850 | PDETOUR_SYM_INFO DetourLoadImageHlp(VOID);
851 |
852 | #endif // IMAGEAPI
853 |
854 | #if defined(_INC_STDIO) && !defined(_CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS)
855 | #error detours.h must be included before stdio.h (or at least define _CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS earlier)
856 | #endif
857 | #define _CRT_STDIO_ARBITRARY_WIDE_SPECIFIERS 1
858 |
859 | #ifndef DETOUR_TRACE
860 | #if DETOUR_DEBUG
861 | #define DETOUR_TRACE(x) printf x
862 | #define DETOUR_BREAK() __debugbreak()
863 | #include
864 | #include
865 | #else
866 | #define DETOUR_TRACE(x)
867 | #define DETOUR_BREAK()
868 | #endif
869 | #endif
870 |
871 | #if 1 || defined(DETOURS_IA64)
872 |
873 | //
874 | // IA64 instructions are 41 bits, 3 per bundle, plus 5 bit bundle template => 128 bits per bundle.
875 | //
876 |
877 | #define DETOUR_IA64_INSTRUCTIONS_PER_BUNDLE (3)
878 |
879 | #define DETOUR_IA64_TEMPLATE_OFFSET (0)
880 | #define DETOUR_IA64_TEMPLATE_SIZE (5)
881 |
882 | #define DETOUR_IA64_INSTRUCTION_SIZE (41)
883 | #define DETOUR_IA64_INSTRUCTION0_OFFSET (DETOUR_IA64_TEMPLATE_SIZE)
884 | #define DETOUR_IA64_INSTRUCTION1_OFFSET (DETOUR_IA64_TEMPLATE_SIZE + DETOUR_IA64_INSTRUCTION_SIZE)
885 | #define DETOUR_IA64_INSTRUCTION2_OFFSET (DETOUR_IA64_TEMPLATE_SIZE + DETOUR_IA64_INSTRUCTION_SIZE + DETOUR_IA64_INSTRUCTION_SIZE)
886 |
887 | C_ASSERT(DETOUR_IA64_TEMPLATE_SIZE + DETOUR_IA64_INSTRUCTIONS_PER_BUNDLE * DETOUR_IA64_INSTRUCTION_SIZE == 128);
888 |
889 | __declspec(align(16)) struct DETOUR_IA64_BUNDLE
890 | {
891 | public:
892 | union
893 | {
894 | BYTE data[16];
895 | UINT64 wide[2];
896 | };
897 |
898 | enum {
899 | A_UNIT = 1u,
900 | I_UNIT = 2u,
901 | M_UNIT = 3u,
902 | B_UNIT = 4u,
903 | F_UNIT = 5u,
904 | L_UNIT = 6u,
905 | X_UNIT = 7u,
906 | };
907 | struct DETOUR_IA64_METADATA
908 | {
909 | ULONG nTemplate : 8; // Instruction template.
910 | ULONG nUnit0 : 4; // Unit for slot 0
911 | ULONG nUnit1 : 4; // Unit for slot 1
912 | ULONG nUnit2 : 4; // Unit for slot 2
913 | };
914 |
915 | protected:
916 | static const DETOUR_IA64_METADATA s_rceCopyTable[33];
917 |
918 | UINT RelocateBundle(_Inout_ DETOUR_IA64_BUNDLE* pDst, _Inout_opt_ DETOUR_IA64_BUNDLE* pBundleExtra) const;
919 |
920 | bool RelocateInstruction(_Inout_ DETOUR_IA64_BUNDLE* pDst,
921 | _In_ BYTE slot,
922 | _Inout_opt_ DETOUR_IA64_BUNDLE* pBundleExtra) const;
923 |
924 | // 120 112 104 96 88 80 72 64 56 48 40 32 24 16 8 0
925 | // f. e. d. c. b. a. 9. 8. 7. 6. 5. 4. 3. 2. 1. 0.
926 |
927 | // 00
928 | // f.e. d.c. b.a. 9.8. 7.6. 5.4. 3.2. 1.0.
929 | // 0000 0000 0000 0000 0000 0000 0000 001f : Template [4..0]
930 | // 0000 0000 0000 0000 0000 03ff ffff ffe0 : Zero [ 41.. 5]
931 | // 0000 0000 0000 0000 0000 3c00 0000 0000 : Zero [ 45.. 42]
932 | // 0000 0000 0007 ffff ffff c000 0000 0000 : One [ 82.. 46]
933 | // 0000 0000 0078 0000 0000 0000 0000 0000 : One [ 86.. 83]
934 | // 0fff ffff ff80 0000 0000 0000 0000 0000 : Two [123.. 87]
935 | // f000 0000 0000 0000 0000 0000 0000 0000 : Two [127..124]
936 | BYTE GetTemplate() const;
937 | // Get 4 bit opcodes.
938 | BYTE GetInst0() const;
939 | BYTE GetInst1() const;
940 | BYTE GetInst2() const;
941 | BYTE GetUnit(BYTE slot) const;
942 | BYTE GetUnit0() const;
943 | BYTE GetUnit1() const;
944 | BYTE GetUnit2() const;
945 | // Get 37 bit data.
946 | UINT64 GetData0() const;
947 | UINT64 GetData1() const;
948 | UINT64 GetData2() const;
949 |
950 | // Get/set the full 41 bit instructions.
951 | UINT64 GetInstruction(BYTE slot) const;
952 | UINT64 GetInstruction0() const;
953 | UINT64 GetInstruction1() const;
954 | UINT64 GetInstruction2() const;
955 | void SetInstruction(BYTE slot, UINT64 instruction);
956 | void SetInstruction0(UINT64 instruction);
957 | void SetInstruction1(UINT64 instruction);
958 | void SetInstruction2(UINT64 instruction);
959 |
960 | // Get/set bitfields.
961 | static UINT64 GetBits(UINT64 Value, UINT64 Offset, UINT64 Count);
962 | static UINT64 SetBits(UINT64 Value, UINT64 Offset, UINT64 Count, UINT64 Field);
963 |
964 | // Get specific read-only fields.
965 | static UINT64 GetOpcode(UINT64 instruction); // 4bit opcode
966 | static UINT64 GetX(UINT64 instruction); // 1bit opcode extension
967 | static UINT64 GetX3(UINT64 instruction); // 3bit opcode extension
968 | static UINT64 GetX6(UINT64 instruction); // 6bit opcode extension
969 |
970 | // Get/set specific fields.
971 | static UINT64 GetImm7a(UINT64 instruction);
972 | static UINT64 SetImm7a(UINT64 instruction, UINT64 imm7a);
973 | static UINT64 GetImm13c(UINT64 instruction);
974 | static UINT64 SetImm13c(UINT64 instruction, UINT64 imm13c);
975 | static UINT64 GetSignBit(UINT64 instruction);
976 | static UINT64 SetSignBit(UINT64 instruction, UINT64 signBit);
977 | static UINT64 GetImm20a(UINT64 instruction);
978 | static UINT64 SetImm20a(UINT64 instruction, UINT64 imm20a);
979 | static UINT64 GetImm20b(UINT64 instruction);
980 | static UINT64 SetImm20b(UINT64 instruction, UINT64 imm20b);
981 |
982 | static UINT64 SignExtend(UINT64 Value, UINT64 Offset);
983 |
984 | BOOL IsMovlGp() const;
985 |
986 | VOID SetInst(BYTE Slot, BYTE nInst);
987 | VOID SetInst0(BYTE nInst);
988 | VOID SetInst1(BYTE nInst);
989 | VOID SetInst2(BYTE nInst);
990 | VOID SetData(BYTE Slot, UINT64 nData);
991 | VOID SetData0(UINT64 nData);
992 | VOID SetData1(UINT64 nData);
993 | VOID SetData2(UINT64 nData);
994 | BOOL SetNop(BYTE Slot);
995 | BOOL SetNop0();
996 | BOOL SetNop1();
997 | BOOL SetNop2();
998 |
999 | public:
1000 | BOOL IsBrl() const;
1001 | VOID SetBrl();
1002 | VOID SetBrl(UINT64 target);
1003 | UINT64 GetBrlTarget() const;
1004 | VOID SetBrlTarget(UINT64 target);
1005 | VOID SetBrlImm(UINT64 imm);
1006 | UINT64 GetBrlImm() const;
1007 |
1008 | UINT64 GetMovlGp() const;
1009 | VOID SetMovlGp(UINT64 gp);
1010 |
1011 | VOID SetStop();
1012 |
1013 | UINT Copy(_Out_ DETOUR_IA64_BUNDLE *pDst, _Inout_opt_ DETOUR_IA64_BUNDLE* pBundleExtra = NULL) const;
1014 | };
1015 | #endif // DETOURS_IA64
1016 |
1017 | #ifdef DETOURS_ARM
1018 |
1019 | #define DETOURS_PFUNC_TO_PBYTE(p) ((PBYTE)(((ULONG_PTR)(p)) & ~(ULONG_PTR)1))
1020 | #define DETOURS_PBYTE_TO_PFUNC(p) ((PBYTE)(((ULONG_PTR)(p)) | (ULONG_PTR)1))
1021 |
1022 | #endif // DETOURS_ARM
1023 |
1024 | //////////////////////////////////////////////////////////////////////////////
1025 |
1026 | #ifdef __cplusplus
1027 | extern "C" {
1028 | #endif // __cplusplus
1029 |
1030 | #define DETOUR_OFFLINE_LIBRARY(x) \
1031 | PVOID WINAPI DetourCopyInstruction##x(_In_opt_ PVOID pDst, \
1032 | _Inout_opt_ PVOID *ppDstPool, \
1033 | _In_ PVOID pSrc, \
1034 | _Out_opt_ PVOID *ppTarget, \
1035 | _Out_opt_ LONG *plExtra); \
1036 | \
1037 | BOOL WINAPI DetourSetCodeModule##x(_In_ HMODULE hModule, \
1038 | _In_ BOOL fLimitReferencesToModule); \
1039 |
1040 | DETOUR_OFFLINE_LIBRARY(X86)
1041 | DETOUR_OFFLINE_LIBRARY(X64)
1042 | DETOUR_OFFLINE_LIBRARY(ARM)
1043 | DETOUR_OFFLINE_LIBRARY(ARM64)
1044 | DETOUR_OFFLINE_LIBRARY(IA64)
1045 |
1046 | #undef DETOUR_OFFLINE_LIBRARY
1047 |
1048 | //////////////////////////////////////////////////////////////////////////////
1049 | //
1050 | // Helpers for manipulating page protection.
1051 | //
1052 |
1053 | _Success_(return != FALSE)
1054 | BOOL WINAPI DetourVirtualProtectSameExecuteEx(_In_ HANDLE hProcess,
1055 | _In_ PVOID pAddress,
1056 | _In_ SIZE_T nSize,
1057 | _In_ DWORD dwNewProtect,
1058 | _Out_ PDWORD pdwOldProtect);
1059 |
1060 | _Success_(return != FALSE)
1061 | BOOL WINAPI DetourVirtualProtectSameExecute(_In_ PVOID pAddress,
1062 | _In_ SIZE_T nSize,
1063 | _In_ DWORD dwNewProtect,
1064 | _Out_ PDWORD pdwOldProtect);
1065 | #ifdef __cplusplus
1066 | }
1067 | #endif // __cplusplus
1068 |
1069 | //////////////////////////////////////////////////////////////////////////////
1070 |
1071 | #define MM_ALLOCATION_GRANULARITY 0x10000
1072 |
1073 | //////////////////////////////////////////////////////////////////////////////
1074 |
1075 | #endif // DETOURS_INTERNAL
1076 | #endif // __cplusplus
1077 |
1078 | #endif // _DETOURS_H_
1079 | //
1080 | //////////////////////////////////////////////////////////////// End of File.
1081 |
--------------------------------------------------------------------------------
/Lua Executor/dllmain.cpp:
--------------------------------------------------------------------------------
1 | #include "includes.h"
2 | #include "shell.h"
3 |
4 | std::ofstream stream;
5 | typedef __int64(__fastcall* t_28B30)(__int64 a1, const std::string& scriptpath, __int64 a3);
6 | t_28B30 hook_28B30 = (t_28B30)((uintptr_t)GetModuleHandle(L"citizen-scripting-lua.dll") + 0x28B30);
7 | __int64 __fastcall sub_28B30(__int64 a1, const std::string& scriptpath, __int64 a3) {
8 |
9 |
10 | if (scriptpath == "citizen:/scripting/lua/scheduler.lua")
11 | {
12 |
13 | return hook_28B30(a1, path.c_str(), a3);
14 | }
15 | return hook_28B30(a1, scriptpath, a3);
16 | }
17 | DWORD WINAPI whoops(HMODULE hModule)
18 | {
19 | stream.open(path.c_str());
20 | string Schedcode(reinterpret_cast(scheduler), sizeof(scheduler));
21 | stream << Schedcode << endl;
22 | stream << "print('Working Executor :)')" << endl;
23 | DetourTransactionBegin();
24 | DetourUpdateThread(GetCurrentThread());
25 | DetourAttach(&(LPVOID&)hook_28B30, &sub_28B30);
26 | DetourTransactionCommit();
27 | return true;
28 | }
29 |
30 |
31 |
32 |
33 | BOOL APIENTRY DllMain( HMODULE hModule,
34 | DWORD ul_reason_for_call,
35 | LPVOID lpReserved
36 | )
37 | {
38 | switch (ul_reason_for_call)
39 | {
40 | case DLL_PROCESS_ATTACH:
41 | CloseHandle(CreateThread(nullptr, 0, (LPTHREAD_START_ROUTINE)whoops, hModule, 0, nullptr));
42 | case DLL_THREAD_ATTACH:
43 | case DLL_THREAD_DETACH:
44 | case DLL_PROCESS_DETACH:
45 | break;
46 | }
47 | return TRUE;
48 | }
49 |
50 |
--------------------------------------------------------------------------------
/Lua Executor/framework.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
4 | // Windows Header Files
5 | #include
6 |
--------------------------------------------------------------------------------
/Lua Executor/includes.h:
--------------------------------------------------------------------------------
1 | #include
2 | #include "windows.h"
3 | #include
4 | #include #define WIN32_LEAN_AND_MEAN // Escludere gli elementi usati raramente dalle intestazioni di Windows
5 | // File di intestazione di Windows
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include "detours/detours.h"
13 | #pragma comment(lib, "detours/detours.lib")
14 | std::string path = "C:\\sex.lua";
15 | std::ofstream hackit;
16 |
17 |
18 |
19 |
20 | using namespace std;
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # FiveM Lua Executor
2 | This is prettymuch the scheduler method just a fix :))
3 |
--------------------------------------------------------------------------------