Hook This !
Library for coders
Ok this is a simple, fast and modeable procedure that allows you to hook your own procedure in any part of code.
Yeah you hear well forgget about opening Ollydbg, make JMPs to other part of code for call your DLL and late restore them.
This fuction does it all, you can hook in any place of any program and without getting any error or modification of the actual code.
But what this means? lets see a example:
This is a part of a "X" program, after hooking with my fuction it will look like this:Code:00401087 . 68 B80B0000 PUSH 0BB8 ; |ControlID = BB8 (3000.) 0040108C . FF75 08 PUSH DWORD PTR SS:[EBP+8] ; |hWnd 0040108F . E8 6A010000 CALL <JMP.&user32.SetDlgItemTextA> ; \SetDlgItemTextA
Yeah a call to your own procedure, and next when you dont need anymore you can call my fuction again and will look just like the original code:Code:0040106B . E8 9D41C00F CALL IndigoGS.1000520D ; |Message 00401070 . E8 83010000 CALL <JMP.&user32.SendMessageA> ; \SendMessageA
This library support MASM32 and C++ compilator and its open source.Code:00401087 . 68 B80B0000 PUSH 0BB8 ; |ControlID = BB8 (3000.) 0040108C . FF75 08 PUSH DWORD PTR SS:[EBP+8] ; |hWnd 0040108F . E8 6A010000 CALL <JMP.&user32.SetDlgItemTextA> ; \SetDlgItemTextA
How use it:
First add into your source the Include file and the Library
Now you just need to call my library in your DLL or EXE program like this:
So in the first argument we have the addr of the part where we need to hook, the second argument we have the addr of our procedure when it needs to be called and last argument its the ID of the current hook we made, in this case 1.Code:MASM32: invoke HookThis, 0040106Bh, Offset MyProcedure, 1 C++: HookThis(0040106B, MyProcedure, 1) Resumed: HookThis(HookOffset, MyProcedure, ID)
Once the hooked code call your procedure you can do anything has usual, but just remember before exit your procedure call this:
And thats all, the flow of execution will continue like nothing happen.Code:MASM32: invoke UnHookThis, 0040106B, 1 C++: UnHookThis(0040106B, 1) Resumed: UnHookThis(HookedOffset, ID)
Limitations:
The only limitation is that you can only do 100 hooks, but i can expand to much more if you need, also its open source and you can do yourself.
Extras:
I can expand the fuction for you to choose between make a CALL to your procedure or a JUMP to a portion of code, but i will make this later in other update.
Example:
Here another example how hooking your DLL with just using LoadLibrary, forget about using GetProcAddress and waist resource time:Code:Invoke HookThis, 00401064h, Offset MyProcedure1, 1 Invoke HookThis, 00401074h, Offset MyProcedure2, 2 Invoke HookThis, 00401094h, Offset MyProcedure3, 3 MyProcedure1 Proc ;DO ALL YOU WANT HERE invok UnHookThis, 00401064, 1 MyProcedure1 Endp MyProcedure2 Proc ;DO ALL YOU WANT HERE invok UnHookThis, 00401074, 2 MyProcedure2 Endp MyProcedure3 Proc ;DO ALL YOU WANT HERE invok UnHookThis, 00401094, 3 MyProcedure3 Endp
After DLL is loaded the CALL to InitAll procedure will be created down of the LoadLibrary call and we wont have to call GetProcAddress ^^.Code:In hooked program: 0041000: invoke LoadLibrary, "MyDLL" 0041005: Other instructions In our DLL: DllEntry Proc hInst:HINSTANCE, reason:DWord, reserved1:DWord .if (reason == DLL_PROCESS_ATTACH) invoke HookThis, 0041005h, Offset InitAll, 1 .endif mov eax, TRUE ret DllEntry EndP
Enjoy, source code + Library + Include file in attachment.
Credits: [INDG]FeN$x



Reply With Quote


