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 


[C++] Hooking API's without touching the actual API

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
kittonkicker
I post too much
Reputation: 1

Joined: 19 Apr 2006
Posts: 2171

PostPosted: Sat Aug 18, 2007 6:56 am    Post subject: [C++] Hooking API's without touching the actual API Reply with quote

I recently made a PE for FlyFF.

Since GalaNet decided to buy into iNCA's Packet Editting protection a LONG time ago, I knew I couldn't modify any packets from outside the game...(so an mIRC scripted proxy is out of the question these days!)

Before I coded it, I decided it would be best to hook into the API's it uses to communicate with the server (in this case WSASend/Recv/Socket).

After a failed attempt at modding the actual API (pwned by GameGuard), I decided to localize my efforts and make the game do it for me ^_^.

If anyone else wants to attempt this, here's a few guidelines for doing what I did.

I dunno if you've noticed in OllyDBG, that when there's a call to an API, for example ReadProcessMemory it'll say something like CALL [&kernel32.ReadProcessMemory]. Well, if you look at the ASM, you can see it's really "call dword ptr [someaddress]". If you go to the "someaddress", you'll either see "DD someapi" OR "jmp dword ptr [someaddress]". If you see "DD someapi", then you can just install your hook there, by changing the "someapi" to "newapi". If you see "jmp dword ptr [someaddress]", then "someaddress" is the address which holds the address of the API you're hooking.

So...you'd change the value of "someaddress" to the address of your "newapi".

You would of course, have to define your own API, which does something, and then returns the value you want it to.

This hooking IS done in the program, not in the imported dll.

A redefined API example:

Code:
DWORD WINAPI _stdcall NewGetTickCount()
{
    return GetTickCount(); //or you might want to always make it return 1 for fun? you'd do that like "return 1;"
}


The hooking code:

Code:
*(DWORD*)AddressWhichHoldsAddressOfOriginalGetTickCount = (DWORD)NewGetTickCount;


Good luck ^_^.


Last edited by kittonkicker on Sat Aug 18, 2007 1:34 pm; edited 1 time in total
Back to top
View user's profile Send private message
UnLmtD
Grandmaster Cheater
Reputation: 0

Joined: 13 Mar 2007
Posts: 894
Location: Canada

PostPosted: Sat Aug 18, 2007 7:16 am    Post subject: Reply with quote

Looks like IAT hooking.
_________________
Back to top
View user's profile Send private message
kittonkicker
I post too much
Reputation: 1

Joined: 19 Apr 2006
Posts: 2171

PostPosted: Sat Aug 18, 2007 7:56 am    Post subject: Reply with quote

'Tis!
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Sat Aug 18, 2007 7:58 am    Post subject: Reply with quote

UnLmtD wrote:
Looks like IAT hooking.


Quote:
Code:
*(DWORD*)AddressWhichHoldsAddressOfOriginalGetTickCount


Kinda gives it away.
Back to top
View user's profile Send private message MSN Messenger
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Sat Aug 18, 2007 9:54 am    Post subject: Reply with quote

I know this may be shocking to you, but you're not the first person in the world to discover this. Microsoft has provided a library for easily doing this for quite some time now.

http://research.microsoft.com/sn/detours/
Back to top
View user's profile Send private message
kittonkicker
I post too much
Reputation: 1

Joined: 19 Apr 2006
Posts: 2171

PostPosted: Sat Aug 18, 2007 10:30 am    Post subject: Reply with quote

Lol appal, I knew that others had done this before.

I didn't know microsoft had an APi that could do it for you though!!
Back to top
View user's profile Send private message
nog_lorp
Grandmaster Cheater
Reputation: 0

Joined: 26 Feb 2006
Posts: 743

PostPosted: Sat Aug 18, 2007 1:29 pm    Post subject: Reply with quote

You cannot dereference a void pointer, since a void holds no data it would be meaningless (null). (also, compiler wouldn't know data size)
_________________
Mutilated lips give a kiss on the wrist of the worm-like tips of tentacles expanding in my mind
I'm fine accepting only fresh brine you can get another drop of this yeah you wish
Back to top
View user's profile Send private message
DeltaFlyer
Grandmaster Cheater
Reputation: 0

Joined: 22 Jul 2006
Posts: 666

PostPosted: Sat Aug 18, 2007 3:10 pm    Post subject: Reply with quote

nog_lorp wrote:
You cannot dereference a void pointer, since a void holds no data it would be meaningless (null). (also, compiler wouldn't know data size)

Who's trying to dereference a void pointer?

_________________

Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for?
Back to top
View user's profile Send private message
appalsap
Moderator
Reputation: 0

Joined: 27 Apr 2006
Posts: 6753
Location: Pakistan

PostPosted: Sat Aug 18, 2007 3:16 pm    Post subject: Reply with quote

DeltaFlyer wrote:
Who's trying to dereference a void pointer?


KittonKicker is.
Back to top
View user's profile Send private message
kittonkicker
I post too much
Reputation: 1

Joined: 19 Apr 2006
Posts: 2171

PostPosted: Sat Aug 18, 2007 3:22 pm    Post subject: Reply with quote

I didn't know you couldn't, I know now though!!
Back to top
View user's profile Send private message
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