Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Hooking WinAPI without detours?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sat Jan 14, 2017 12:46 pm    Post subject: Reply with quote

Go old school
Code:

** VirtualProtect **

you pretty much can find it everywhere online

_________________
Stylo
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8517
Location: 127.0.0.1

PostPosted: Sat Jan 14, 2017 2:35 pm    Post subject: Reply with quote

Look into how to hook an IAT/EAT entry to do pointer hooks rather than full blown detours, which is what it looks like you are trying to do.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8517
Location: 127.0.0.1

PostPosted: Sat Jan 14, 2017 6:23 pm    Post subject: Reply with quote

There are tons of examples of doing it online, just Google for it.
_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8517
Location: 127.0.0.1

PostPosted: Sun Jan 15, 2017 3:29 am    Post subject: Reply with quote

You are doing things entirely wrong, more or less because you don't understand what you are doing.

Firstly, DispatchMessageA is an API call, it is not going to be specifically at address 0x029F8654. It is an API so it is going to be within its parents module space. For DispatchMessageA, its within User32.dll. If you want to get its address specifically, use GetProcAddress.

If you want to hook it you are going to need to mimic what detours do, or create a hook-hop type of hook.
(Also known as a mid-function hook.)

Doing that, you place a jump at the start of the API (or mid-function hence the name) and jump to your own code. You need to restore the original code, realign the stack as needed, do whatever you want to in your hook, realign the stack again if needed and jump back if desired.

Here is a small tutorial someone did explaining mid-function hooks somewhat:
https://www.unknowncheats.me/forum/c-and-c/67884-mid-function-hook-big-deal.html

There are a handful of other tutorials on the net explaining this in better detail, I recommend you read up on what you are trying to do first as you are doing it wrong.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8517
Location: 127.0.0.1

PostPosted: Sun Jan 15, 2017 1:56 pm    Post subject: Reply with quote

aasdf wrote:
I wasn't clear, but it is a pointer that points to DispatchMessageA function.

Edit: I also do not want to use __asm.


You are literally going to be recoding a detours based library then..

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Dark Byte
Site Admin
Reputation: 458

Joined: 09 May 2003
Posts: 25288
Location: The netherlands

PostPosted: Sun Jan 15, 2017 9:12 pm    Post subject: Reply with quote

When you call DispatchMessageA you are calling the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
Which calls the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
Which calls the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
Which calls the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
Which calls the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
Which calls the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
Which calls the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
Which calls the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
Which calls the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
Which calls the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
Which calls the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
Which calls the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
Which calls the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
Which calls the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
Which calls the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
Which calls the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
Which calls the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
Which calls the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
Which calls the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
Which calls the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
Which calls the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
Which calls the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
Which calls the hooked version of dispatchMessageA, which jumps to DispatchMessageA_Hook
till you run out of stack and crash

You need to store the original code somewhere, with some extra code so it jumps back to after the hook. Then call that instead of DispatchMessageA

Tip: Add a disassembler to your code to figure out the size of the instructions you're overwriting and where to place the jmp back

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites