zoukankan      html  css  js  c++  java
  • 【转】UNITY之LUA加密

    来自:Lua加密

    两种方式:一种用luac,一种用luajit

    luac加密:

    1、lua本身可以使用luac将脚本编译为字节码(bytecode)从而实现加密,去官网下载Lua源代码包(http://www.lua.org/ftp/),下好解压,目录如下

    2、启动一个Visual Studio 命令行工具,用32位命令行会生成32位版本,用64位则生成64位版本

    3、在命令行中使用cd 进入lua目录(刚才解压后的目录),然后输入 "etcluavs.bat" 回车

    4、如果没有问题的话,会显示生成过程,(64位下还会有几个warning C4334)、完成后会在src目录下找到生成结果,4个主要文件一个.exp的中间文件,luac.exe生成完毕,

        然后把luac.exe所在存在的目录设为环境变量,如果不设置的话,那么执行生成字节码的dos命令的时候就要转到luac.exe所在的目录才能执行此dos命令了,都懂得,不多说

    5、(1)、新建一个名为1.lua的文件,里面只有一句话print("Hello Lua"),新建一个空的out.lua脚本文件
        (2)、开始--运行--cmd
        (3)、luac -o out.lua 1.lua
          注: luac -o [编译后脚本名] [脚本名],必要时带上脚本路径,如:

    然后实验一下,执行这个字节码脚本,可以看到lua原生的解释器可以直接解析luac编译出来的bytecode脚本,很方便!

    luajit加密:

    1、官网下载luajit(http://luajit.org/luajit.html),解压,目录如下

    2、在命令行中使用cd 进入luajit下src的目录,然后执行输入msvcbuild.bat,执行此批处理文件,编译出luajit.exe

    3、接下来就可以使用luajit.exe编译lua脚本的bytecode了:luajit -b [脚本名] [编译后的脚本名],执行完后会在src目录下生成一个已经编译成bytecode的lua文件

    此时即使把此路径加入环境变量是没用的,进行luajit加密命令的时候必须使用cd进入此目录(C:UsershengjingjingDesktopLuaJIT-2.0.4src),因为luajit加密,必须是luajit.exe和src下的jit文件夹配合使用才管用!

    如果unity项目用的是基于ulua扩展的其他lua版本(cstolua、slua),或者本身用的就是ulua,那么要用luajit加密方式,因为ulua底层就是用的luajit

    两者比较:

    http://lua-users.org/lists/lua-l/2011-06/msg01052.html

    LuaJIT is open source software, released under the MIT/X license.
    LuaJIT builds out-of-the-box on most x86 or x64 operating systems
    (Linux, Windows, OSX etc.) and can be cross-compiled for embedded
    systems based on ARM or PPC/e500 CPUs.
    The LuaJIT bytecode format is portable and ~40% smaller than Lua
    bytecode. The LuaJIT bytecode loader is 10x faster than the Lua
    bytecode loader. And LuaJIT bytecode loads 30x-40x faster than
    source code. Note that this is unrelated to the _execution_ speed
    of the code itself -- it doesn't matter how the code was loaded.

    可以看出:Luajit跨平台,满足于32位和64位,并且加密后的bytecode比luac生成的bytecode至少小40%,速度也是它的10倍多,总之luajit就是比lua原生的好
  • 相关阅读:
    Java实现 LeetCode 30 串联所有单词的子串
    Java实现 LeetCode 29 两数相除
    Java实现 LeetCode 29 两数相除
    Java实现 LeetCode 29 两数相除
    Java实现 LeetCode 28 实现strStr()
    Java实现 LeetCode 28 实现strStr()
    Java实现 LeetCode 28 实现strStr()
    Java实现 LeetCode 27 移除元素
    Java实现 LeetCode 27 移除元素
    字符编码终极笔记:ASCII、Unicode、UTF-8、UTF-16、UCS、BOM、Endian
  • 原文地址:https://www.cnblogs.com/timeObjserver/p/9479230.html
Copyright © 2011-2022 走看看