#include "stdafx.h" #include #include "PythonDynamicModuleNames.h" #include "CheatQueueManager.h" #include "PythonStackCheck.h" #include "../eterPack/EterPackManager.h" #include /* import app > import impMgr\napp = __import__(impMgr.getModule("app")) import net > import impMgr\nnet = __import__(impMgr.getModule("net")) import chr > import impMgr\nchr = __import__(impMgr.getModule("chr")) import chrmgr > import impMgr\nchrmgr = __import__(impMgr.getModule("chrmgr")) import player > import impMgr\nplayer = __import__(impMgr.getModule("player")) import item > import impMgr\nitem = __import__(impMgr.getModule("item")) import pack > import impMgr\npack = __import__(impMgr.getModule("pack")) */ #pragma optimize("", off ) static char __impMgr[] = { 'i', 'm', 'p', 'M', 'g', 'r', 0x0 }; static char __getModule[] = { 'g', 'e', 't', 'M', 'o', 'd', 'u', 'l', 'e', 0x0 }; inline std::string GenRandomString(size_t length) { CHAR __alphabet[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 0x0 }; // abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 static std::string charset = __alphabet; std::string result; result.resize(length); for (int i = 0; i < length; i++) result[i] = charset[rand() % charset.length()]; return result; } #pragma optimize("", on ) static std::array gs_arrayModuleNames; std::string GetPythonModuleName(int moduleId) { return gs_arrayModuleNames[moduleId]; } PyObject * importMgrGetModule(PyObject * poSelf, PyObject * poArgs) { char* szOldName; if (!PyTuple_GetString(poArgs, 0, &szOldName)) return Py_BuildException(); const char* c_szCallerReference = PY_REF_FILE.c_str(); const char* c_szCallerReferenceFunc = PY_REF_FUNC.c_str(); if (strlen(c_szCallerReference) > 0 && !CEterPackManager::Instance().isExistInPack(c_szCallerReference) && !strstr(c_szCallerReference, XOR("locale/")) && !strstr(c_szCallerReference, XOR("uiscript/"))) { CCheatDetectQueueMgr::Instance().AppendDetection(CHEAT_PY_API_REQUEST_UNKNOWN_REFERENCE, 0, c_szCallerReference); } std::string strNewName = szOldName; if (strcmp(szOldName, XOR("app")) == 0) strNewName = GetPythonModuleName(PYTHON_APPLICATION).c_str(); else if (strcmp(szOldName, XOR("net")) == 0) strNewName = GetPythonModuleName(PYTHON_NETWORK).c_str(); else if (strcmp(szOldName, XOR("chr")) == 0) strNewName = GetPythonModuleName(PYTHON_CHARACTER).c_str(); else if (strcmp(szOldName, XOR("chrmgr")) == 0) strNewName = GetPythonModuleName(PYTHON_CHARACTER_MGR).c_str(); else if (strcmp(szOldName, XOR("player")) == 0) strNewName = GetPythonModuleName(PYTHON_PLAYER).c_str(); else if (strcmp(szOldName, XOR("item")) == 0) strNewName = GetPythonModuleName(PYTHON_ITEM).c_str(); else if (strcmp(szOldName, XOR("pack")) == 0) strNewName = GetPythonModuleName(PYTHON_PACK).c_str(); else { char szMsg[255]; sprintf_s(szMsg, XOR("Ref: '%s'-'%s' Req: '%s'"), c_szCallerReference, c_szCallerReferenceFunc, szOldName); CCheatDetectQueueMgr::Instance().AppendDetection(CHEAT_PY_API_REQUEST_UNKNOWN_API, 0, szMsg); } // TraceError("Ref: '%s'-'%s' Req: '%s' New: '%s'", c_szCallerReference, c_szCallerReferenceFunc, szOldName, strNewName.c_str()); return Py_BuildValue(XOR("s"), strNewName.c_str()); } void initModuleNameManager() { static PyMethodDef s_methods[] = { { __getModule, importMgrGetModule, METH_VARARGS}, { NULL, NULL, NULL }, }; PyObject* poModule = Py_InitModule(__impMgr, s_methods); for (int i = 0; i < PYTHON_MODULE_NAME_MAX; ++i) gs_arrayModuleNames[i] = GenRandomString(16); }