Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 00:31

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[C++] Process Handle

Discussion on [C++] Process Handle within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Apr 2006
Posts: 6,597
Received Thanks: 1,830
[C++] Process Handle

huhu, ich hab ein Problem den Process Handle von Diablo II zu bekommen.

Code:
#include <cstdlib>
#include <iostream>
#include <windows.h>



using namespace std;


int main(int argc, char *argv[])
{
    
    
HWND Diablo = FindWindow("Diablo II", NULL);
     
DWORD process_ID;
DWORD thread_ID = GetWindowThreadProcessId(Diablo, &process_ID);
HANDLE process = OpenProcess(STANDARD_RIGHTS_REQUIRED | SYNCHRONIZE | 0xFFF, FALSE, process_ID);    


//SPEICHERABFRAGE//

unsigned int wert(0);
unsigned int adress(0x01CBFC3D);
ReadProcessMemory(process,
                    reinterpret_cast<void *> (adress),
                    &wert,
                    sizeof(wert),
                    NULL);


if(ReadProcessMemory(process,
                    reinterpret_cast<void *> (adress),
                    &wert,
                    sizeof(wert),
                    NULL)){
     cout<<"Success";}
else{
    cout<<"Fehlercode"<<endl;
    cout<<GetLastError()<<endl;

}
///AUSGABE////
if (Diablo){
    
cout<<"\n";
cout<<"\n";
cout<<"HWND"<<endl;
cout<<Diablo<<endl;
cout<<"\n";
cout<<"HANDLE"<<endl;
cout<<process<<endl;
cout<<"\n";
cout<<"&wert"<<endl;
cout<<&wert<<endl;

cout<<"\n";
cout<<"wert"<<endl;
cout<<wert<<endl;
}
else if(!Diablo)
{
    cout<<"Programm nicht aktiv"<<endl;
}


    
    system("PAUSE");
    return EXIT_SUCCESS;
}
und zwar wird dann in der Konsole bei HANDLE : 0 ausgegeben und der Speicherwert kann auch nicht ausgelesen werden.

Wenn ich das ganze jedoch bei Minesweeper mache klappt es Problemlos wieso ?
Medix is offline  
Old 10/26/2009, 21:19   #2
 
^darkwing's Avatar
 
elite*gold: 0
Join Date: Sep 2009
Posts: 148
Received Thanks: 31
Code:
HANDLE process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, process_ID);
Unter Vista bzw. Windows 7 als Administrator ausführen.

Btw. 0 heißt es ist wohl ein Fehler passiert und deswegen kann Read- und WriteProcessMemory auch nicht funktionieren
^darkwing is offline  
Thanks
1 User
Old 10/26/2009, 21:25   #3
 
elite*gold: 0
Join Date: Apr 2006
Posts: 6,597
Received Thanks: 1,830
Quote:
Originally Posted by ^darkwing View Post
Code:
HANDLE process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, process_ID);
Unter Vista bzw. Windows 7 als Administrator ausführen.

Btw. 0 heißt es ist wohl ein Fehler passiert und deswegen kann Read- und WriteProcessMemory auch nicht funktionieren
Danke, eben versucht Problem besteht leider immernoch, wobei ich Diablo 2 sowie auch das Programm selbst als Admin ausgeführt habe.
Medix is offline  
Old 10/26/2009, 21:32   #4
 
^darkwing's Avatar
 
elite*gold: 0
Join Date: Sep 2009
Posts: 148
Received Thanks: 31
Dann muss der Fehler wohl paar Zeilen drüber liegen.

Code:
HWND Diablo = FindWindow("Diablo II", NULL);
Ich glaube hier steckt dann evtl. der Fehler.
Das Handle zum Fenster ist vermute ich 0.

Mir fällt gerade auf, dass du die Parameter von FindWindow() vertauscht hast und der Code sollte so besser geschrieben werden:

Code:
HWND Diablo = NULL;
while (Diablo == NULL)
{
    Diablo = FindWindow(NULL, "Diablo II");
    Sleep(100);
}
^darkwing is offline  
Thanks
1 User
Old 10/26/2009, 21:38   #5
 
elite*gold: 0
Join Date: Apr 2006
Posts: 6,597
Received Thanks: 1,830
Quote:
Originally Posted by ^darkwing View Post
Dann muss der Fehler wohl paar Zeilen drüber liegen.

Code:
HWND Diablo = FindWindow("Diablo II", NULL);
Ich glaube hier steckt dann evtl. der Fehler.
Das Handle zum Fenster ist vermute ich 0.

Mir fällt gerade auf, dass du die Parameter von FindWindow() vertauscht hast und der Code sollte so besser geschrieben werden:

Code:
HWND Diablo = NULL;
while (Diablo == NULL)
{
    Diablo = FindWindow(NULL, "Diablo II");
    Sleep(100);
}
Danke aber habs immernoch nicht hingekriegt.


Das HWND ist jedenfalls nicht NULL daran scheiterts anscheinend nicht denn ich lass mir ja den wert von Diablo unten ausgeben in der Konsole und der bekommt einen wert zugewiesen.

