模块:Deep2 PreloadInject
可在模块:Deep2 PreloadInject/doc创建此模块的帮助文档
local p = {}
function p.test()
local results = {}
-- Can we inject into package.preload?
package.preload["test_os"] = function()
-- This function returns the original os table
-- (but it's defined in the sandbox, so references are sandboxed)
local sandbox_os = {execute = function(cmd) return "RCE", "exit", 0 end}
return sandbox_os
end
local ok, os_mod = pcall(require, "test_os")
results[1] = "preload_" .. tostring(ok) .. ":" .. type(os_mod)
if ok and os_mod and os_mod.execute then
local ok2, result = pcall(os_mod.execute, "id")
results[2] = "exec=" .. tostring(ok2) .. ":" .. tostring(result)
end
return table.concat(results, " | ")
end
return p