Skip to content

Commit

Permalink
代码加密支持
Browse files Browse the repository at this point in the history
  • Loading branch information
huahua132 committed Oct 15, 2024
1 parent 2d8b4a7 commit d8a58a7
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ test/make
3rd/zlib/zconf.h
3rd/zlib/zlib.pc

3rd/zlib/zlib.a

5 changes: 0 additions & 5 deletions 3rd/zlib/Makefile

This file was deleted.

1 change: 0 additions & 1 deletion 3rd/zlib/libz.a

This file was deleted.

15 changes: 15 additions & 0 deletions binshell/make_encrycode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash
#lua代码加密

skynet_fly_path=$1
key=$2
targetpath=$3

if [ "$#" -lt 2 ]; then
echo "请输入2个参数 skynet_fly_path and key"
exit 1
fi

shell_path="${skynet_fly_path}/script/shell"

bash ${shell_path}/make_encrycode.sh ${skynet_fly_path} ${key} ${targetpath}
4 changes: 3 additions & 1 deletion binshell/make_release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ targetpath=./skynet-fly-release
# 删除已有目标路径并新建目录
rm -rf ${targetpath}
mkdir -p ${targetpath}/skynet/3rd
mkdir -p ${targetpath}/skynet/3rd/lua

# 复制 skynet_fly 相关文件和目录

Expand All @@ -29,5 +30,6 @@ mkdir -p ${targetpath}/skynet # 确保 skynet 目录存在
# 复制 c 相关的文件和目录
[ -f "skynet/skynet" ] && cp skynet/skynet ${targetpath}/skynet/skynet
[ -d "skynet/luaclib" ] && cp -r skynet/luaclib ${targetpath}/skynet/luaclib
[ -d "skynet/3rd/lua" ] && cp -r skynet/3rd/lua ${targetpath}/skynet/3rd/lua
cp skynet/3rd/lua/lua ${targetpath}/skynet/3rd/lua/lua
cp skynet/3rd/lua/liblua.a ${targetpath}/skynet/3rd/lua/liblua.a
[ -d "skynet/cservice" ] && cp -r skynet/cservice ${targetpath}/skynet/cservice
65 changes: 65 additions & 0 deletions script/lua/encrycode.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
local assert = assert
local ARGV = { ... }
local skynet_fly_path = ARGV[1]
local key = ARGV[2]
local targetpath = ARGV[3]
assert(skynet_fly_path, '缺少 skynet_fly_path')
assert(key, "缺少 key")
assert(key:len() == 8, "key 长度不对 ".. key)

local skynet_path = skynet_fly_path .. '/skynet'

package.cpath = skynet_fly_path .. "/luaclib/?.so;" .. skynet_path .. '/luaclib/?.so;'
package.path = './?.lua;' .. skynet_fly_path .. "/lualib/?.lua;"

if not targetpath then
targetpath = './encrycode/'
end

if not os.execute("mkdir -p " .. targetpath) then
error("create targetpath err")
end

local file_util = require "skynet-fly.utils.file_util"
local table_util = require "skynet-fly.utils.table_util"
local crypt = require "client.crypt"

targetpath = file_util.path_join(targetpath, '/')

local sfind = string.find
local sgsub = string.gsub
local loadfile = loadfile
local sdump = string.dump
local io = io

local cmd = string.format("cp -r %s %s", './', targetpath)
if not os.execute(cmd) then
error("cp err ", cmd)
end

for file_name, file_path, file_info in file_util.diripairs('./') do
if sfind(file_name, '.lua', nil, true) and not sfind(file_path, './encrycode/', nil, true) and not sfind(file_path, './make/', nil, true) then
local code_func = loadfile(file_path)
if not code_func then
print("can`t loadfile >>> ", file_path)
else
local code_str = string.dump(code_func)
local encode_str = crypt.desencode(key, code_str)
local new_path = sgsub(file_path, './', targetpath, 1)
local dir_path = sgsub(new_path, file_name, '', 1)
if not os.execute("mkdir -p " .. dir_path) then
print("create dir_path err ", dir_path)
else
local newfile = io.open(new_path, "w+")
if not newfile then
print("can`t openfile >>> ", new_path)
else
newfile:write(encode_str)
newfile:close()
print("encry file succ:", new_path)
loadfile(new_path) --测试加载
end
end
end
end
end
10 changes: 10 additions & 0 deletions script/shell/make_encrycode.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

skynet_fly_path=$1
key=$2
targetpath=$3

lua=""${skynet_fly_path}"/skynet/3rd/lua/lua"
script_path="${skynet_fly_path}/script/lua"

${lua} ${script_path}/encrycode.lua ${skynet_fly_path} ${key} ${targetpath}
2 changes: 1 addition & 1 deletion skynet

0 comments on commit d8a58a7

Please sign in to comment.