Then the hypothetical attacker can override string.dump.
local oldGetID, oldDump = os.computerID, string.dump
function os.computerID() return 42 end
function string.dump(f)
if f == os.computerID then error("dan200.computer.core.LuaJLuaMachine$2 cannot be cast to org.luaj.vm2.LuaClosure", 0) end -- the exact error message CC gives
return oldDump(f)
end
(does this count as malicious code? it could be part of a legitimate sandbox)
Edit: This can be countered by:
local old = os.computerID
function os.computerID() end
local isBeingAttacked = not pcall(string.dump, os.computerID)
os.computerID = old
which can be countered by:
local oldGetID, oldDump = os.computerID, string.dump
function os.computerID() return 42 end
local ourComputerID = os.computerID
function string.dump(f)
if f == ourComputerID then error("dan200.computer.core.LuaJLuaMachine$2 cannot be cast to org.luaj.vm2.LuaClosure", 0) end
return oldDump(f)
end
which can be countered by:
local isBeingAttacked = pcall(string.dump, string.dump)
which can be countered by:
...etc
This could go on for a while. Eventually, the attacker will win. If a sufficiently determined attacker has full access to the computer running your program, they will always win, and there is nothing you can do about it.
Of course, maybe this has nothing to do with security. If you're
not trying to defend against sufficiently determined attackers, this should do:
local isComputerIDOverridden = pcall(string.dump, os.computerID)