diff --git a/client/src/CV8Resource.cpp b/client/src/CV8Resource.cpp index 7c80142e..6bcb739c 100644 --- a/client/src/CV8Resource.cpp +++ b/client/src/CV8Resource.cpp @@ -28,6 +28,7 @@ #include "JSBindings.h" + extern void StaticRequire(const v8::FunctionCallbackInfo& info) { V8_GET_ISOLATE_CONTEXT_RESOURCE(); @@ -37,6 +38,11 @@ extern void StaticRequire(const v8::FunctionCallbackInfo& info) IImportHandler* handler = nullptr; bool isWorker = *static_cast(isolate->GetData(isolate->GetNumberOfDataSlots() - 1)); + +#ifdef NDEBUG + VMProtectBeginMutation("StaticRequire"); +#endif + if (isWorker) { auto worker = static_cast(ctx->GetAlignedPointerFromEmbedderData(2)); @@ -50,6 +56,9 @@ extern void StaticRequire(const v8::FunctionCallbackInfo& info) if (!_exports.IsEmpty()) info.GetReturnValue().Set(_exports.ToLocalChecked()); else V8Helpers::Throw(isolate, "No such module " + name); +#ifdef NDEBUG + VMProtectEnd(); +#endif } void StartFile(const v8::FunctionCallbackInfo& info) @@ -69,12 +78,18 @@ void StartFile(const v8::FunctionCallbackInfo& info) void CV8ResourceImpl::ProcessDynamicImports() { +#ifdef NDEBUG + VMProtectBeginMutation("ProcessDynamicImports"); +#endif if (dynamicImports.empty()) return; for (auto& importFn : dynamicImports) { importFn(); } dynamicImports.clear(); +#ifdef NDEBUG + VMProtectEnd(); +#endif } extern std::string bootstrap_code = @@ -234,6 +249,10 @@ bool CV8ResourceImpl::Stop() void CV8ResourceImpl::OnEvent(const alt::CEvent* e) { +#ifdef NDEBUG + VMProtectBeginMutation("CV8ResourceImpl::OnEvent"); +#endif + auto nscope = resource->PushNativesScope(); v8::Locker locker(isolate); @@ -308,6 +327,9 @@ void CV8ResourceImpl::OnEvent(const alt::CEvent* e) runtime.OnDisconnect(); } } +#ifdef NDEBUG + VMProtectEnd(); +#endif } void CV8ResourceImpl::HandleRPCAnswer(const alt::CScriptRPCAnswerEvent* ev) @@ -463,6 +485,9 @@ std::vector CV8ResourceImpl::GetRmlHandlers(alt::IRml void CV8ResourceImpl::OnTick() { +#ifdef NDEBUG + VMProtectBeginMutation("CV8ResourceImpl::OnTick"); +#endif v8::Locker locker(isolate); v8::Isolate::Scope isolateScope(isolate); v8::HandleScope handleScope(isolate); @@ -526,6 +551,10 @@ void CV8ResourceImpl::OnTick() } promiseRejections.ProcessQueue(this); + +#ifdef NDEBUG + VMProtectEnd(); +#endif } void CV8ResourceImpl::OnPromiseRejectedWithNoHandler(v8::PromiseRejectMessage& data) diff --git a/client/src/IImportHandler.cpp b/client/src/IImportHandler.cpp index 82451f7f..a20c7860 100644 --- a/client/src/IImportHandler.cpp +++ b/client/src/IImportHandler.cpp @@ -3,12 +3,19 @@ static inline v8::MaybeLocal CompileESM(v8::Isolate* isolate, const std::string& name, const std::string& src) { +#ifdef NDEBUG + VMProtectBeginMutation("CompileESM"); +#endif + v8::Local sourceCode = V8Helpers::JSValue(src); v8::ScriptOrigin scriptOrigin(isolate, V8Helpers::JSValue(name), 0, 0, false, -1, v8::Local(), false, false, true, v8::Local()); v8::ScriptCompiler::Source source{ sourceCode, scriptOrigin }; return v8::ScriptCompiler::CompileModule(isolate, &source); +#ifdef NDEBUG + VMProtectEnd(); +#endif } static inline bool IsSystemModule(v8::Isolate* isolate, const std::string& name) @@ -110,25 +117,43 @@ std::string IImportHandler::GetModulePath(v8::Local moduleHandle) const IImportHandler::ModuleData IImportHandler::GetModuleData(const std::string& name) { auto result = modules.find(name); + + #ifdef NDEBUG + VMProtectBeginMutation("IImportHandler::GetModuleData"); +#endif + if(result == modules.end()) return ModuleData{}; return result->second; +#ifdef NDEBUG + VMProtectEnd(); +#endif } v8::Local IImportHandler::GetModuleFromPath(std::string modulePath) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); +#ifdef NDEBUG + VMProtectBeginMutation("IImportHandler::GetModuleFromPath"); +#endif for(auto& md : modules) { if(md.first == modulePath) return md.second.mod.Get(isolate); } return v8::Local{}; +#ifdef NDEBUG + VMProtectEnd(); +#endif } v8::MaybeLocal IImportHandler::Require(const std::string& name) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); auto it = requiresMap.find(name); + +#ifdef NDEBUG + VMProtectBeginMutation("Require"); +#endif if(it != requiresMap.end()) return it->second.Get(isolate); auto v8module = V8Module::All()[isolate].find(name); @@ -151,6 +176,9 @@ v8::MaybeLocal IImportHandler::Require(const std::string& name) } return v8::MaybeLocal(); +#ifdef NDEBUG + VMProtectEnd(); +#endif } v8::MaybeLocal IImportHandler::ResolveFile(const std::string& name, v8::Local referrer, alt::IResource* resource) @@ -158,6 +186,10 @@ v8::MaybeLocal IImportHandler::ResolveFile(const std::string& name, v8::Isolate* isolate = v8::Isolate::GetCurrent(); auto path = alt::ICore::Instance().Resolve(resource, name, GetModulePath(referrer)); +#ifdef NDEBUG + VMProtectBeginMutation("ResolveFile"); +#endif + if(!path.pkg) return v8::MaybeLocal(); std::string fileName = path.fileName; @@ -208,6 +240,10 @@ v8::MaybeLocal IImportHandler::ResolveFile(const std::string& name, } return maybeModule; + +#ifdef NDEBUG + VMProtectEnd(); +#endif } v8::MaybeLocal IImportHandler::ResolveModule(const std::string& _name, v8::Local referrer, alt::IResource* resource) @@ -217,6 +253,10 @@ v8::MaybeLocal IImportHandler::ResolveModule(const std::string& _nam std::string name = _name; +#ifdef NDEBUG + VMProtectBeginMutation("ResolveModule"); +#endif + if(name.starts_with("alt:")) name = name.substr(4); if(name == "alt-client") name = "alt"; @@ -277,6 +317,9 @@ v8::MaybeLocal IImportHandler::ResolveModule(const std::string& _nam }*/ return maybeModule; +#ifdef NDEBUG + VMProtectEnd(); +#endif } v8::MaybeLocal IImportHandler::ResolveCode(const std::string& name, const std::string& code, const V8Helpers::SourceLocation& location) @@ -284,18 +327,29 @@ v8::MaybeLocal IImportHandler::ResolveCode(const std::string& name, v8::Isolate* isolate = v8::Isolate::GetCurrent(); v8::MaybeLocal maybeModule; std::stringstream nameStream; +#ifdef NDEBUG + VMProtectBeginMutation("Import::ResolveCode"); +#endif + if(name.empty()) nameStream << "[module " << location.GetFileName() << ":" << location.GetLineNumber() << "]"; else nameStream << name; maybeModule = CompileESM(isolate, nameStream.str(), code); return maybeModule; +#ifdef NDEBUG + VMProtectEnd(); +#endif } v8::MaybeLocal IImportHandler::ResolveBytecode(const std::string& name, uint8_t* buffer, size_t size) { v8::Isolate* isolate = v8::Isolate::GetCurrent(); +#ifdef NDEBUG + VMProtectBeginMutation("ResolveBytecode"); +#endif + // Copy source code size int sourceCodeSize = 0; memcpy(&sourceCodeSize, buffer + sizeof(bytecodeMagic), sizeof(int)); @@ -325,4 +379,7 @@ v8::MaybeLocal IImportHandler::ResolveBytecode(const std::string& na } else return module; +#ifdef NDEBUG + VMProtectEnd(); +#endif } diff --git a/shared/V8Class.h b/shared/V8Class.h index 4bda0eb1..e8ae2501 100644 --- a/shared/V8Class.h +++ b/shared/V8Class.h @@ -6,6 +6,8 @@ #include "Log.h" +#include "../../vmp/VMProtectSDK.h" + class V8Class { using InitCallback = std::function)>; diff --git a/shared/V8ResourceImpl.cpp b/shared/V8ResourceImpl.cpp index 56817c11..9d8ff8b9 100644 --- a/shared/V8ResourceImpl.cpp +++ b/shared/V8ResourceImpl.cpp @@ -19,6 +19,10 @@ using namespace alt; extern V8Class v8Vector3, v8Vector2, v8RGBA, v8BaseObject, v8Quaternion; bool V8ResourceImpl::Start() { +#ifdef NDEBUG + VMProtectBeginMutation("V8ResourceImpl::Start"); +#endif + vector3Class.Reset(isolate, v8Vector3.JSValue(isolate, GetContext())); vector2Class.Reset(isolate, v8Vector2.JSValue(isolate, GetContext())); quaternionClass.Reset(isolate, v8Quaternion.JSValue(isolate, GetContext())); @@ -26,6 +30,9 @@ bool V8ResourceImpl::Start() baseObjectClass.Reset(isolate, v8BaseObject.JSValue(isolate, GetContext())); return true; +#ifdef NDEBUG + VMProtectEnd(); +#endif } bool V8ResourceImpl::Stop()