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 


Hooked Api Send,but how to get Socket ID?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
anthor
How do I cheat?
Reputation: 0

Joined: 28 Dec 2009
Posts: 6

PostPosted: Mon Dec 28, 2009 1:27 pm    Post subject: Hooked Api Send,but how to get Socket ID? Reply with quote

i have hooked Api Send,but how to retrieve the socket id ?
i m using Delphi ,i have no idea already..please guide me...!
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Mon Dec 28, 2009 1:33 pm    Post subject: Reply with quote

when send function called the socket's id is pushed into the stack
you can use inline assembly to get it
Code:

asm
  push ebp
  mov ebp,esp
  mov eax,[ebp+0x8] // [ebp] = to ebp value that we've pushed earlier, ebp + 4 = to the return address to the original code and [ebp + 8] is the socket's id
end;

i guess 0x8 won't work at delphi since it has other way to present hexadecimal numbers
but that's the way
and if you'd like to move the socket's id to your variables instead eax register just use
Code:

mov dword ptr ds:[myVar],eax

hope you got it Wink
Back to top
View user's profile Send private message
anthor
How do I cheat?
Reputation: 0

Joined: 28 Dec 2009
Posts: 6

PostPosted: Mon Dec 28, 2009 2:08 pm    Post subject: Reply with quote

Confused still blur with asm..is ok..this is my code,let me show u
Code:

type
PData = ^TData;
TData = record
Hook: THandle;
Hooked: Boolean;
end;

var
DLLData: PData;

procedure HookProc(nCode, wParam, lParam: LongWORD);stdcall;
begin
if not DLLData^.Hooked then
begin
HookAPI;
DLLData^.Hooked := True;
end;
CallNextHookEx(DLLData^.Hook, nCode, wParam, lParam);
end;

function InstallHook(SWindow: LongWORD):Boolean;stdcall;
var
ThreadID: LongWORD;
begin
Result := False;
DLLData^.Hook := 0;
ThreadID := GetWindowThreadProcessId(sWindow, nil);
DLLData^.Hook := SetWindowsHookEx(WH_GETMESSAGE, @HookProc, Hinstance, ThreadID);
if DLLData^.Hook > 0 then
Result := True //ÊÇ·ñ³É¹¦HOOK
else
exit;
end;

procedure HookAPI;
var
DLLModule: THandle;
dwSize: cardinal;
begin
ProcessHandle := GetCurrentProcess;
DLLModule := LoadLibrary('ws2_32.dll');
AddSend := GetProcAddress(DLLModule, 'send');
end;

so,we get the send address and stored into AddSend,which Address i have to push or wat=.=...bluring.... Rolling Eyes

and 1 more question, that 0x8?why + 8 bytes?i think Delphi stored as 8 bytes too
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Mon Dec 28, 2009 3:45 pm    Post subject: Reply with quote

Because that's where the socket is stored on the stack.
Back to top
View user's profile Send private message
anthor
How do I cheat?
Reputation: 0

Joined: 28 Dec 2009
Posts: 6

PostPosted: Mon Dec 28, 2009 11:37 pm    Post subject: Reply with quote

so now i hooked the send function and then jump to my own following code
Code:

asm
  push ebp
  mov ebp,esp
  mov eax,[ebp+0x8] // [ebp] = to ebp value that we've pushed earlier, ebp + 4 = to the return address to the original code and [ebp + 8] is the socket's id
end;

then get the socket id and jmp back to the original send address?
am i right??
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Tue Dec 29, 2009 12:21 am    Post subject: Reply with quote

No.
this isn't a memory redirection that should be returned to it's original code
this is just a code (only in assembly instead of delphi) you just run it as it is
Back to top
View user's profile Send private message
anthor
How do I cheat?
Reputation: 0

Joined: 28 Dec 2009
Posts: 6

PostPosted: Tue Dec 29, 2009 3:23 am    Post subject: Reply with quote

Shocked goshh.....
i don't understand at all,then what i need to hook?..
it is better u give me some example man...thanks!
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Tue Dec 29, 2009 11:57 am    Post subject: Reply with quote

redirecting code is when you're editing other process's memory to jump to your own code
like:
Code:

// original code could be (memory map)
0xFFFFFFFD: mov edi,edi
0xFFFFFFFE: push ebp
0xFFFFFFFF: mov ebp,esp

// but when you want the address 0xFFFFFFFD to jump to your own code instead of continue you use the formula [destination address - source address - 5] which means
<myHookingFunc> - 0xFFFFFFFD - 5 = the number of bytes to jump to myHookingFunc
and in your hooking function you write your own code in assembly cuz that's the easiest access to the stack and from there to the socket's id

