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++ Help] Hooking A Program To A Process?
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Mussy69
Grandmaster Cheater
Reputation: 0

Joined: 09 Mar 2007
Posts: 842
Location: Sydney

PostPosted: Mon May 26, 2008 8:32 am    Post subject: [C++ Help] Hooking A Program To A Process? Reply with quote

Hey Guys Me Again,
Could somebody help me to hook lets say A Trainer to a process name called "Example123" ( Those Are Examples ) I'm new to C++ and would like help on doing so,
Thanks Alot, Much Appreciated ~ MuSSii

_________________
Back to top
View user's profile Send private message AIM Address
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Mon May 26, 2008 8:37 am    Post subject: Reply with quote

A hook is probably something way away from what you mean.

Are you saying that you want to "attach" (in Cheat Engine's terms) to a process?

If so, look up the OpenProcess API on MSDN.

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Ferocious
Advanced Cheater
Reputation: 0

Joined: 06 Feb 2008
Posts: 54

PostPosted: Mon May 26, 2008 8:37 am    Post subject: Reply with quote

its apperent that you don't know what is your objective.

you have two options :

1. you want to inject your code into the process.

2. you want to create a debugger that attaches itself to the process.

_________________
I wanna hack, but I don't know how...
Back to top
View user's profile Send private message
tombana
Master Cheater
Reputation: 2

Joined: 14 Jun 2007
Posts: 456
Location: The Netherlands

PostPosted: Mon May 26, 2008 8:43 am    Post subject: Reply with quote

What do you mean by 'hook to a process'. Do you mean attach to a process like CE does so you can read it's memory?
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8586
Location: 127.0.0.1

PostPosted: Mon May 26, 2008 9:06 am    Post subject: Reply with quote

Assuming you mean 'attach' as in being able to read and write to and from the processes memory, you would use OpenProcess to obtain a handle to the process to be used with the respected API, ReadProcessMemory and WriteProcessMemory.

OpenProcess requires a process ID to work, which you can get several different ways. The two common methods would be the use of:

FindWindow with GetWindowThreadProcId
or
CreateToolhelp32Snapshot with Process32First and Process32Next

There are tons of examples of using CreateToolhelp32snapshot in this section.

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

Joined: 02 Apr 2007
Posts: 2947
Location: you wanna know why?

PostPosted: Mon May 26, 2008 9:16 am    Post subject: Reply with quote

Here's an example of "attaching" to a process with both of the ways that Wiccaan suggested. I opened the processes using PROCESS_VM_READ and PROCESS_VM_WRITE assuming that you were going to read and write to the file, but otherwise you should access the process access rights at msdn.com

Code:

BOOL ProcessOpen(char *szExeFile) {
   HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
   HANDLE hProcess;
   PROCESSENTRY32 pe32;
   pe32.dwSize = sizeof(PROCESSENTRY32);
   bool popen = FALSE;
   Process32First(hSnapshot, &pe32);
   do {
      if(strcmp(pe32.szExeFile, szExeFile) == 0) {
         hProcess = OpenProcess(PROCESS_VM_READ | PROCESS_VM_WRITE, NULL, pe32.th32ProcessID);
         popen = TRUE;
         CloseHandle(hSnapshot);
      }
   } while(Process32Next(hSnapshot, &pe32));
   return popen;
}


Code:

BOOL ProcessOpen(char *WindowName) {
   DWORD pid;
   HANDLE hProcess;
   HWND hwnd = FindWindow(NULL, WindowName);
   if(hwnd != INVALID_HANDLE_VALUE) {
      if(GetWindowThreadProcessId(hwnd, &pid)) {
         hProcess = OpenProcess(PROCESS_VM_READ | PROCESS_VM_WRITE, NULL, pid);
      }
   }
}

_________________


8D wrote:

cigs dont make people high, which weed does, which causes them to do bad stuff. like killing
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Mussy69
Grandmaster Cheater
Reputation: 0

Joined: 09 Mar 2007
Posts: 842
Location: Sydney

PostPosted: Mon May 26, 2008 5:13 pm    Post subject: Reply with quote

Is The Bold Part What I Must Edit?
Code:
BOOL ProcessOpen(char * [b]Example123[/b]) {
   DWORD pid;
   HANDLE hProcess;
   HWND hwnd = FindWindow(NULL, [b]Example123[/b]);
   if(hwnd != INVALID_HANDLE_VALUE) {
      if(GetWindowThreadProcessId(hwnd, &pid)) {
         hProcess = OpenProcess(PROCESS_VM_READ | PROCESS_VM_WRITE, NULL, pid);
      }
   }
}

_________________
Back to top
View user's profile Send private message AIM Address
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Mon May 26, 2008 5:20 pm    Post subject: Reply with quote

FindWindow gets the Window Handle to a specific Window that matches the parameters inputted

The first paramater is lpClassName which is the Window Class and the second parameter is lpWindowName which is Window Name (the text in the title bar)

so the bolded part would be the window name, so say the window text was "Example1" and class name was "ExampleClass"

then you would do

HWND hWindow = FindWindow( "ExampleClass", NULL )
or
HWND hWindow = FindWindow( NULL, "Example1" )
or
HWND hWindow = FindWindow( "ExampleClass", "Example1" );

BUT this parameter is alreayd chosen for you and it is the inputted parameter for the function

so when you call the function like ProcessOpen( "Example1" ); would be valid.

_________________


Last edited by lurc on Mon May 26, 2008 5:21 pm; edited 1 time in total
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8586
Location: 127.0.0.1

PostPosted: Mon May 26, 2008 5:21 pm    Post subject: Reply with quote

The Example123 there is a param of the function. You could do something such as:

Code:
if( ProcessOpen( "Minesweeper" ) == FALSE )
{
  // Failed...
}
else
{
  // Opened...
}

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
HomerSexual
Grandmaster Cheater Supreme
Reputation: 5

Joined: 03 Feb 2007
Posts: 1657

PostPosted: Mon May 26, 2008 6:32 pm    Post subject: Reply with quote

Remember to put .exe
_________________
Back to top
View user's profile Send private message
Mussy69
Grandmaster Cheater
Reputation: 0

Joined: 09 Mar 2007
Posts: 842
Location: Sydney

PostPosted: Tue May 27, 2008 3:42 am    Post subject: Reply with quote

Alright put it this way because im sorry but i dont quite understand,
Examples:
MapleStory.exe
SymbolTrainer.exe

Goal:
Make the symbol trainer "Find Maplestory" ( Attach Process ) Actually attach, could you help me with that code?

_________________
Back to top
View user's profile Send private message AIM Address
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Tue May 27, 2008 6:06 am    Post subject: Reply with quote

Mussy69 wrote:
Alright put it this way because im sorry but i dont quite understand,
Examples:
MapleStory.exe
SymbolTrainer.exe

Goal:
Make the symbol trainer "Find Maplestory" ( Attach Process ) Actually attach, could you help me with that code?


See this is what happens when kids come from using Cheat Engine to actually wanting to program for hacking purposes only. Your getting ahead of yourself and you need to learn all the basics before you start anything huge. There is no "Attaching" What your actually doing is opening (gaining access to) a handle for a certain thing like the Window or the process and using it in certain API to make your program things such as Read memory, write memory, send keys, etc.

It's been posted already how you could do this ( oib111's code, and lots of examples within the section )
Anyways to your question you can use the code snippet posted by oib111 (ProcessOpen using the CreateToolhelp32Snapshot method) except your going to want to add a handle parameter or make hProcess global.

