EDIT- Wow, just looked at the dates, seems this forum section is very inactive.
@Billy O'Neal: Not possible, eh? Win32 API has a thing or 2 to say about that.
@Romeo29: The address is not dynamically allocated, it is actually a specific location in WinMine's data section (mainly used for global variables), so it's relative to the module handle.
A very hastily modified version of some code I wrote a long time ago to achieve a similar goal:
#include <windows.h>
#include <psapi.h>
void ToLower(char*a)
{
register int i;
register int j;
j=strlen(a);
for (i=0;i<j;i++)
if (a[i]>='A'&&a[i]<='Z')
a[i]+='a'-'A';
return;
}
int startswithi(char*haystack,char*needle)
{
char*a;
int ret;
a=malloc(strlen(haystack)+1);
strcpy(a,haystack);
a[strlen(needle)]=0;
ToLower(a);
ret=!strcmp(a,needle);
free(a);
return ret;
}
int main()
{
DWORD aProcesses[1024],cbNeeded,cProcesses,pid,read;
unsigned int i;
HANDLE process;
HMODULE module;
char procname[MAX_PATH]="";
unsigned int data,modpoint;
if (!EnumProcesses(aProcesses,sizeof(aProcesses),&cbNeeded))
return 0;
cProcesses=cbNeeded/sizeof(DWORD);
pid=0;
for (i=0;i<cProcesses;i++)
{
if (aProcesses[i]!=0)
{
process=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,0,aProcesses[i]);
if (process!=NULL)
{
if (EnumProcessModules(process,&module,sizeof(module),&cbNeeded))
{
GetModuleBaseName(process,module,procname,MAX_PATH);
}
CloseHandle(process);
if (startswithi(procname,"winmine"))
{
pid=aProcesses[i];
break;
}
}
}
}
if (pid==0)
{
MessageBox(NULL,"Could not find WinMine.","Error",0x10);
return 0;
}
process=OpenProcess(PROCESS_VM_OPERATION| PROCESS_QUERY_INFORMATION| PROCESS_VM_READ| PROCESS_VM_WRITE, 0, pid);
if (process==NULL)
{
MessageBox(NULL,"WinMine unexpectedly terminated (?)","Error",0x10);
return 0;
}
if (!EnumProcessModules(process,&module,sizeof(module),&cbNeeded))
{
MessageBox(NULL,"Could not get WinMine's module handle.","Error",0x10);
CloseHandle(process);
return 0;
}
modpoint=(unsigned int)module;
modpoint+=0x579C; //0x0100579C
if (!ReadProcessMemory(process,(void*)modpoint,&data,sizeof(data),&read))
{
i=GetLastError();
MessageBox(NULL,"Could not read WinMine's memory.","Error",0x10);
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,i,0,procname,sizeof(procname),NULL);
MessageBox(NULL,procname,"Description",0);
CloseHandle(process);
return 0;
}
data=0; //Reset the timer to zero
if (!WriteProcessMemory(process,(void*)modpoint,&data,sizeof(data),&read))
{
MessageBox(NULL,"Could not write to WinMine's memory.","Error",0x10);
CloseHandle(process);
return 0;
}
MessageBox(NULL,"Success!","Go wild!",0x40);
CloseHandle(process);
return 0;
}
I wrote this for use with MinGW, the command line is:
gcc -o ptr.exe ptr.c -Os -s -lpsapi
If you're using Dev-C++, Code::Blocks, MSVC++, etc., then you'll need to find somewhere in the project settings how to add psapi to your libraries you are linking to (if you have to find it in a bunch of files, it'll probably be "psapi.lib" or "libpsapi.a").
This post has been edited by Score_Under: 26 July 2009 - 09:06 AM