Ok, I've been working on this peice of code for about 4 days now. It still won't work. I've looked up every google peice of infortmation I could think of. What I'm trying to do is hex dump single values of another program (Google had one for hex dumping the entire program, I found it thanks to nvoight). Failing at so much as reproducing that example, I tried at least displaying a single value from my own program. And that's my current failed attempt -,-.
I'm getting the error codes (299, ReadProcessMemory or WriteProcessMemory could not be completed.) Sence I only use ReadProcessMemory, it has to be that. Error code 998 I have no idea what this error means... At all. I'll quote msdn though; (Multiply accumulate instruction used without /QMR4121, /QMViper, /QMR5400, /QMmips32, or /QMmips64)
Now, I thought I could Read my own process' memory without giving it tokens. I tried giving the debug priviledge token, but it doesn't change anything. Token granting code;
Code:
HANDLE TokenHandle;
LUID debugid;
TOKEN_PRIVILEGES tp;
LookupPrivilegeValue(NULL, "SeDebugPrivilege", &debugid);
tp.Privileges[0].Luid = debugid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(TokenHandle, FALSE, &tp, NULL, NULL, NULL);
The rest is pritty simple, this is my current test program, it outputs the last error repeatdly. It also crashs after a small amount of time. I thought it would be easier to try with my own program, but it's just making things more complicated >.<.
Code:
#include <iostream>
#include <windows.h>
#include <conio.h>
#include <String.h>
using namespace std;
int* Search(int SearchValue, HANDLE op, DWORD add) {
MEMORY_BASIC_INFORMATION mbi;
SYSTEM_INFO sys;
LPVOID lpMem;
string buffer;
GetSystemInfo(&sys);
lpMem = sys.lpMinimumApplicationAddress;
while(lpMem < sys.lpMaximumApplicationAddress) {
mbi.RegionSize = 0;
VirtualQueryEx(op, lpMem, &mbi, sizeof(mbi));
ReadProcessMemory(op, &add, &buffer, mbi.RegionSize, NULL);
lpMem = (LPVOID)((DWORD)mbi.BaseAddress + (DWORD)mbi.RegionSize);
cout << GetLastError() << endl;
}
return 0;
}
int main() {
int srak = 4;
HANDLE CURRENTPROCESS = GetCurrentProcess();
DWORD ProcessId;
HANDLE tProc;
tProc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, GetCurrentProcessId());
if(!tProc) {
cout << "Could not open the process o-O";
getch();
return 0;
}
cout << *Search(srak, tProc, ProcessId);
}
From reading all thoes google tutorials, I actualy understand the virtual memory quite well, but accessing it seems to be a really vague subject (Or maybe I just suck at searching) I've seen tutorials for hex dumping my own program without treating my program as if I don't control it, but that's not helpful to me.
-Thank you for any help -,-.