so it would look like this:

Code:
BOOL ProcessOpen( __out HANDLE hProcess, __in char *szExeFile) {
   HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
   PROCESSENTRY32 pe32;
   pe32.dwSize = sizeof(PROCESSENTRY32);
   bool popen = FALSE;
   Process32First(hSnapshot, &pe32);
   do {
      if(strcmp(pe32.szExeFile, szExeFile) == 0) {
         hProcess = OpenProcess(PROCESS_VM_READ | PROCESS_VM_WRITE, NULL, pe32.th32ProcessID);
         popen = TRUE;
         CloseHandle(hSnapshot);
      }
   } while(Process32Next(hSnapshot, &pe32));
   return popen;
}


So in your code you would define HANDLE hProcess somewhere and then call the function like: ProcessOpen( hProcess, "MapleStory.exe" );

K i g2g to school now, later.

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

Joined: 09 Mar 2007
Posts: 842
Location: Sydney

PostPosted: Tue May 27, 2008 6:33 am    Post subject: Reply with quote

I did not want this for hacking purpose
i did not even need this, i am asking to save it for future use Evil or Very Mad

_________________
Back to top
View user's profile Send private message AIM Address
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Tue May 27, 2008 7:56 am    Post subject: Reply with quote

Mussy69 wrote:
I did not want this for hacking purpose
i did not even need this, i am asking to save it for future use Evil or Very Mad


oh well then my mistake. Anyways, like i said, its always good to get all the basics learned first because then it gets easier from there to understand everything you see Wink

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

Joined: 09 Mar 2007
Posts: 842
Location: Sydney

PostPosted: Tue May 27, 2008 6:47 pm    Post subject: Reply with quote

yeah thats true because after i learnt abit i went back to reading the tut and before im like huh whats the Confused but now i understand it, thanks for your help everyone Very Happy
_________________
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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