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)