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 


Simpler Function Hooks

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Chaosis13
Master Cheater
Reputation: 0

Joined: 14 Aug 2007
Posts: 372

PostPosted: Mon Aug 10, 2009 7:16 pm    Post subject: Simpler Function Hooks Reply with quote

Wouldn't this
Code:
   __asm {
          push eax
          mov eax, [WSASend]
          mov OriginalAddress, eax
          pop eax
          }
be simpiler than this?
Code:
   HINSTANCE hDll = LoadLibrary((LPCTSTR) "Ws2_32.dll");
   OriginalAddress = (DWORD)GetProcAddress(hDll, "WSASend");

Just wondering why do it the first way?
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Mon Aug 10, 2009 8:25 pm    Post subject: Reply with quote

don't you have to load the library to get the address? The first one doesn't have the library loaded
_________________
Back to top
View user's profile Send private message
Chaosis13
Master Cheater
Reputation: 0

Joined: 14 Aug 2007
Posts: 372

PostPosted: Mon Aug 10, 2009 8:27 pm    Post subject: Reply with quote

Well, it returns the same address. I guess I should try it with the first method. I guess if the program didn't have the winsock library loaded it could be a problem... Anyone else know why?

EDIT:
I tested my method, it works. I tested injecting it into a program of mine without winsock, it also works (because the DLL will have winsock). I check file size, and my way is 512 bytes bigger. I don't care about 512 bytes; unless someone has a reason not to, I will use my simpler way.
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Mon Aug 10, 2009 8:38 pm    Post subject: Reply with quote

Chaosis13 wrote:
Well, it returns the same address. I guess I should try it with the first method. I guess if the program didn't have the winsock library loaded it could be a problem... Anyone else know why?

EDIT:
I tested my method, it works. I tested injecting it into a program of mine without winsock, it also works (because the DLL will have winsock). I check file size, and my way is 512 bytes bigger. I don't care about 512 bytes; unless someone has a reason not to, I will use my simpler way.


also it might be preferred to use the 2nd way just because its all C++ and not mixing languages?

_________________
Back to top
View user's profile Send private message
Chaosis13
Master Cheater
Reputation: 0

Joined: 14 Aug 2007
Posts: 372

PostPosted: Mon Aug 10, 2009 8:58 pm    Post subject: Reply with quote

Some compilers don't allow this:
Code:
OriginalAddress = (DWORD)WSASend;

I use gcc a lot, but let me try it on VC++...

EDIT:
Yes, the C++ version works with VC++.


Last edited by Chaosis13 on Mon Aug 10, 2009 9:10 pm; edited 1 time in total
Back to top
View user's profile Send private message
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Mon Aug 10, 2009 9:06 pm    Post subject: Reply with quote

Chaosis13 wrote:
Some compilers don't allow this:
Code:
OriginalAddress = (DWORD)WSASend;

I use gcc a lot, but let me try it on VC++...


that shouldn't work, unless you load all the libraries for winsock

_________________
Back to top
View user's profile Send private message
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Mon Aug 10, 2009 9:14 pm    Post subject: Reply with quote

Code:

HMODULE Ws = GetModuleHandle('ws2_32.dll');
if(Ws)
{
   FindWsaSend..
}
else
{
   LoadLibrary();
}

_________________
don't +rep me..i do not wish to have "status" or "recognition" from you or anyone.. thank you.
Back to top
View user's profile Send private message MSN Messenger
Chaosis13
Master Cheater
Reputation: 0

Joined: 14 Aug 2007
Posts: 372

PostPosted: Mon Aug 10, 2009 9:51 pm    Post subject: Reply with quote

I don't know why you need that if the DLL has the library and will always return true. I am all for clean code, but not overly complex code.
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Tue Aug 11, 2009 1:24 am    Post subject: Reply with quote

not sure about other compilers but for example in masm32 if you were to do something like :
mov eax, WSASend

then that by itself will import ws2_32.dll. no need to load the library manually. of course i can't speak for other compilers/assemblers
Back to top
View user's profile Send private message
Deltron Z
Expert Cheater
Reputation: 1

Joined: 14 Jun 2009
Posts: 164

PostPosted: Tue Aug 11, 2009 6:47 am    Post subject: Reply with quote

BanMe wrote:
Code:

HMODULE Ws = GetModuleHandle('ws2_32.dll');
if(Ws)
{
   FindWsaSend..
}
else
{
   LoadLibrary();
}

It's easier to simply call LoadLibrary, if the library is already loaded it will return the handle to the loaded library, else it'll simply load it.
And there's no point of calling LoadLibrary in this case, if the library isn't loaded then it means there are no calls to WSASend so... no point of hooking.
Back to top
View user's profile Send private message
Chaosis13
Master Cheater
Reputation: 0

Joined: 14 Aug 2007
Posts: 372

PostPosted: Tue Aug 11, 2009 9:37 am    Post subject: Reply with quote

Slugsnack wrote:
not sure about other compilers but for example in masm32 if you were to do something like :
mov eax, WSASend

then that by itself will import ws2_32.dll. no need to load the library manually. of course i can't speak for other compilers/assemblers

Oh, I should look into this... It would explain why it doesn't crash... But like Deltron Z said, it doesn't matter if it doesn't use the library. Very Happy

Thanks for the input. I just want to create a hook made with only my code.
Back to top
View user's profile Send private message
Bswap
Newbie cheater
Reputation: 0

Joined: 18 Aug 2009
Posts: 21

PostPosted: Wed Aug 19, 2009 2:36 am    Post subject: re: Reply with quote

Code:
   __asm {
          push eax
          mov eax, [WSASend]
          mov OriginalAddress, eax
          pop eax
          }


In this case, WSASend is the pointer to WSASend() Entry in the Import Address Table (IAT). It is not the address within the Ws2_32.dll.

Example;

Code:
   ;--------------------------------------------------------
   ; MASM
   ;
   
   mov      eax, ExitProcess

   ;--------------------------------------------------------
   ; Deadlisting
   ;

   B8 66104000   MOV EAX,<JMP.&kernel32.ExitProcess>

   ; IAT

   FF25 14204000   JMP DWORD PTR DS:[<&kernel32.ExitProcess>
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Wed Aug 19, 2009 4:31 am    Post subject: Reply with quote

this would get you the actual address :
Code:
    mov eax,[MessageBox]
    add eax,2
    mov eax,[eax]
    mov eax,[eax]
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: Wed Aug 19, 2009 5:15 am    Post subject: Reply with quote

Ja

Code:
OriginalAddress = &WSASend;
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