Is there a way I can allow players to require a specific ModuleScript and run a specific ModuleScript function?
Yes, using hooks and read hooks it is possible:
-- Assuming VM is a LuaVM object
local allowedModule = ... -- whatever module
local requiredAllowedModule = require(allowedModule)
VM:ReplaceClosure(require, function(module)
assert(module == allowedModule, "module cannot be required")
return requiredAllowedModule
end)
VM:AddReadHook(requiredAllowedModule, function(self, Index, NormalValue)
if type(Index) == "string" then
--// CheckCString should not be used in non c function hooks
if "someFunc" == Index then --> Replace someFunc with the function's index in the module
return NormalValue
end
end
error("cannot use function '" .. Index .. "' from module", 2)
end)
So my problem is Signal.__index = Signal because when i remove this line, this unlocks the script but it gives me error cause __index is important after. Any solution?
i enabled this settings:
LuaVM:EnableAdditionalSetting(SLVM.Enum.AdditionalSettings.ThrottleLoopInstructions)
LuaVM:EnableAdditionalSetting(SLVM.Enum.AdditionalSettings.ThrottleRecursiveCalls)
LuaVM:EnableAdditionalSetting(SLVM.Enum.AdditionalSettings.SandboxCalls)
I ran exactly the script you gave me, however if you did not find a solution to your problem, disable SandboxCalls
although that is not recommended.
I found a solution I have put the __index script inside of a module script.
But do you have a idea how to optimize the lua vm? Because i run a lot of script inside of the lua vm and i takes 4-5 minutes to load (very annoying)
I am no longer actively updating this module. However feel free to give suggestions and I will do my best to implement them. I sadly cannot do much regarding the VMâs speed.
Any way to allow Instance.new()
, but only for GuiObjects?
Set Instance
to a new local variable before the rest of the script runs. You can regulate it yourself that way!
Thatâs ok! Send it when you can.
Hi, are you able to send the answer now?
Sorry for the delay;
One can use the roblox api dump https://github.com/MaximumADHD/Roblox-Client-Tracker/blob/roblox/Full-API-Dump.json and check if the object requestedâs superclass is âGuiObjectâ. I cannot send a code snippet example right now, but Iâll send one when Iâll be available.
Have you any idea to improve performance in the slvmrules.AdditionalSettings.SandboxCalls function, cause when i disabling it, it runs more faster. But i want security?
If disabling that gives you performance then donât worry about security
No I sadly cannot make it any faster.
You could however block getfenv
and debug.info
Ok no problem, your module is very nice, back to back my loadstring module was sht and lagging all the times and now with your module the situation has improved!
Unless you made a bridge to expose Roblox API to the Luau VM created in LuauInLuau, theres practically no need to sandbox LuauInLuau as it essentially runs code in a vanilla Luau environment. Hell you can literally further control it using the C api provided you know what youâre doing.
Additionally, as @HexadecimalLiker has said, it is practically just the vanilla Luau project compiled into WebAssembly, translated into Luau, and with extra modifications to expose a usable api and setup. The perfomance would be quite hampered.
The best use case youâre probably looking right now is to use the Luau compiler in LuauInLuau and combine it with Fiu.
Now looking back at this project, I really need to update it to the latest Luau so Iâll do that when I have time
@HexadecimalLiker Also, consider uploading source to GitHub (either repo or gists) to allow users with no Studio access to view the script
Okay, Iâll try that when Iâll rewrite SLVM which should be pretty soon. Iâll also try making a method to choose a module so users can use custom made vms, for example Fiu.
Hi, another question: Is there a way to get the clientâs code, processit on the server and then if the SLVM module doesnât return any errors(ex. Instance.new is found and is blocked by SLVM), it runs normally on the client?
You cannot do that as SLVM operates at runtime, which means if the script consists of creating a part in workspace, the part will stay there on the server until :DeleteCreatedInstances
is called. You could however use SLVM on the client, however I didnât test if it worked locally yet.