有时候需要在Lua脚本中嵌入二进制文件,在需要的时候把文件释放出来进行加载
先写个python脚本将二进制文件转换为数组
import struct
f = 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()
end
end
本文介绍了一种使用Python脚本将二进制文件转换为数组的方法,并展示了如何在Lua脚本中嵌入这些二进制数据,以便在运行时释放并加载成原始文件。
8870

被折叠的 条评论
为什么被折叠?



