Das mit dem long habe ich in DWORD geändert.
@.Infinity
Danke ich werds mal versuchen (:
EDIT:
MH ka wie ichs lösen soll es funkt i.w. net :S
Hier der Functions-Aufruf:
Code:
#include "Header.h"
void main()
{
TMemory a;
a.Init( "0x0052600C+0x20", "Blabla"); //Fenstertitel ausgedacht.. adresse + offset nicht , das sind die daten womit ich die neue adr suche...
a.GetValue();
}
Header.h
Code:
#ifndef HEADER_H
#define HEADER_H
#include <iostream>
#include <Windows.h>
#include <string>
#include "TMemory.h"
using namespace std;
#endif
TMemory.h
Code:
#ifndef TMEMORY_H
#define TMEMORY_H
class TMemory
{
public:
//Normal Konstructor
TMemory(void);
//Destructor
virtual ~TMemory(void);
unsigned long MakeAdress(char *, HANDLE *);
void Init( char *, std::string );
void GetValue();
void WriteValue(int);
private:
HWND window;
HANDLE handle;
DWORD prozess;
DWORD puffer;
unsigned long adress;
std::string title;
int value;
};
#endif
TMemory.cpp
(MakeAdress ist hierbei das mit den offsets addieren etc.pp)
Code:
#include "Header.h"
TMemory::TMemory(void)
{
cout << "New TMemory Instance started!" << endl;
//Init
window = NULL;
handle = NULL;
prozess = NULL;
puffer = NULL;
adress = NULL;
title = "";
value = NULL;
}
TMemory::~TMemory(void)
{
window = NULL;
handle = NULL;
prozess = NULL;
puffer = NULL;
adress = NULL;
title = "";
value = NULL;
if(handle != NULL)
{
CloseHandle(handle);
cout << "TMemory Handle geschlossen!" << endl;
}
cout << "TMemory Instance deleted!" << endl;
}
unsigned long TMemory::MakeAdress(char * source, HANDLE *h)
{
int main_addr_lengh = 0;
int source_lengh = 0;
int offsets = 0;
unsigned long adresse;
unsigned long dummyadresse;
DWORD numBytesRead;
for( int i=0; source[i] != '\0'; i++)
{
source_lengh++;
if(source[i] == '+')
offsets++;
}
for( int i=0; source[i] != '+'; i++)
main_addr_lengh++;
cout << "Source_lengh = "<<source_lengh << endl;
cout << "Main-Addr_Lengh = "<< main_addr_lengh << endl;
cout << "Offsets = " << offsets << endl<<endl<<endl;
// START HAUPTADRESSE //
char * mainadr = NULL;
mainadr = new char[main_addr_lengh+1];
for(int i=0; i<main_addr_lengh; i++)
mainadr[i] = source[i];
mainadr[main_addr_lengh] = '\0';
cout << "Main-Adresse lautet: "<< mainadr << endl;
adresse = strtoul(mainadr, NULL, 0);
cout << "Main-Adresse umgewandelt: "<< adresse << endl << endl;
if(mainadr != NULL)
delete []mainadr;
if( offsets == 0)
return adresse;
// START OFFSETS //
int offset_lengh = 0;
int akt_pos = main_addr_lengh+1;
for(int offnr=0; offnr < offsets; offnr++)
{
for(int a=akt_pos;source[a] != '+' && source[a] != '\0'; a++)
{
offset_lengh++;
//cout << source[a];
}
//cout << "offset"<<offnr<<"_länge ="<<offset_lengh <<endl;
char * offset = NULL;
offset = new char[offset_lengh+1];
for(int i=0; i<offset_lengh; i++)
offset[i] = source[akt_pos+i];
offset[offset_lengh] = '\0';
unsigned long offset_adr = strtoul(offset, NULL, 0);
cout << "Offset"<<offnr<<" lautet: "<<offset<<endl;
cout << "Offset-Umgewandelt lautet: "<<offset_adr<<endl<<endl;
ReadProcessMemory(h, (LPCVOID)adresse, &adresse, sizeof(DWORD), &numBytesRead);
adresse += offset_adr;
if(offset != NULL)
delete []offset;
akt_pos += offset_lengh+1;
offset_lengh = 0;
}
cout << "NEUE ADR: " << adresse;
return adresse;
}
void TMemory::Init(char * SEARCH_ADRESS, string WINDOW_TITLE)
{
//GET PARAMS
//Search Window
while(window == NULL)
{
cout << "Suche nach Fenster: "<<WINDOW_TITLE<<" ..."<<endl;
Sleep(100);
window = FindWindow(NULL, WINDOW_TITLE.c_str());
}
cout << "Fenster gefunden!"<<endl;
//Prozess holen
GetWindowThreadProcessId(window, &prozess);
//Handle holen
handle = OpenProcess(PROCESS_ALL_ACCESS | PROCESS_VM_READ | PROCESS_VM_WRITE, FALSE, prozess);
adress = MakeAdress(SEARCH_ADRESS, &handle);
cout << endl << "******************* - "<<adress<<" - **************"<<endl;
}
void TMemory::GetValue()
{
int tempval = 0;
int errRe = ReadProcessMemory(handle, (LPCVOID)adress, &tempval, sizeof(puffer),NULL);
if(errRe == 0) {
cout << "Error Reading Memory: " << GetLastError() << endl;
} else {
value = tempval;
cout << "Wert ist: "<< value << endl;
}
}
void TMemory::WriteValue(int param)
{
int errWr = WriteProcessMemory(handle, (LPVOID)adress, ¶m,sizeof(param),&puffer);
if(errWr == 0) {
cout << "Error Writing Memory: " << GetLastError() << endl;
}
else
{
cout << "Wert "<<param<<" erfolgreich geschrieben!"<<endl;
}
}
Quote:
Originally Posted by dready
Windef.h:151 - typedef unsigned long DWORD;
:D
Denk aber auch das Dword "richtiger" wäre Oo
Aber warum das ganze nicht klappt ist ne gute Frage, errechnest du die Base selbst ?
Was hast du in offset adress wenns läuft ?
|
Wenns läuft hab ich einfach nur die aktuelle Adresse (nicht die Basepoint adresse!) von z.B. X-Pos eines Charackters vom Programm was ich geöffnet habe.