admin管理员组文章数量:1355093
I program in Lua and I need some help:
I have file1.lua and file2.lua
In file1.lua:
loadstring('print("Hello World!")')
in file2.lua:
_loadstring = loadstring
function loadstring(code)
iprint("The code is:", code)
return _loadstring(code)()
end
Basically, file2.lua allows me to see the code that is being passed inside the loadstring. Would it be possible for me to COMPLETELY BLOCK modification of the loadstring function? So that it cannot be accessed/intercepted in other places?
I want to ensure security when executing client-side code, but if I cannot block this interception it will be difficult because I intend to encrypt the code, decrypt it and put a loadstring for it to work.
EDIT:
I'm still looking for alternatives and I thought of something:
It's like my code starts like this:
_loadstring = loadstring
function loadstring(code)
iprint("The code is:", code)
return _loadstring(code)()
end
loadstring('print("Hello World!")')
Can't I guarantee that the second loadstring called is the Lua loadstring? Force it to use the exact Lua loadstring instead of any other?
I program in Lua and I need some help:
I have file1.lua and file2.lua
In file1.lua:
loadstring('print("Hello World!")')
in file2.lua:
_loadstring = loadstring
function loadstring(code)
iprint("The code is:", code)
return _loadstring(code)()
end
Basically, file2.lua allows me to see the code that is being passed inside the loadstring. Would it be possible for me to COMPLETELY BLOCK modification of the loadstring function? So that it cannot be accessed/intercepted in other places?
I want to ensure security when executing client-side code, but if I cannot block this interception it will be difficult because I intend to encrypt the code, decrypt it and put a loadstring for it to work.
EDIT:
I'm still looking for alternatives and I thought of something:
It's like my code starts like this:
_loadstring = loadstring
function loadstring(code)
iprint("The code is:", code)
return _loadstring(code)()
end
loadstring('print("Hello World!")')
Can't I guarantee that the second loadstring called is the Lua loadstring? Force it to use the exact Lua loadstring instead of any other?
Share Improve this question edited Apr 2 at 16:19 Nifim 5,0212 gold badges15 silver badges35 bronze badges asked Mar 30 at 2:06 kaleb sociaiskaleb sociais 11 bronze badge 3 |1 Answer
Reset to default 0It sounds like you may not need to as long as you're executing loadstring
server-side (if someone is overriding your loadstring at that point they already have the keys to the kingdom)
Nearest thing you can get is namespacing your function to a table and overriding __newindex
local l = {}
local set = false
l = setmetatable(l, {
__newindex = function(t, key, value)
if key == 'oadstring' then
if set == false then
set = true
t[k] = value
else
print('stop!')
end
end
end
})
function l.oadstring() end # Set once
function l.oadstring() print('overridden') end
# stop!
l.oadstring = function() print('overridden') end
# stop!
At which point someone would have to replace the l
table to redefine the function and inject their version in every file that relies on it without breaking anything (but, again, I don't think you need to do this).
本文标签: luaHow to block functions from being overwrittenStack Overflow
版权声明:本文标题:lua - How to block functions from being overwritten? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743998677a2573457.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
loadstring()
to execute user's code, and does that userrequire()
your code, so that you are afraid that, beforerequire()
the user will redefineloadstring()
? – Alexander Mashin Commented Mar 31 at 17:41