|
14 | 14 | #include "utils/Utils.h"
|
15 | 15 |
|
16 | 16 | #include <Python.h>
|
17 |
| -#include <detours.h> |
18 | 17 | #include <engine/TimeTaskSystem.h>
|
19 | 18 | #include <filesystem>
|
20 | 19 | #include <toml.h>
|
@@ -267,51 +266,52 @@ int executePipCommand(std::string cmd) {
|
267 | 266 | //
|
268 | 267 | // Attention! When CPython is upgraded, this fix must be re-adapted or removed!!
|
269 | 268 | //
|
270 |
| -namespace FixPython310Stdin { |
271 |
| -// Hard coded function address |
272 |
| -const uintptr_t create_stdio_func_base_offset = 0xCE0F4; |
273 |
| - |
274 |
| -create_stdio_func_type create_stdio_original = nullptr; |
275 |
| - |
276 |
| -PyObject* create_stdio_hooked( |
277 |
| - const PyConfig* config, |
278 |
| - PyObject* io, |
279 |
| - int fd, |
280 |
| - int write_mode, |
281 |
| - const char* name, |
282 |
| - const wchar_t* encoding, |
283 |
| - const wchar_t* errors |
284 |
| -) { |
285 |
| - if (fd == 0) { |
286 |
| - Py_RETURN_NONE; |
287 |
| - } |
288 |
| - return create_stdio_original(config, io, fd, write_mode, name, encoding, errors); |
289 |
| -} |
290 |
| - |
291 |
| -bool patchPython310CreateStdio() { |
292 |
| - if (create_stdio_original == nullptr) { |
293 |
| - HMODULE hModule = GetModuleHandleW(L"python310.dll"); |
294 |
| - if (hModule == NULL) return false; |
295 |
| - create_stdio_original = (create_stdio_func_type)(void*)(((uintptr_t)hModule) + create_stdio_func_base_offset); |
296 |
| - } |
297 |
| - |
298 |
| - DetourRestoreAfterWith(); |
299 |
| - if (DetourTransactionBegin() != NO_ERROR) return false; |
300 |
| - else if (DetourUpdateThread(GetCurrentThread()) != NO_ERROR) return false; |
301 |
| - else if (DetourAttach((PVOID*)&create_stdio_original, create_stdio_hooked) != NO_ERROR) return false; |
302 |
| - else if (DetourTransactionCommit() != NO_ERROR) return false; |
303 |
| - return true; |
304 |
| -} |
305 |
| - |
306 |
| -bool unpatchPython310CreateStdio() { |
307 |
| - if (DetourTransactionBegin() != NO_ERROR) return false; |
308 |
| - else if (DetourUpdateThread(GetCurrentThread()) != NO_ERROR) return false; |
309 |
| - else if (DetourDetach((PVOID*)&create_stdio_original, create_stdio_hooked) != NO_ERROR) return false; |
310 |
| - else if (DetourTransactionCommit() != NO_ERROR) return false; |
311 |
| - return true; |
312 |
| -} |
313 |
| - |
314 |
| -} // namespace FixPython310Stdin |
| 269 | +// namespace FixPython310Stdin { |
| 270 | +// // Hard coded function address |
| 271 | +// const uintptr_t create_stdio_func_base_offset = 0xCE0F4; |
| 272 | + |
| 273 | +// create_stdio_func_type create_stdio_original = nullptr; |
| 274 | + |
| 275 | +// PyObject* create_stdio_hooked( |
| 276 | +// const PyConfig* config, |
| 277 | +// PyObject* io, |
| 278 | +// int fd, |
| 279 | +// int write_mode, |
| 280 | +// const char* name, |
| 281 | +// const wchar_t* encoding, |
| 282 | +// const wchar_t* errors |
| 283 | +// ) { |
| 284 | +// if (fd == 0) { |
| 285 | +// Py_RETURN_NONE; |
| 286 | +// } |
| 287 | +// return create_stdio_original(config, io, fd, write_mode, name, encoding, errors); |
| 288 | +// } |
| 289 | + |
| 290 | +// bool patchPython310CreateStdio() { |
| 291 | +// if (create_stdio_original == nullptr) { |
| 292 | +// HMODULE hModule = GetModuleHandleW(L"python310.dll"); |
| 293 | +// if (hModule == NULL) return false; |
| 294 | +// create_stdio_original = (create_stdio_func_type)(void*)(((uintptr_t)hModule) + |
| 295 | +// create_stdio_func_base_offset); |
| 296 | +// } |
| 297 | + |
| 298 | +// DetourRestoreAfterWith(); |
| 299 | +// if (DetourTransactionBegin() != NO_ERROR) return false; |
| 300 | +// else if (DetourUpdateThread(GetCurrentThread()) != NO_ERROR) return false; |
| 301 | +// else if (DetourAttach((PVOID*)&create_stdio_original, create_stdio_hooked) != NO_ERROR) return false; |
| 302 | +// else if (DetourTransactionCommit() != NO_ERROR) return false; |
| 303 | +// return true; |
| 304 | +// } |
| 305 | + |
| 306 | +// bool unpatchPython310CreateStdio() { |
| 307 | +// if (DetourTransactionBegin() != NO_ERROR) return false; |
| 308 | +// else if (DetourUpdateThread(GetCurrentThread()) != NO_ERROR) return false; |
| 309 | +// else if (DetourDetach((PVOID*)&create_stdio_original, create_stdio_hooked) != NO_ERROR) return false; |
| 310 | +// else if (DetourTransactionCommit() != NO_ERROR) return false; |
| 311 | +// return true; |
| 312 | +// } |
| 313 | + |
| 314 | +// } // namespace FixPython310Stdin |
315 | 315 |
|
316 | 316 | } // namespace PythonHelper
|
317 | 317 |
|
|
0 commit comments