From 9b591bb71cd640821a5a36d21278c0825ef8252c Mon Sep 17 00:00:00 2001 From: plusgiant5 Date: Sun, 29 Dec 2024 20:20:46 -0800 Subject: [PATCH] osunsafe --- runluau-osunsafe/dllmain.cpp | 5 + runluau-osunsafe/lib.cpp | 85 ++++++++ runluau-osunsafe/pch.cpp | 1 + runluau-osunsafe/pch.h | 6 + runluau-osunsafe/runluau-osunsafe.vcxproj | 186 ++++++++++++++++++ .../runluau-osunsafe.vcxproj.filters | 33 ++++ runluau-plugins.sln | 10 + 7 files changed, 326 insertions(+) create mode 100644 runluau-osunsafe/dllmain.cpp create mode 100644 runluau-osunsafe/lib.cpp create mode 100644 runluau-osunsafe/pch.cpp create mode 100644 runluau-osunsafe/pch.h create mode 100644 runluau-osunsafe/runluau-osunsafe.vcxproj create mode 100644 runluau-osunsafe/runluau-osunsafe.vcxproj.filters diff --git a/runluau-osunsafe/dllmain.cpp b/runluau-osunsafe/dllmain.cpp new file mode 100644 index 0000000..def0f3d --- /dev/null +++ b/runluau-osunsafe/dllmain.cpp @@ -0,0 +1,5 @@ +#include "pch.h" + +BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { + return TRUE; +} \ No newline at end of file diff --git a/runluau-osunsafe/lib.cpp b/runluau-osunsafe/lib.cpp new file mode 100644 index 0000000..1c2438a --- /dev/null +++ b/runluau-osunsafe/lib.cpp @@ -0,0 +1,85 @@ +#include "pch.h" + +int execute(lua_State* thread) { + wanted_arg_count(1); + const char* command = luaL_checkstring(thread, 1); + int code = system(command); + if (code == ERROR_SUCCESS) { + return 0; + } else { + code = errno; + char* error_message = new char[256]; + strerror_s(error_message, 256, code); + lua_pushfstring(thread, "Command failed with error code %d: %s", code, error_message); + lua_error(thread); + delete[] error_message; + return 0; + } +} + +int capture(lua_State* thread) { + wanted_arg_count(1); + const char* command = luaL_checkstring(thread, 1); + + FILE* pipe = _popen(command, "r"); + if (!pipe) { + int code = errno; + char error_message[256]; + strerror_s(error_message, sizeof(error_message), code); + lua_pushfstring(thread, "Command failed with error code %d: %s. Unable to capture.", code, error_message); + lua_error(thread); + return 0; + } + + std::string output; + char buffer[256]; + while (fgets(buffer, sizeof(buffer), pipe)) { + output += buffer; + } + + int status = _pclose(pipe); + if (status != 0) { + int code = errno; + char error_message[256]; + strerror_s(error_message, sizeof(error_message), code); + lua_pushfstring(thread, "Command failed with error code %d: %s. Captured:\n%s", code, error_message, output.data()); + lua_error(thread); + return 0; + } + + lua_pushlstring(thread, output.c_str(), output.size()); + return 1; +} + +int getenv(lua_State* thread) { + wanted_arg_count(1); + const char* name = luaL_checkstring(thread, 1); + const char* value = std::getenv(name); + if (value) { + lua_pushstring(thread, value); + } else { + lua_pushnil(thread); + } + return 1; +} +int setenv(lua_State* thread) { + wanted_arg_count(2); + const char* name = luaL_checkstring(thread, 1); + const char* value = luaL_checkstring(thread, 2); + if (!SetEnvironmentVariableA(name, value)) { + lua_pushfstring(thread, "Failed to SetEnvironmentVariableA: %d", GetLastError()); + lua_error(thread); + return 0; + } + return 0; +} + +#define reg(name) lua_pushcfunction(thread, name, #name); lua_setfield(thread, -2, #name) +extern "C" __declspec(dllexport) void register_library(lua_State* thread) { + lua_createtable(thread, 0, 0); + reg(execute); + reg(capture); + reg(getenv); + reg(setenv); + lua_setglobal(thread, "os"); +} \ No newline at end of file diff --git a/runluau-osunsafe/pch.cpp b/runluau-osunsafe/pch.cpp new file mode 100644 index 0000000..1730571 --- /dev/null +++ b/runluau-osunsafe/pch.cpp @@ -0,0 +1 @@ +#include "pch.h" \ No newline at end of file diff --git a/runluau-osunsafe/pch.h b/runluau-osunsafe/pch.h new file mode 100644 index 0000000..37cf671 --- /dev/null +++ b/runluau-osunsafe/pch.h @@ -0,0 +1,6 @@ +#pragma once + +#include +#include + +#include "luau.h" \ No newline at end of file diff --git a/runluau-osunsafe/runluau-osunsafe.vcxproj b/runluau-osunsafe/runluau-osunsafe.vcxproj new file mode 100644 index 0000000..887e5df --- /dev/null +++ b/runluau-osunsafe/runluau-osunsafe.vcxproj @@ -0,0 +1,186 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {E02B59B9-BA00-4CAE-B953-BAE40BFCC970} + runluautemplate + 10.0 + + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + DynamicLibrary + true + v143 + Unicode + + + DynamicLibrary + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + ..\..\runluau\out\$(Configuration)\plugins\ + $(SolutionDir)obj\$(ShortProjectName)\ + + + ..\..\runluau\out\$(Configuration)\plugins\ + $(SolutionDir)obj\$(ShortProjectName)\ + + + + Level3 + true + WIN32;_DEBUG;RUNLUAUTEMPLATE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + false + + + + + Level3 + true + true + true + WIN32;NDEBUG;RUNLUAUTEMPLATE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + + + Windows + true + true + true + false + + + + + Level3 + true + _CRT_SECURE_NO_WARNINGS;_DEBUG;RUNLUAUTEMPLATE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + stdcpp20 + stdc17 + ../../runluau/shared;%LUAUSRC%\CodeGen\include;%LUAUSRC%\Common\include;%LUAUSRC%\VM\include;%LUAUSRC%\Compiler\include;%LUAUSRC%\Ast\include;%(AdditionalIncludeDirectories) + + + Windows + true + false + ..\..\runluau\luau\$(Configuration);%(AdditionalLibraryDirectories) + luau.lib;%(AdditionalDependencies) + /NOIMPLIB /NOEXP %(AdditionalOptions) + + + + + + + + + Level3 + true + true + true + _CRT_SECURE_NO_WARNINGS;NDEBUG;RUNLUAUTEMPLATE_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) + true + Use + pch.h + stdcpp20 + stdc17 + ../../runluau/shared;%LUAUSRC%\CodeGen\include;%LUAUSRC%\Common\include;%LUAUSRC%\VM\include;%LUAUSRC%\Compiler\include;%LUAUSRC%\Ast\include;%(AdditionalIncludeDirectories) + None + + + Windows + true + true + false + false + luau.lib;%(AdditionalDependencies) + ..\..\runluau\luau\$(Configuration);%(AdditionalLibraryDirectories) + /NOIMPLIB /NOEXP %(AdditionalOptions) + + + + + + + + + + + + + + Create + Create + Create + Create + + + + + + \ No newline at end of file diff --git a/runluau-osunsafe/runluau-osunsafe.vcxproj.filters b/runluau-osunsafe/runluau-osunsafe.vcxproj.filters new file mode 100644 index 0000000..7c98277 --- /dev/null +++ b/runluau-osunsafe/runluau-osunsafe.vcxproj.filters @@ -0,0 +1,33 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Header Files + + + + + Source Files + + + Source Files + + + Source Files + + + \ No newline at end of file diff --git a/runluau-plugins.sln b/runluau-plugins.sln index 3a0c5d8..f88cad6 100644 --- a/runluau-plugins.sln +++ b/runluau-plugins.sln @@ -19,6 +19,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "runluau-graphics", "runluau EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{B5D5A95D-A9AC-4426-96E0-DB819AF60319}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "runluau-osunsafe", "runluau-osunsafe\runluau-osunsafe.vcxproj", "{E02B59B9-BA00-4CAE-B953-BAE40BFCC970}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -83,6 +85,14 @@ Global {9A682B45-A00B-484D-A90A-EB5585FBA315}.Release|x64.Build.0 = Release|x64 {9A682B45-A00B-484D-A90A-EB5585FBA315}.Release|x86.ActiveCfg = Release|Win32 {9A682B45-A00B-484D-A90A-EB5585FBA315}.Release|x86.Build.0 = Release|Win32 + {E02B59B9-BA00-4CAE-B953-BAE40BFCC970}.Debug|x64.ActiveCfg = Debug|x64 + {E02B59B9-BA00-4CAE-B953-BAE40BFCC970}.Debug|x64.Build.0 = Debug|x64 + {E02B59B9-BA00-4CAE-B953-BAE40BFCC970}.Debug|x86.ActiveCfg = Debug|Win32 + {E02B59B9-BA00-4CAE-B953-BAE40BFCC970}.Debug|x86.Build.0 = Debug|Win32 + {E02B59B9-BA00-4CAE-B953-BAE40BFCC970}.Release|x64.ActiveCfg = Release|x64 + {E02B59B9-BA00-4CAE-B953-BAE40BFCC970}.Release|x64.Build.0 = Release|x64 + {E02B59B9-BA00-4CAE-B953-BAE40BFCC970}.Release|x86.ActiveCfg = Release|Win32 + {E02B59B9-BA00-4CAE-B953-BAE40BFCC970}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE