Lua脚本中释放binary文件

来源:互联网 发布:汽车pp2000软件下载 编辑:程序博客网 时间:2024/06/05 01:41

有时候需要在Lua脚本中嵌入二进制文件,在需要的时候把文件释放出来进行加载


先写个python脚本将二进制文件转换为数组

import structf = open('function.so', 'rb')fhex = open('hex.txt', 'w')data = f.read()for c in data:    fhex.write(str(struct.unpack('B', c)[0]) + ',')


Lua中的实现如下

fileData={4,0,0,0,0,0,0,0,195,......0,0,0,0,0,0,133,128,1,0,211,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,}function save_so()    local file = io.open("function.so", "wb")    if file then        for i in pairs(fileData) do            file:write(string.char(fileData[i]))        end            file:close()    endend

0 0
原创粉丝点击