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 


How do you get the injected dll's processID?

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

Joined: 04 Jan 2007
Posts: 2674

PostPosted: Wed Aug 06, 2008 9:13 am    Post subject: How do you get the injected dll's processID? Reply with quote

If you inject a dll into a process how would you get the process's id from inside the dll? is there an eaiser method?
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Wed Aug 06, 2008 9:14 am    Post subject: Reply with quote

GetCurrentProcessId()
http://msdn.microsoft.com/en-us/library/ms683180.aspx

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
dnsi0
I post too much
Reputation: 0

Joined: 04 Jan 2007
Posts: 2674

PostPosted: Wed Aug 06, 2008 9:15 am    Post subject: Reply with quote

O.o thanks alot.
Back to top
View user's profile Send private message
Cx
Master Cheater
Reputation: 0

Joined: 27 Jul 2007
Posts: 367

PostPosted: Wed Aug 06, 2008 11:04 am    Post subject: Reply with quote

GetCurrentProcessId:
Code:
7C809920 >/$ 64:A1 18000000 MOV EAX,DWORD PTR FS:[18]
7C809926  |. 8B40 20        MOV EAX,DWORD PTR DS:[EAX+20]
7C809929  \. C3             RETN


Someone explain to me how the hell that works?

_________________

armed with this small butterfly net
i will face the world alone
& never be lonely.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Wed Aug 06, 2008 11:10 am    Post subject: Reply with quote

Code:
MOV EAX,DWORD PTR FS:[18]


Obtains the current process TEB block.

Code:
MOV EAX,DWORD PTR DS:[EAX+20]


Obtains the current process ID from the TEB block and stores it into EAX and returns.

Rough copy of the TEB struct:
http://en.wikipedia.org/wiki/Win32_Thread_Information_Block

0x20 offset in the struct is the current process id.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Cx
Master Cheater
Reputation: 0

Joined: 27 Jul 2007
Posts: 367

PostPosted: Wed Aug 06, 2008 11:16 am    Post subject: Reply with quote

Ah, cool.
Thanks!

_________________

armed with this small butterfly net
i will face the world alone
& never be lonely.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Wed Aug 06, 2008 11:21 am    Post subject: Reply with quote

Just for shits and giggles, you can do the same thing inline like this:

Code:
__declspec(naked) DWORD __stdcall GetProcId()
{
   _asm mov eax, dword ptr fs:[0x18]
   _asm mov eax, dword ptr ds:[eax+0x20]
   _asm retn
}

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Cx
Master Cheater
Reputation: 0

Joined: 27 Jul 2007
Posts: 367

PostPosted: Wed Aug 06, 2008 11:41 am    Post subject: Reply with quote

Yeah. So I would assume GetCurrentThreadId also uses TIB (TIB+0x24), but does GetLastError also use it (offset 0x34)?

Are there any other blocks with information like this? It's pretty interesting stuff.

_________________

armed with this small butterfly net
i will face the world alone
& never be lonely.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Wed Aug 06, 2008 5:26 pm    Post subject: Reply with quote

Another common one would be the PEB block.

Code:
_asm mov eax, dword ptr fs:[0x18]
_asm mov eax, dword ptr [eax+0x30]


http://en.wikipedia.org/wiki/Process_Environment_Block

Which also has a fair amount of information. This ones commonly used for unlinking your DLL from a processes linked lists to "hide" it.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
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