作者: luckiejacky 時間: 2016-8-26 11:05 標題: 個hook function run左4000 iterations,然後crash?
本帖最後由 luckiejacky 於 2016-8-26 11:07 編輯
我已save左所有register before entry
restore when exit
應該可以同平時一樣禁行?
我用minhook
應該中間D functions改左個stack frame?
https://github.com/TsudaKageyu/minhook
- char __fastcall hooked_game_thunk(void* a1, void* a2)
- {
- try {
- __asm {
- pushad
- }
- DWORD mess = ((struct game_message*)a2)->Message_Base;
- stringstream oss;
- oss << mess << endl;
- logfile2->shared_print(0, oss.str());
- __asm {
- popad
- }
- return original_game_thunk(a1, a2);
- }
- catch (std::exception e)
- {
- MessageBox(0, e.what(), e.what(), 0);
- return 0;
- }
- }
作者: luckiejacky 時間: 2016-8-26 15:15
有冇CHING知為何會throw exception, 如果無任何instruction
在subroutine start 去到tramp(a1,a2)
個program唔會crash,但一加一個MessageBox就會crash
- char __fastcall hooked_game_thunk(void* a1, void* a2)
- {
- 5C56C9D0 push ebp
- 5C56C9D1 mov ebp,esp
- 5C56C9D3 sub esp,0D8h
- 5C56C9D9 push ebx
- 5C56C9DA push esi
- 5C56C9DB push edi
- 5C56C9DC push ecx
- 5C56C9DD lea edi,[ebp-0D8h]
- 5C56C9E3 mov ecx,36h
- 5C56C9E8 mov eax,0CCCCCCCCh
- 5C56C9ED rep stos dword ptr es:[edi]
- 5C56C9EF pop ecx
- 5C56C9F0 mov dword ptr [a2],edx
- 5C56C9F3 mov dword ptr [a1],ecx
-
- //Assembly
- __asm
- {
- push 0
- 5C56C9F6 push 0
- push eax
- 5C56C9F8 push eax
- push eax
- 5C56C9F9 push eax
- push 0
- 5C56C9FA push 0
- call MessageBox
- 5C56C9FC call dword ptr [__imp__MessageBoxA@16 (5C58636Ch)]
-
- }
-
-
- return tramp(a1, a2);
- 5C56CA02 mov esi,esp
- 5C56CA04 mov edx,dword ptr [a2]
- 5C56CA07 mov ecx,dword ptr [a1]
- 5C56CA0A call dword ptr [tramp (5C585174h)]
- 5C56CA10 cmp esi,esp
- 5C56CA12 call __RTC_CheckEsp (5C56159Bh)
- }
作者: luckiejacky 時間: 2016-8-26 15:39
Okay, this works
- __asm
- {
-
- pushad
- push 0
- push eax
- push eax
- push 0
- // stdcall, callee cleans up
- call MessageBox
-
- popad
- }
-
-
- // pass on stack, so wrong, must be passed on registers
- return tramp();
