| View previous topic :: View next topic |
| Author |
Message |
Onelio Newbie cheater
Reputation: 0
Joined: 22 Mar 2016 Posts: 20
|
Posted: Fri Mar 25, 2016 12:32 pm Post subject: WriteProcessMemory with pointers in c++ |
|
|
Hello!
I'm trying to write a program in c++ using WriteProcessMemory to change this address i.stack.imgur(.)com/jQMds.png
Before finding in a lot of post I found a way and i tried this:
| Code: | #include <windows.h>
#include <iostream>
int main() {
HWND hWnd = FindWindow(0, "WindowName");
if (hWnd == 0) {
std::cout << "Cannot find window." << std::endl;
}
DWORD pId;
GetWindowThreadProcessId(hWnd, &pId);
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pId);
DWORD baseAddress = 0x009B03D0;
DWORD offset = 0xA7;
DWORD ptrAddress;
char *newString = "newvalue";
ReadProcessMemory(hProc, (void*)baseAddress, &ptrAddress, sizeof(DWORD), 0);
WriteProcessMemory(hProc, (void*)(ptrAddress + offset), newString, strlen(newString), 0);
std::cout << "Done. " << &ptrAddress << std::endl;
std::getchar();
} |
The problem is that it's not working and I don't know why.
Can Somebody help me pls?
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Fri Mar 25, 2016 4:26 pm Post subject: |
|
|
99.9% of the time it is going to fail due to 'PROCESS_ALL_ACCESS'.
You should do some error checking and see where the code is actually failing though. Check return values etc. You can use GetLastError() if something fails to find the reason.
As for using PROCESS_ALL_ACCESS, you shouldn't. You should be only using the specific flags that you need. Otherwise you need Administrative privileges as well as proper debug access to use 'PROCESS_ALL_ACCESS' properly.
_________________
- Retired. |
|
| Back to top |
|
 |
Onelio Newbie cheater
Reputation: 0
Joined: 22 Mar 2016 Posts: 20
|
Posted: Fri Mar 25, 2016 6:20 pm Post subject: |
|
|
I know about that, but I need this permision.
I've changed the code but now I've problems with the WriteProcessMemory, It's not Working.. But Reading works fine
| Code: | int main()
{
unsigned long Pointer; /* to hold the final value */
unsigned long temp; /* hold the temp values */
unsigned long address = 0x009B03D0;
unsigned long offset = 0xA7;
char *newString = "dosydosespesypes";
size_t sz = strlen(newString);
SIZE_T bytes_read = 0, bytes_written = 0;
DWORD pid;
HWND hwnd;
hwnd = FindWindow(0, TEXT("NewWindow"));
if (!hwnd)
{
cout << "Process Not Found!\n";
cin.get();
}
else
{
GetWindowThreadProcessId(hwnd, &pid);
HANDLE phandle = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
if (!phandle)
{
cout << "Unknown error...!\n";
cin.get();
}
else
{
while (1)
{
ReadProcessMemory(phandle, reinterpret_cast<LPVOID>(address), &temp, sizeof(temp), 0);
Pointer = temp + offset;
//Good
if (!WriteProcessMemory(phandle, reinterpret_cast<unsigned*>(Pointer), (LPCVOID)newString, sz, &bytes_written))
std::cerr << "Couldn't write process memory:" << GetLastError() << std::endl;
cout << reinterpret_cast<LPVOID>(Pointer) << " en " << newString << std::endl;
Sleep(1000);
}
return 0;
}
}
} |
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat Mar 26, 2016 12:28 am Post subject: |
|
|
If it fails to write then it probably lacks permission. Use VirtualProtectEx on the address to adjust the permissions on it to allow writing.
_________________
- Retired. |
|
| Back to top |
|
 |
Onelio Newbie cheater
Reputation: 0
Joined: 22 Mar 2016 Posts: 20
|
Posted: Sat Mar 26, 2016 7:31 am Post subject: |
|
|
| atom0s wrote: | | If it fails to write then it probably lacks permission. Use VirtualProtectEx on the address to adjust the permissions on it to allow writing. |
Thank you so much!!!!!!!
Now I tested it and I've another problem... Because when I read the BaseAddress Pointer, it gives me a diffrent one that CE.
i.gyazo(.)com/4a654cdf7b2308f37957c491e6e7fd02.png
(The program gives me a random one..)
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat Mar 26, 2016 6:51 pm Post subject: |
|
|
How are you getting the base address? That will determine what the problem is.
_________________
- Retired. |
|
| Back to top |
|
 |
|