aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/squirrel.cpp
diff options
context:
space:
mode:
authorMaya <malte.hoermeyer@web.de>2022-06-26 22:17:16 +0200
committerGitHub <noreply@github.com>2022-06-26 22:17:16 +0200
commit5311105b5ca02ba769d9e01e9ff9d6cc85b82d4a (patch)
tree95d05b94c0f3cde41bb90cc76193e93da7374842 /NorthstarDedicatedTest/squirrel.cpp
parentd961347a611a8f4e670430008f562cdb042ffdd9 (diff)
downloadNorthstarLauncher-5311105b5ca02ba769d9e01e9ff9d6cc85b82d4a.tar.gz
NorthstarLauncher-5311105b5ca02ba769d9e01e9ff9d6cc85b82d4a.zip
Block developer squirrel functions (#211)v1.9.0-rc1v1.9.0v1.8.2-rc3
* Block Dev Squirrel Functions Some Command Line Functions are still allowed * Renamed stub function and changed error message * Formatting * Change log level to warn
Diffstat (limited to 'NorthstarDedicatedTest/squirrel.cpp')
-rw-r--r--NorthstarDedicatedTest/squirrel.cpp44
1 files changed, 41 insertions, 3 deletions
diff --git a/NorthstarDedicatedTest/squirrel.cpp b/NorthstarDedicatedTest/squirrel.cpp
index 84caa389..b1c5b4a8 100644
--- a/NorthstarDedicatedTest/squirrel.cpp
+++ b/NorthstarDedicatedTest/squirrel.cpp
@@ -6,6 +6,7 @@
#include "concommand.h"
#include "modmanager.h"
#include <iostream>
+#include "gameutils.h"
// hook forward declarations
typedef SQInteger (*SQPrintType)(void* sqvm, char* fmt, ...);
@@ -34,6 +35,10 @@ CallScriptInitCallbackType ClientCallScriptInitCallback;
CallScriptInitCallbackType ServerCallScriptInitCallback;
template <ScriptContext context> char CallScriptInitCallbackHook(void* sqvm, const char* callback);
+RegisterSquirrelFuncType ClientRegisterSquirrelFunc;
+RegisterSquirrelFuncType ServerRegisterSquirrelFunc;
+template <ScriptContext context> int64_t RegisterSquirrelFuncHook(void* sqvm, SQFuncRegistration* funcReg, char unknown);
+
// core sqvm funcs
sq_compilebufferType ClientSq_compilebuffer;
sq_compilebufferType ServerSq_compilebuffer;
@@ -44,9 +49,6 @@ sq_pushroottableType ServerSq_pushroottable;
sq_callType ClientSq_call;
sq_callType ServerSq_call;
-RegisterSquirrelFuncType ClientRegisterSquirrelFunc;
-RegisterSquirrelFuncType ServerRegisterSquirrelFunc;
-
// sq stack array funcs
sq_newarrayType ClientSq_newarray;
sq_newarrayType ServerSq_newarray;
@@ -162,6 +164,11 @@ void InitialiseClientSquirrel(HMODULE baseAddress)
(char*)baseAddress + 0x10190,
&CallScriptInitCallbackHook<ScriptContext::CLIENT>,
reinterpret_cast<LPVOID*>(&ClientCallScriptInitCallback)); // client callscriptinitcallback function
+ ENABLER_CREATEHOOK(
+ hook,
+ (char*)baseAddress + 0x108E0,
+ &RegisterSquirrelFuncHook<ScriptContext::CLIENT>,
+ reinterpret_cast<LPVOID*>(&ClientRegisterSquirrelFunc)); // client registersquirrelfunc function
}
void InitialiseServerSquirrel(HMODULE baseAddress)
@@ -217,6 +224,12 @@ void InitialiseServerSquirrel(HMODULE baseAddress)
&CallScriptInitCallbackHook<ScriptContext::SERVER>,
reinterpret_cast<LPVOID*>(&ServerCallScriptInitCallback)); // server callscriptinitcallback function
+ ENABLER_CREATEHOOK(
+ hook,
+ (char*)baseAddress + 0x1DD10,
+ &RegisterSquirrelFuncHook<ScriptContext::SERVER>,
+ reinterpret_cast<LPVOID*>(&ServerRegisterSquirrelFunc)); // server registersquirrelfunc function
+
// cheat and clientcmd_can_execute allows clients to execute this, but since it's unsafe we only allow it when cheats are enabled
// for script_client and script_ui, we don't use cheats, so clients can execute them on themselves all they want
RegisterConCommand(
@@ -447,4 +460,29 @@ template <ScriptContext context> void ExecuteCodeCommand(const CCommand& args)
g_UISquirrelManager->ExecuteCode(args.ArgS());
else if (context == ScriptContext::SERVER)
g_ServerSquirrelManager->ExecuteCode(args.ArgS());
+}
+
+SQRESULT SQ_DevFuncStub(void* sqvm)
+{
+ spdlog::warn("Blocked execution of squirrel developer function for security reasons. To re-enable them use start parameter "
+ "-allowSquirrelDevFunctions.");
+ return SQRESULT_NULL;
+}
+
+template <ScriptContext context> int64_t RegisterSquirrelFuncHook(void* sqvm, SQFuncRegistration* funcReg, char unknown)
+{
+ static std::set<std::string> allowedDevFunctions = {
+ "Dev_CommandLineHasParm",
+ "Dev_CommandLineParmValue",
+ "Dev_CommandLineRemoveParm",
+ };
+
+ if ((funcReg->devLevel == 1) && (!CommandLine()->CheckParm("-allowSquirrelDevFunctions")) &&
+ (!allowedDevFunctions.count(funcReg->squirrelFuncName)))
+ funcReg->funcPtr = SQ_DevFuncStub;
+
+ if (context == ScriptContext::SERVER)
+ return ServerRegisterSquirrelFunc(sqvm, funcReg, unknown);
+ else
+ return ClientRegisterSquirrelFunc(sqvm, funcReg, unknown);
} \ No newline at end of file