├── Lua └── hookFuncTool.lua └── README.md /Lua/hookFuncTool.lua: -------------------------------------------------------------------------------- 1 | bs = print 2 | funcTable = {} 3 | for k, v in pairs(_ENV) do 4 | if (type(v) == 'function') then 5 | funcTable[#funcTable + 1] = k 6 | end 7 | if (type(v) == 'table' and k ~= 'package' and k ~= '_G' and k ~= 'funcTable') then 8 | for key, value in pairs(_ENV[k]) do 9 | funcTable[#funcTable + 1] = k .. '.' .. key 10 | end 11 | end 12 | end 13 | 14 | function saveCallFunc(...) 15 | n = n + 1 16 | if (debug.getinfo(3).name == 'dofile' and isDofile == nil) then 17 | isDofile = true 18 | return 0 19 | end 20 | if (debug.getinfo(3).name == 'sethook' and isSetHook == nil) then 21 | isSetHook = true 22 | return 0 23 | end 24 | funcTable[#funcTable + 1] = debug.getinfo(3).name 25 | end 26 | 27 | function runScriptMenu() 28 | local file = gg.prompt({'运行脚本路径'},{'/sdcard/'},{'file'}) 29 | if (file) then 30 | if (io.open(file[1]) == nil) then 31 | gg.alert('文件不存在或无访问权限') 32 | return 0 33 | end 34 | if (loadfile(file[1]) == nil) then 35 | gg.alert('脚本编译错误') 36 | return 0 37 | end 38 | pathname = file[1] 39 | pathname2 = file[1] 40 | end 41 | end 42 | 43 | function getFunc() 44 | if (pathname == nil) then 45 | gg.alert('未设置脚本') 46 | return 0 47 | end 48 | debug.sethook(saveCallFunc, 'c') 49 | dofile(pathname) 50 | debug.sethook() 51 | gg.alert('获取完毕') 52 | table.sort(funcTable) 53 | end 54 | 55 | function chooseHookFunc() 56 | local chooseFunc = {} 57 | if (pathname == nil) then 58 | gg.alert('未设置脚本') 59 | return 0 60 | end 61 | local SN = gg.multiChoice(funcTable, nil, '请选择要hook的func') 62 | if (SN) then 63 | for k, v in pairs(SN) do 64 | if (v == true) then 65 | chooseFunc[#chooseFunc + 1] = funcTable[k] 66 | end 67 | end 68 | io.open('/sdcard/tmp.tmp', 'w') 69 | files = io.open('/sdcard/tmp.tmp', 'a+') 70 | for k, v in ipairs(chooseFunc) do 71 | writeNewFunc(v) 72 | end 73 | end 74 | end 75 | 76 | function writeNewFunc(func) 77 | while true do 78 | ::last:: 79 | local hook = gg.prompt({'请输入要Hook的代码\n当前函数: ' .. func, '是否输出参数'}, {'return', false}, {'text', 'checkbox'}) 80 | if (hook) then 81 | if (hook[2]) then 82 | files:write('function ' .. func .. '(...)\nbs(...)\n' .. hook[1] .. '\nend\n') 83 | else 84 | files:write('function ' .. func .. '(...)\n' .. hook[1] .. '\nend\n') 85 | end 86 | if (loadfile('/sdcard/tmp.tmp') == nil) then 87 | gg.alert('代码编写错误,清重写编写') 88 | io.open('/sdcard/tmp.tmp', 'w') 89 | goto last 90 | else 91 | dofile('/sdcard/tmp.tmp') 92 | dofile(pathname) 93 | break 94 | end 95 | end 96 | end 97 | end 98 | local pathname 99 | pathname2 = '无' 100 | n = 1 101 | function main() 102 | local SN = gg.choice({ 103 | '获取函数', 104 | '设置脚本', 105 | 'hook函数', 106 | '退出脚本' 107 | }, nil, 'By.Sakuras\n当前设置运行脚本为: ' .. pathname2) 108 | if (SN == nil) then 109 | else 110 | if (SN == 1) then 111 | getFunc() 112 | elseif (SN == 2) then 113 | runScriptMenu() 114 | elseif (SN == 3) then 115 | chooseHookFunc() 116 | else 117 | os.exit() 118 | end 119 | end 120 | end 121 | 122 | gg.showUiButton() 123 | while true do 124 | if (gg.isClickedUiButton()) then 125 | main() 126 | end 127 | end -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GameGuardian-Lua-hook-function-tool 2 | 用于Hook GameGuardian Lua脚本函数的工具 3 | # 使用教程 4 | 进入脚本主页,选择要hook的脚本,然后进入hook选择函数页面,然后会自动运行脚本 5 | # hook脚本内声明函数 6 | 选择第一个获取函数,再进入hook函数页面 7 | --------------------------------------------------------------------------------