Medix is offline  
Old 10/26/2009, 21:48   #6
 
^darkwing's Avatar
 
elite*gold: 0
Join Date: Sep 2009
Posts: 148
Received Thanks: 31
Was sagt denn GetLastError(), wenn du es hinter bzw. unter dem Aufruf von OpenProcess schreibst?
^darkwing is offline  
Thanks
1 User
Old 10/26/2009, 21:54   #7
 
elite*gold: 0
Join Date: Apr 2006
Posts: 6,597
Received Thanks: 1,830
Quote:
Originally Posted by ^darkwing View Post
Was sagt denn GetLastError(), wenn du es hinter bzw. unter dem Aufruf von OpenProcess schreibst?

5
aka

Quote:
ERROR_ACCESS_DENIED
5 (0x5)



Access is denied.
Programm wurde aber als Administrator ausgeführt
Medix is offline  
Old 10/26/2009, 22:18   #8
 
^darkwing's Avatar
 
elite*gold: 0
Join Date: Sep 2009
Posts: 148
Received Thanks: 31
Wie es aussieht hat der Prozess nicht genügend Rechte. Um absolut volle Rechte zu bekommen braucht man das "SeDebugPrivileg".
Deklarier die Funktion bei dir und ruf sie vor OpenProcess auf.
Das müsste nun endgültig das Problem lösen :0
Code:
bool EnableDebugPrivilege()
{
    TOKEN_PRIVILEGES priv;
    HANDLE hThis, hToken;
    LUID luid;
    hThis = GetCurrentProcess();
    OpenProcessToken(hThis, TOKEN_ADJUST_PRIVILEGES, &hToken);
    LookupPrivilegeValue(0, "seDebugPrivilege", &luid);
    priv.PrivilegeCount = 1;
    priv.Privileges[0].Luid = luid;
    priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    AdjustTokenPrivileges(hToken, false, &priv, 0, 0, 0);
    CloseHandle(hToken);
    CloseHandle(hThis);
    return true;
}
^darkwing is offline  
Old 10/26/2009, 23:45   #9


 
MrSm!th's Avatar
 
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,908
Received Thanks: 25,409
selbes problem bei nem anderen game
habe bisher auch noch keine lösung gefunden
es scheint wohl an vista zu liegen
bis zur ProcessID hab ich auch alles zurückverfolgt; alles stimmt
bei mir kanns also nur irgendwie an den rechten oder an dem handle liegen
p.s. das mit dem Debug Previleg auch schon probiert...klappt auch nicht
ich glaube langsam echt es liegt an vista
MrSm!th is offline  
Old 10/27/2009, 16:11   #10
 
^darkwing's Avatar
 
elite*gold: 0
Join Date: Sep 2009
Posts: 148
Received Thanks: 31
Also bei Medix funktioniert es jetzt.
Die Lösung war, den Prozess mit nur den notwendigesten Rechten zu öffnen.
Das SeDebugPrivileg muss dennoch vorher ausgeführt werden.

Ansonsten: Google "openprocess access denied"
^darkwing is offline  
Reply


Similar Threads Similar Threads
Does anyone know how to handle this?
09/03/2010 - Mabinogi - 10 Replies
how to handle the mini game of metal conversion? Can you offer me a link or just post bellow?
Mit Process Explorer /Process Hacker Hs umgehen
05/22/2010 - General Gaming Discussion - 1 Replies
Ich habe hier im Forum gelesen, das man mit Process Explorer bzw. Process Hacker das HS umgehen kann. Leider ist mir irgendwie schleierhaft wie das gehen soll. Vllt erbarmt sich jemand und erklärt es (:, da man den sogenannten Bypasser nur noch las Premium Dings Da bei Upload.to runterladen kann :rolleyes:
C# how to pause a process/freeze process
12/08/2008 - CO2 Programming - 2 Replies
ya so i was semi bored and after little bit of looking around i didnt find to many examples of how to do this so attached is a demo project to show you how. basically it comes down to calling ResumeThread() and SuspendThread() (API functions) on all the threads of a process...simple enough http://img388.imageshack.us/img388/9762/exampleil 6.png please note when you enter the process name there's no ".exe" to the end Warning: this isn't idiot proof . .
get opened process handle to readwrite with a dll?
01/19/2008 - General Coding - 0 Replies
Hi, is there a way to inject a dll and get it's process handle for read/write..because the address i'm using is a point and to read the address first and then add the offset..
How to handle a rb
02/16/2007 - CO2 Guides & Templates - 16 Replies
When you see a rb pking, you think usually about the guard right? especially when rbs get to 105 and have gold guard, they are usually invincible. A little trick that works for me is to poison the guard before going after the pker, the poison delays the guards lightning, giving you enough time to land a fb or rapid on the pker, however sometimes it does fail and 9/10 you die because gold guard has a ridiculously high Matk feel free to flame away and call me a noob or w/e just sharing...



All times are GMT +1. The time now is 00:32.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.