View previous topic :: View next topic |
Author |
Message |
Mussy69 Grandmaster Cheater
Reputation: 0
Joined: 09 Mar 2007 Posts: 842 Location: Sydney
|
Posted: Mon May 26, 2008 8:32 am Post subject: [C++ Help] Hooking A Program To A Process? |
|
|
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 |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Mon May 26, 2008 8:37 am Post subject: |
|
|
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.
_________________
|
|
Back to top |
|
 |
Ferocious Advanced Cheater
Reputation: 0
Joined: 06 Feb 2008 Posts: 54
|
Posted: Mon May 26, 2008 8:37 am Post subject: |
|
|
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 |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Mon May 26, 2008 8:43 am Post subject: |
|
|
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 |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8586 Location: 127.0.0.1
|
Posted: Mon May 26, 2008 9:06 am Post subject: |
|
|
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 |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Mon May 26, 2008 9:16 am Post subject: |
|
|
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 |
|
 |
Mussy69 Grandmaster Cheater
Reputation: 0
Joined: 09 Mar 2007 Posts: 842 Location: Sydney
|
Posted: Mon May 26, 2008 5:13 pm Post subject: |
|
|
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 |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Mon May 26, 2008 5:20 pm Post subject: |
|
|
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 |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8586 Location: 127.0.0.1
|
Posted: Mon May 26, 2008 5:21 pm Post subject: |
|
|
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 |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Mon May 26, 2008 6:32 pm Post subject: |
|
|
Remember to put .exe
_________________
|
|
Back to top |
|
 |
Mussy69 Grandmaster Cheater
Reputation: 0
Joined: 09 Mar 2007 Posts: 842 Location: Sydney
|
Posted: Tue May 27, 2008 3:42 am Post subject: |
|
|
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 |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Tue May 27, 2008 6:06 am Post subject: |
|
|
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 |
|
 |
Mussy69 Grandmaster Cheater
Reputation: 0
Joined: 09 Mar 2007 Posts: 842 Location: Sydney
|
Posted: Tue May 27, 2008 6:33 am Post subject: |
|
|
I did not want this for hacking purpose
i did not even need this, i am asking to save it for future use
_________________
|
|
Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Tue May 27, 2008 7:56 am Post subject: |
|
|
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  |
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
_________________
|
|
Back to top |
|
 |
Mussy69 Grandmaster Cheater
Reputation: 0
Joined: 09 Mar 2007 Posts: 842 Location: Sydney
|
Posted: Tue May 27, 2008 6:47 pm Post subject: |
|
|
yeah thats true because after i learnt abit i went back to reading the tut and before im like huh whats the but now i understand it, thanks for your help everyone
_________________
|
|
Back to top |
|
 |
|