just for the record these addresses is just a random addresses that i picked now

now when you write assembly code at your program it's just as you write it on delphi, the compiler compiles it anyway to assembly so it won't matter, it's just an easiest way to access your memory
Back to top
View user's profile Send private message
anthor
How do I cheat?
Reputation: 0

Joined: 28 Dec 2009
Posts: 6

PostPosted: Sat Feb 20, 2010 8:59 pm    Post subject: Reply with quote

here is what i understand...
Example:
Code:

Send Func From ws2_32.dll
0xFFFFFFFD: mov edi,edi //Send Address
0xFFFFFFFE: push ebp
0xFFFFFFFF: mov ebp,esp

DLLModule := LoadLibrary('ws2_32.dll');
AddSend := GetProcAddress(DLLModule, 'send');

ok,now Addsend i get 0xFFFFFFFD,
i change the asm using writememoryprocess
0xFFFFFFFD: mov edi,edi
become
0xFFFFFFFD: JMP 0x00400000

0x00400000 is my ABC Func Address,

here is my ABC func Code:
Code:

ABC:
asm
  push ebp
  mov ebp,esp
  mov eax,[ebp+0x8]
  mov dword ptr ds:[Socket_ID],eax
 JMP 0xFFFFFFFE //ok now i get what i want,then jmp back to the original code
end;


Am i Right??Now i get the socket ID on my variable Socket_ID..
Back to top
View user's profile Send private message
anthor
How do I cheat?
Reputation: 0

Joined: 28 Dec 2009
Posts: 6

PostPosted: Mon Mar 08, 2010 1:16 am    Post subject: Reply with quote

_DoR??please...
Back to top
View user's profile Send private message
pkedpker
Master Cheater
Reputation: 1

Joined: 11 Oct 2006
Posts: 412

PostPosted: Thu Mar 11, 2010 6:39 pm    Post subject: Reply with quote

I do this in C++

after redirection is complete.. as you can see SOCKET sock is the socketId.

Note that I don't use any assembly at all I don't want to complicate the code but only in the DetourFunction method you will see a few 0xE8/0xE9's for assembly CALL/JMP's.

Code:

int WINAPI myDetouredSend(SOCKET sock, char* buf, int len, int flags)
{
  char makePacket = "\x01\x02\x03\x04\x05\x06\etc.."; //temp packet.
  int size = strlen(makePacket); //not always correct \x00 etc.. best to do it by hand
  char* sendPacket = new char[size];
  memcpy(sendPacket,makePacket,size); //transfer it to pointer
  return osend(sock, sendPacket, size, flags);
}


haven't did C++ coding in a while not sure if that even compiles just showing how I would do it.

myDetouredSend and osend are both addresses but osend is the original send address where it jumps back I declare it with typedef'ing.

Code:

typedef int (WINAPI* r_send)(SOCKET sock, char* buf, int len, int flags);
r_send osend;



How I get oringinal address similar to your WINAPI calls
Code:

DWORD dwSendOriAddr = GetProcAddress(GetModuleHandle("ws2_32.dll"), "send"); //gets original address for send


No idea in delphi sorry could be similiar I use this in a DLL Injection method

Here is the DetourFunction method I use.

Code:

void *DetourFunc(BYTE *src, const BYTE *dst, const int len)
{
   BYTE *jmp = (BYTE*)malloc(len+5);
   DWORD dwback;
   
   VirtualProtect(src, len, PAGE_READWRITE, &dwback);
   memcpy(jmp, src, len); jmp += len;
   
   jmp[0] = 0xE9;
   *(DWORD*)(jmp+1) = (DWORD)(src+len - jmp) - 5;
   
   src[0] = 0xE9;
   *(DWORD*)(src+1) = (DWORD)(dst - src) - 5;
   
   VirtualProtect(src, len, dwback, &dwback);
   
   return (jmp-len);
}


As you can see the function above does 2 things.. redirect your found address where send function is loaded in the application/game nearly always changes when you restart the game.

It replaces the address to the function in your DLL Injection which is also generated when your DLL is injected and in the end it returns the address of the original jump back to send function.

I use it like this

Code:


osend         = (r_send)         DetourFunc((BYTE*)osend, (BYTE*)&myDetouredSend, 5);


_________________
Hacks I made for kongregate.
Kongregate Universal Badge Hack: http://forum.cheatengine.org/viewtopic.php?p=4129411
Kongreate Auto Rating/Voter hack: http://forum.cheatengine.org/viewtopic.php?t=263576
Took a test lol
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