I tried to get the adress of the variable which contains the String/Value "Systemname" or "Microsoft Corporation".
(of the window "Systeminformationen").
Using FindWindows,GetWindowThreadProcessID,Process32First|Next,CreateToolhelpSnapshot etc
,I create an array ,which contains the PROCESSENTRY32 of the
target Process(which appendet to "Systeminformation") and
of his parent process and of all his threads and child processes.
(of course that is redundant,but I want to play it safe)
->I think,this part of my programm works fine
Then I used OpenProcess,VirtualQueryEx for getting the memory of every single Process.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
void GetMemory(DWORD proc_ID,char* target_buf){
MEMORY_BASIC_INFORMATION mbi;
unsigned int adress = 0x100000;
unsigned int start=0;
unsigned int end=0;
HANDLE hproc;
hproc=OpenProcess(PROCESS_ALL_ACCESS,false,proc_ID);
do
{
VirtualQueryEx( //öffnet Speicher des Prozesses
hproc,
(void*)adress,
&mbi,
sizeof(MEMORY_BASIC_INFORMATION)
);
if((mbi.State == MEM_COMMIT) //--Speicher beantsprucht
){
start = (uint)mbi.BaseAddress;
end = (uint)mbi.BaseAddress+mbi.RegionSize;
ScanMemory(start,end,target_buf,hproc);
}
adress += mbi.RegionSize;
} while(adress < 0x80000000 && !(ERROR_INVALID_PARAMETER==GetLastError()));
if(!(ERROR_INVALID_PARAMETER==GetLastError())){
printf("MemoryAdresse too high 0x%x\n",adress);
}
CloseHandle(hproc);
}
|
Searching for "Systemname",I rifled through all of this memory-blocs
but I didn´t get any satisfying result.
( of course ,there were matches,but they seemd to be part of a kind of manual)
void ScanMemory(DWORD start, DWORD end,char* target_buf,HANDLE hproc){
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
void ScanMemory(DWORD start, DWORD end,char* target_buf,HANDLE hproc){
void* save_buf;
uint sizebuffer=end-start;
void* buffer=(void*) malloc(sizebuffer); //buffer for memory
DWORD read = 0;
uint count=0;
uint i=0;
//check both formats
//wchar_t is 2byte -> Unicode
//char is 1 Byte -> Ansi
wchar_t* target_buf_wide=(wchar_t*) malloc((strlen(target_buf)+1)*sizeof(wchar_t));
//transform a Ansi-String into a Unicode-String
MultiByteToWideChar (CP_ACP, 0, target_buf, -1,target_buf_wide,(strlen(target_buf)+1));
//Reading Memory
ReadProcessMemory(
hproc,
(void*)start,
buffer,
sizebuffer,
&read
);
save_buf=buffer;
//interpretation as char
for(;sizeof(char)*count<sizebuffer;){
if(target_buf[i]==*((char*)buffer)){
//check if agree with memory
i++;
if(i==strlen(target_buf)){ //strlen(target_buf) checks in a row -> match
printf("< %s > gefunden an 0x%x \n",target_buf,(start+(DWORD)(count*sizeof(char))));
i=0;
}
}
else{
if(i>0){
count=count-i; //go on after first match
buffer=(void*)((uint)buffer-(uint)(i*sizeof(char))); //","
i=0;}}
count++;
buffer=(void*)((uint)buffer+(uint)sizeof(char));
}
buffer=save_buf;
//interpretation as wchar_t
//, -----------------in a similar manner-----------------
for(count=0;sizeof(wchar_t)*count<sizebuffer;){
if(target_buf_wide[i]==*((wchar_t*)buffer)){ //check if agree with memory
i++;
if(i==strlen(target_buf)){
printf("< %s > gefunden an 0x%x \n",target_buf,(start+(DWORD)(count*sizeof(wchar_t))));
i=0;
}
}
else{
if(i>0){
count=count-i; //go on after first match
buffer=(void*)((uint)buffer-(uint)(i*sizeof(wchar_t))); //
i=0;}}
count++;
buffer=(void*)((uint)buffer+(uint)sizeof(char));
}
free(save_buf_2);
free(target_buf_wide);
}
|
Where are my mistakes?
I searched on Heaps,Stacks, etc but i could not find
this variable?!
Where could it be?
btw. I use Microsoft Windows 7 Professional.