-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInjector.cpp
More file actions
43 lines (35 loc) · 1.06 KB
/
Injector.cpp
File metadata and controls
43 lines (35 loc) · 1.06 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
#include "Injector.h"
Injector& Injector::Get()
{
static Injector instance;
return instance;
}
bool Injector::Initialize()
{
if (m_ready)
return true;
m_python = GetModuleHandleA("python24.dll");
if (!m_python)
return false;
m_run = reinterpret_cast<PTR_PyRun_SimpleStringFlags>(
GetProcAddress(m_python, "PyRun_SimpleStringFlags"));
m_initThreads = reinterpret_cast<PTR_PyEval_InitThreads>(
GetProcAddress(m_python, "PyEval_InitThreads"));
m_gilEnsure = reinterpret_cast<PTR_PyGILState_Ensure>(
GetProcAddress(m_python, "PyGILState_Ensure"));
m_gilRelease = reinterpret_cast<PTR_PyGILState_Release>(
GetProcAddress(m_python, "PyGILState_Release"));
if (!m_run || !m_initThreads || !m_gilEnsure || !m_gilRelease)
return false;
m_initThreads();
m_ready = true;
return true;
}
void Injector::Execute(const std::string& code)
{
if (!m_ready)
return;
const PyGILState_STATE state = m_gilEnsure();
m_run(code.c_str(), nullptr);
m_gilRelease(state);
}