- 注册时间
- 2011-8-8
- 最后登录
- 1970-1-1
该用户从未签到
|
捡个软柿子来说:
LUA的注册函数为:
lua_register(L, "funcname", func);
参数1为:lua_State*
参数2为:导出的接口名称,脚本里就可以使用此名字了
参数3为:该函数的代码位置
一般用OD逆出来大概就是这样:
004AE4A3 6A 00 PUSH 0
004AE4A5 68 00BF4E00 PUSH 4EBF00
004AE4AA 68 94D9CD00 PUSH 0CDD994 ; ASCII "AutoSelectTarget"
004AE4AF 8D4D D0 LEA ECX, [EBP-30] *** lua_State*
004AE4B2 E8 89A26D00 CALL 00B88740 ; khan.?Register@LuaObject@LuaPlus@@QAEXPBDP6AHPAVLuaState@2@@ZH@Z
最起码也会象这样:
.data:004F5550 dd offset aIsplayer ; "IsPlayer"
.data:004F5554 dd offset sub_415C70
.data:004F5558 dd offset aGetscene ; "GetScene"
.data:004F555C dd offset sub_4230C0
.data:004F5560 dd offset aGetplayer ; "GetPlayer"
.data:004F5564 dd offset sub_423170
.data:004F5568 dd offset aGetnpc ; "GetNpc"
.data:004F556C dd offset sub_423210
至于到底谁的函数跟随哪个函数名的,人眼识别下就好了。
我们先看"GetPlayer"的代码位置是423170 --->>>
.text:00423170 sub_423170 proc near ; DATA XREF: .data:004F5564o
.text:00423170
.text:00423170 var_A = word ptr -0Ah
.text:00423170 var_8 = qword ptr -8
.text:00423170 arg_0 = dword ptr 4 ************ 在LUA的函数中,这种参数意义不大
.text:00423170
.text:00423170 sub esp, 0Ch
.text:00423173 push esi
.text:00423174 mov esi, [esp+10h+arg_0]
.text:00423178 push edi
.text:00423179 push esi
.text:0042317A xor edi, edi
.text:0042317C call lua_gettop ***检测LUA堆栈数量
.text:00423181 add esp, 4
.text:00423184 cmp eax, 1 ***
.text:00423187 jz short loc_4231B0 ****结合cmp eax,1后理解为:必须是一个参数,不可少,不可多
.text:00423189 push offset aKscriptfunc_96 ; "KScriptFuncList::LuaGetPlayer"
.text:0042318E push 0DBh
.text:00423193 push offset aNretcode1 ; "nRetCode == 1"
.text:00423198 push offset aKglog_process_ ; "KGLOG_PROCESS_ERROR(%s) at line %d in %"...
.text:0042319D push 7
.text:0042319F call ds:?KGLogPrintf@@YAHW4KGLOG_PRIORITY@@QBDZZ ; KGLogPrintf(KGLOG_PRIORITY,char const * const,...)
.text:004231A5 add esp, 14h
.text:004231A8
.text:004231A8 loc_4231A8: ; CODE XREF: sub_423170+81j
.text:004231A8 ; sub_423170+86j
.text:004231A8 mov eax, edi
.text:004231AA pop edi
.text:004231AB pop esi
.text:004231AC add esp, 0Ch
.text:004231AF retn
.text:004231B0 ; ---------------------------------------------------------------------------
.text:004231B0
.text:004231B0 loc_4231B0: ; CODE XREF: sub_423170+17j
.text:004231B0 push 1
.text:004231B2 push esi
.text:004231B3 call lua_tonumber ***取出堆栈里的数值转成个整数
.text:004231B8 fnstcw [esp+1Ch+var_A] ***LUA的数据类型一般是浮点型的,[esp+1Ch+var_A]得到具体数值, 想想应该就是人物结构的ID号吧
.text:004231BC movzx eax, [esp+1Ch+var_A]
.text:004231C1 mov ecx, dword_504450 **** 全局变量 dword_504450
.text:004231C7 or eax, 0C00h
.text:004231CC mov dword ptr [esp+1Ch+var_8], eax
.text:004231D0 add esp, 8
.text:004231D3 add ecx, 4D98h **省略分析-_-
.text:004231D9 fldcw word ptr [esp+14h+var_8]
.text:004231DD fistp [esp+14h+var_8]
.text:004231E1 mov eax, dword ptr [esp+14h+var_8]
.text:004231E5 push eax ***sub_413160 函数用的一个参数
.text:004231E6 fldcw [esp+18h+var_A]
.text:004231EA call sub_413160 ******** 根据ID遍历人物结构指针出来
.text:004231EF test eax, eax
.text:004231F1 jz short loc_4231A8
.text:004231F3 cmp [eax+48h], edi ***不为0? 则EAX返回人物结构了
.text:004231F6 jz short loc_4231A8
.text:004231F8 push esi
.text:004231F9 mov ecx, eax
.text:004231FB call sub_4156C0 ***这是个LUA的其他操作了,不管它
.text:00423200 pop edi
.text:00423201 pop esi
.text:00423202 add esp, 0Ch
.text:00423205 retn
.text:00423205 sub_423170 endp
再看个"IsPlayer",代码位置是415C70 --->>>
.text:00415C70 sub_415C70 proc near ; DATA XREF: .data:004F5554o
.text:00415C70
.text:00415C70 var_A = word ptr -0Ah
.text:00415C70 var_8 = qword ptr -8
.text:00415C70 arg_0 = dword ptr 4
.text:00415C70
.text:00415C70 sub esp, 0Ch
.text:00415C73 push esi
.text:00415C74 mov esi, [esp+10h+arg_0]
.text:00415C78 push edi
.text:00415C79 push esi
.text:00415C7A xor edi, edi
.text:00415C7C call lua_gettop
.text:00415C81 add esp, 4
.text:00415C84 cmp eax, 1 ********* 和"GetPlayer"完全一样
.text:00415C87 jz short loc_415CB0
.text:00415C89 push offset aKscriptfunc_47 ; "KScriptFuncList::LuaIsPlayer"
.text:00415C8E push 0B2h
.text:00415C93 push offset aLua_gettopin_1 ; "Lua_GetTopIndex(L) == 1"
.text:00415C98 push offset aKglog_process_ ; "KGLOG_PROCESS_ERROR(%s) at line %d in %"...
.text:00415C9D push 7
.text:00415C9F call ds:?KGLogPrintf@@YAHW4KGLOG_PRIORITY@@QBDZZ ; KGLogPrintf(KGLOG_PRIORITY,char const * const,...)
.text:00415CA5 add esp, 14h
.text:00415CA8 mov eax, edi
.text:00415CAA pop edi
.text:00415CAB pop esi
.text:00415CAC add esp, 0Ch
.text:00415CAF retn
.text:00415CB0 ; ---------------------------------------------------------------------------
.text:00415CB0
.text:00415CB0 loc_415CB0: ; CODE XREF: sub_415C70+17j
.text:00415CB0 push 1
.text:00415CB2 push esi
.text:00415CB3 call lua_tonumber ****具体OD动态跟踪下看下是什么参数吧
.text:00415CB8 fnstcw [esp+1Ch+var_A]
.text:00415CBC movzx eax, [esp+1Ch+var_A]
.text:00415CC1 or eax, 0C00h
.text:00415CC6 mov dword ptr [esp+1Ch+var_8], eax
.text:00415CCA fldcw word ptr [esp+1Ch+var_8]
.text:00415CCE fistp [esp+1Ch+var_8]
.text:00415CD2 mov eax, dword ptr [esp+1Ch+var_8]
.text:00415CD6 and eax, 0F0000000h ****
.text:00415CDB neg eax **** IsPlayer的判断依据
.text:00415CDD fldcw [esp+1Ch+var_A]
.text:00415CE1 sbb eax, eax
.text:00415CE3 add eax, 1
.text:00415CE6 push eax *****判断结果,是还是不是?
.text:00415CE7 push esi
.text:00415CE8 call lua_pushboolean ****将结果放入堆栈
.text:00415CED add esp, 10h
.text:00415CF0 pop edi
.text:00415CF1 mov eax, 1
.text:00415CF6 pop esi
.text:00415CF7 add esp, 0Ch
.text:00415CFA retn
.text:00415CFA sub_415C70 endp
伪脚本大概象这样: local isP = IsPlayer(参数);
isP的值就是 lua_pushboolean 放入的结果
静态分析LUA函数就是这样子了,展开下联想联系各个环节,很方便的找出有用的信息来 |
|