cgmsv引擎论坛

 找回密码
 注册/Sign up
搜索
查看: 6107|回复: 3

[LUA] 游戏内直接注册账号的lua

[复制链接]
发表于 2021-7-23 17:53:47 | 显示全部楼层 |阅读模式
直接根据输入的用户名、密码注册新账号并登录,无需开网页注册,只支持cmgsv 21.2a windows版本

accountRegister.zip (1.99 KB, 下载次数: 1)

  1. local ffi = require "ffi";
  2. local FFI = ffi;
  3. --HOOKS
  4. local hook = { hooks = {} }
  5. ffi.cdef [[
  6.     int VirtualProtect(void* lpAddress, unsigned long dwSize, unsigned long flNewProtect, unsigned long* lpflOldProtect);
  7. ]]
  8. function hook.new(cast, callback, hook_addr, size)
  9.   local _size = size or 5
  10.   local new_hook = {}
  11.   local detour_addr = tonumber(ffi.cast('intptr_t', ffi.cast('void*', ffi.cast(cast, callback))))
  12.   local hookFnPtr = ffi.cast('void*', hook_addr)
  13.   local old_prot = ffi.new('unsigned long[1]')
  14.   local old_prot2 = ffi.new('unsigned long[1]')
  15.   local org_bytes = ffi.new('uint8_t[?]', _size + 10)
  16.   ffi.copy(org_bytes, hookFnPtr, _size)
  17.   org_bytes[_size] = 0xE9;
  18.   ffi.cast('uint32_t*', org_bytes + _size + 1)[0] = hook_addr - (ffi.cast('uint32_t', org_bytes) + _size);
  19.   local hook_bytes = ffi.new('uint8_t[?]', _size, 0x90)
  20.   hook_bytes[0] = 0xE9
  21.   ffi.cast('uint32_t*', hook_bytes + 1)[0] = detour_addr - hook_addr - 5
  22.   ffi.C.VirtualProtect(hookFnPtr, _size, 0x40, old_prot)
  23.   ffi.copy(hookFnPtr, hook_bytes, _size)
  24.   ffi.C.VirtualProtect(hookFnPtr, _size, old_prot[0], old_prot2)
  25.   --local orgHookedPtr = ffi.cast(cast, ffi.cast('void*', ffi.cast('uint32_t', org_bytes)));
  26.   --ffi.C.VirtualProtect(org_bytes, _size, old_prot[0], old_prot2)
  27.   new_hook.uninstall = function()
  28.     ffi.C.VirtualProtect(hookFnPtr, _size, 0x40, old_prot)
  29.     ffi.copy(hookFnPtr, org_bytes, _size)
  30.     ffi.C.VirtualProtect(hookFnPtr, _size, old_prot[0], old_prot2)
  31.     hook.hooks[tostring(hook_addr)] = nil;
  32.   end
  33.   new_hook.call = ffi.cast(cast, org_bytes)
  34.   new_hook.org_bytes = org_bytes;
  35.   new_hook.callback = callback;
  36.   hook.hooks[tostring(hook_addr)] = new_hook;
  37.   return setmetatable(new_hook, {
  38.     __call = function(self, ...)
  39.       local res = self.call(...)
  40.       return res
  41.     end
  42.   })
  43. end
  44. ffi.hook = hook;
  45. _G.SQL = _G.SQL or {}
  46. local SQL = _G.SQL;
  47. function SQL.sqlValue(s)
  48.   if s == nil then
  49.     return 'null'
  50.   end
  51.   if type(s) == 'number' then
  52.     return tostring(s)
  53.   end
  54.   if type(s) == 'string' then
  55.     local r = "'"
  56.     for i = 1, string.len(s) do
  57.       local v = string.sub(s, i, i);
  58.       if v == '\\' or v == '\'' then
  59.         r = r .. '\\'
  60.       end
  61.       if not (v == '\n' or v == '\r') then
  62.         r = r .. v;
  63.       end
  64.     end
  65.     return r .. "'";
  66.   end
  67.   return 'null';
  68. end
  69. function SQL.querySQL(sql)
  70.   local result = SQL.Run(sql)
  71.   if type(result) == "table" then
  72.     local res = {}
  73.     local field = tonumber(result.field);
  74.     local row = tonumber(result.row);
  75.     for i = 0, row do
  76.       for j = 0, field do
  77.         res[i + 1] = res[i + 1] or {}
  78.         res[i + 1][j + 1] = result['' .. i .. '_' .. j];
  79.       end
  80.     end
  81.     return res
  82.   end
  83.   return result
  84. end
  85. SQL.CONST_RET_NO_ROW = -3;
  86. local Protocol = { Hooks = {}, _hooked = false }
  87. local _OnDispatch;
  88. local _nrproto_unescapeString = FFI.cast('char* (__cdecl *)(const char* str)', 0x00559040)
  89. ---封包字符串解密
  90. function Protocol.nrprotoUnescapeString(str)
  91.   return FFI.string(_nrproto_unescapeString(str));
  92. end
  93. function string.split(str, separator)
  94.   local str = tostring(str)
  95.   local separator = tostring(separator)
  96.   local strB, arrayIndex = 1, 1
  97.   local targetArray = {}
  98.   if (separator == nil)
  99.   then
  100.     return false
  101.   end
  102.   local condition = true
  103.   local si, sd;
  104.   while (condition)
  105.   do
  106.     si, sd = string.find(str, separator, strB)
  107.     if (si)
  108.     then
  109.       targetArray[arrayIndex] = string.sub(str, strB, si - 1)
  110.       arrayIndex = arrayIndex + 1
  111.       strB = sd + 1
  112.     else
  113.       targetArray[arrayIndex] = string.sub(str, strB, string.len(str))
  114.       condition = false
  115.     end
  116.   end
  117.   return targetArray
  118. end
  119. local function OnDispatch(fd, str)
  120.   local s, e = pcall(function()
  121.     local s = FFI.string(str);
  122.     local list = string.split(s, ' ');
  123.     local head = list[1];
  124.     table.remove(list, 1);
  125.     for i = 1, #list do
  126.       list[i] = Protocol.nrprotoUnescapeString(list[i]);
  127.     end
  128.     --print('收到', head, '封包,内容: ', unpack(list))
  129.     if Protocol.Hooks[head] and _G[Protocol.Hooks[head]] then
  130.       local ret = _G[Protocol.Hooks[head]](fd, head, list);
  131.       if type(ret) == 'number' and ret < 0 then
  132.         return -1;
  133.       end
  134.     end
  135.     return _OnDispatch(fd, str);
  136.   end)
  137.   return s and e or _OnDispatch(fd, str);
  138. end
  139. ---拦截封包回调
  140. ---@param Dofile string 加载文件
  141. ---@param FuncName string 回调名字
  142. ---@param PacketID string 封包头
  143. function Protocol.OnRecv(Dofile, FuncName, PacketID)
  144.   if Dofile and _G[FuncName] == nil then
  145.     dofile(Dofile)
  146.   end
  147.   Protocol.Hooks[PacketID] = FuncName;
  148.   if Protocol._hooked == false then
  149.     Protocol._hooked = true;
  150.     _OnDispatch = FFI.hook.new('int (__cdecl *)(uint32_t fd, const char *encoded)', OnDispatch, 0x00551800, 5);
  151.   end
  152. end
  153. local function OnRecv(fd, head, data)
  154.   local user = SQL.querySQL('select * from tbl_user where CdKey = ' .. SQL.sqlValue(data[3]));
  155.   if user == SQL.CONST_RET_NO_ROW then
  156.     local seq = SQL.querySQL('select max(SequenceNumber) + 1 from tbl_user');
  157.     local sql = 'insert into tbl_user (CdKey, SequenceNumber, AccountID, AccountPassWord, '
  158.       .. ' EnableFlg, UseFlg, BadMsg, TrialFlg, DownFlg, ExpFlg) values ('
  159.       .. SQL.sqlValue(data[3]) .. ', ' .. SQL.sqlValue(seq[1][1]) .. ', '
  160.       .. SQL.sqlValue(data[3]) .. ', '
  161.       .. SQL.sqlValue(data[2]) .. ',1,1,0,0,0,0);'
  162.     local r = SQL.querySQL(sql)
  163.   end
  164.   return 0
  165. end
  166. _G.OnRecv = OnRecv;
  167. Protocol.OnRecv(nil, 'OnRecv', 'JFVf')
复制代码




补充内容 (2021-9-12 18:08):
165行更正为
      .. SQL.sqlValue(data[2]) .. ',1,1,0,8,0,0);'

补充内容 (2021-9-14 11:52):
PS: string.split 注意不要被其他脚本覆盖了。不然会崩端

评分

参与人数 1金币 +2 收起 理由
Zack + 2 原创资源贴

查看全部评分

Rank: 4

发表于 2021-7-24 13:04:22 | 显示全部楼层
经测试 确实有效

补充内容 (2021-7-28 11:32):
注意事项:此lua加载成功后不要再次加载,否则崩端

评分

参与人数 1金币 +1 收起 理由
Zack + 1 资源评测奖励

查看全部评分

Rank: 1

发表于 2021-8-13 18:02:39 | 显示全部楼层
感谢分享,很方便
您需要登录后才可以回帖 登录 | 注册/Sign up

本版积分规则

手机版|cgmsv引擎论坛

GMT+8, 2024-11-21 22:40 , Processed in 0.160407 second(s), 11 queries , Gzip On, MemCached On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表