I would like to concatenate 2 non-string types so i can use them as one. This is the main kind of part of my code:
#include<stdio.h>
#include<string.h>
#include<windows.h>
int main() {
HANDLE hwnd = FindWindowA(NULL, "MyProgram");
DWORD ProcessId; GetWindowThreadProcessId(hwnd, &ProcessId);
HANDLE handler = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ProcessId);
... ??? (type im not sure about) = 0x; ??? ...
... ??? (type im not sure about) MemoryAddress; ??? ...
int ValueOfAddress;
ReadProcessMemory(handle, (LPVOID)(concatenated 0x+MemoryAddress), &ValueOfAddress, sizeof(ValueOfAddress), 0);
printf("Value Of Address %? Is %d", (concatenated 0x+MemoryAddress), ValueOfAddress);
return 0;
}
I need to concatenate 0x to a Memory Address that I find via ReadProcessMemory (E.G. 0x0023DA44, 0x being 0x and 0023DA44 being what the value is read from the Memory). Thanks for any help given :) sorry if this doesn't make sense im not very good at explaining. Basically I need to know how to concatenate to DWORD Data Types in order to get a memory address type variable. Any help if greatly appreciated!
If I understood correctly you want to convert a value from a string containing e.g. "DEADBEEF"
to the integer value 0xDEADBEEF
? You are looking for the strtol
family of functions.
void *ptr = (void *)strtoull("DEADBEEF", NULL, 16);
You can then do:
ReadProcessMemory(handle, ptr, &ValueOfAddress, sizeof(ValueOfAddress), 0);
printf("Value Of Address %p Is %d", ptr, ValueOfAddress);
Note that there is no error checking in that code (in particular, you should check that the value fits into a pointer and the string is valid hex).