【问题标题】:Lua scripts stored in memory存储在内存中的 Lua 脚本
【发布时间】:2014-01-13 18:08:09
【问题描述】:

我遇到了 lua 的问题,

每次我执行一个函数/命令甚至定义一个变量时,所有的东西都会作为字符串存储在内存中。

并且可以通过 Cheat Engine 或 HxD 等程序读取

例如

 x = 'Test'

如果我搜索字符串 x = ' 我将能够从内存中提取整个命令。 函数也一样

function Test()
   print(1);
end

搜索 Test() 将允许我获取整个函数脚本。

这是一个示例图片 http://i40.tinypic.com/6oh281.png

正如您在 Memory Viewer 窗口底部看到的那样,有整个函数信息。

现在如何防止 lua 在内存中创建脚本的“额外”副本? Garbagecollector 不会将其清除。

欢迎任何防止这种情况的解决方案或想法。

【问题讨论】:

  • 我相信 JIT 总是这样做...
  • “防止额外的副本”是什么意思?您只想加载脚本一次吗?
  • 无论如何我都看不到图像。你能把它上传到别的地方吗?
  • 抱歉耽搁了,在右下角,您可以将 Lua 函数作为纯文本查看,所以我的意思是额外的副本,避免脚本在内存中的任何地方作为纯文本可见..

标签: lua


【解决方案1】:

我不确定您的意思,但请尝试 luaL_loadbuffer(L,script,strlen(script),”=noname”) 加载脚本。如果您使用luaL_dostring,则整个脚本将保存为其自己的名称。

另请注意,您可以加载一个脚本并多次运行它,而无需再次加载。

【讨论】:

    【解决方案2】:

    您根本不需要加载脚本的 Lua 源代码。使用luac -s 预编译脚本。当然,Lua 字节码和字符串仍然可以在内存中访问,并且很容易找到。

    更新

    luac 的输出是二进制形式的脚本。像 Lua 脚本一样使用它。您可以将其与loadstring、loadfile 等一起使用。

    制作你的 test.lua:

    print("testing")
    

    测试:

    luac -o test.lub -s test.lua
    lua test.lua
    lua test.lub
    

    查看您公开的内容与 Lua 源代码:

    luac -l test.lub
    

    【讨论】:

    • lua 脚本存储在我的服务器上(为了避免用户下载每个更新,因为应用程序是 1 个单独的独立 .exe)。
    【解决方案3】:

    默认情况下,lua 将 key(x) 存储为字符串,并将值存储为内存中的对象,除了管理脚本和仅将值存储在块中之外,您无能为力。不过,这种方式可以被作弊引擎检测到,但它比默认方式安全得多。

    safe.lua:

    local protected = {}
    
    protected.x = "Test"
    
    safe = {}
    
    function safe.Get(pass, val)
        if pass == "0x012345" then
             if not protected[val] then return nil end
             return protected[val]
        end
        return nil
    end
    
    function safe.Set(pass, val, key)
        if not pass == "0x012345" then return end
        protected[val] = key
    end
    
    function safe.Remove(pass, val)
         if not pass == "0x012345" then return end
         if not protected[val] then return end
         protected[val] = nil
     end
    

    test.lua:

    safe.Set("0x012345", "b", {C = "111"})
    print(safe.Get("0x012345", "b").C)
    

    如果您想为每个键使用自定义通行证,请使用此 safe.lua:

    local protected = {}
    
    safe = {}
    
    function safe.Get(pass, val)
        if protected[val] then
             if not protected[val][pass] then return nil end
             return protected[val][pass]
        end
        return nil
    end
    
    function safe.Set(pass, val, key)
        protected[val] = {}
        protected[val][pass] = key
    end
    
    function safe.Remove(pass, val)
         if not protected[val] then return end
         if not protected[val][pass] then return end
         protected[val][pass] = nil
    end
    

    和 test.lua:

    safe.Set("tsting", "x", "keey")
    print(safe.Get("tsting", "x"))
    print(safe.Get("testing", "x"))
    

    【讨论】:

    • 请检查我在 Lua 引擎函数 test() print(1) 中写的图像 end 我使用了内存浏览工具,我能够读取函数本身。还有那个获取变量或对象的方法,我已经在用了。我想出了更好的方法;)
    猜你喜欢
    • 2018-11-20
    • 2015-10-10
    • 1970-01-01
    • 2012-03-29
    • 2020-11-25
    • 1970-01-01
    • 2022-01-18
    • 2017-05-21
    • 2017-09-08
    相关资源
    最近更新 更多