I'm writing a memory viewer which can both display a block of process memory and dump it to file. The following function works fine.
void SomeFunction(void)
{
char* buf = (char*) 0x00123ABC;
for(int i = 0; i < bigNumber; i++)
{
fprintf(fp, "%x", *buf);
}
}
However if I try this below, the program crashes.
DWORD* temp = (DWORD*)0x00123ABC;
DWORD currAddr = *temp;
void someFunction(void)
{
char* buf = (char*) currAddr;
for(int i = 0; i < bigNumber; i++)
{
fprintf(fp, "%x", *buf); // program crash
}
}
I have to get something along these lines working as I need to be able to change what buf is pointing to from outwith the function, in order to 'page' through memory. The real function isn't void but I don't want to pass in currAddr (I still don't think that would solve it anyway).
I've come across this issue before and after a bit of experimenting, I think I've narrowed the problem down to a general case:
// variable with file scope
DWORD* somePtr = (DWORD*) 0x00123ABC;
void someFunction(void)
{
somePtr++; //crashes program
}
If somePtr has global scope, why can't I perform pointer arithmetic on it from within the function?
Compiling with MSVC++ 6.0
void SomeFunction(void)
{
char* buf = (char*) 0x00123ABC;
for(int i = 0; i < bigNumber; i++)
{
fprintf(fp, "%x", *buf);
}
}
However if I try this below, the program crashes.
DWORD* temp = (DWORD*)0x00123ABC;
DWORD currAddr = *temp;
void someFunction(void)
{
char* buf = (char*) currAddr;
for(int i = 0; i < bigNumber; i++)
{
fprintf(fp, "%x", *buf); // program crash
}
}
I have to get something along these lines working as I need to be able to change what buf is pointing to from outwith the function, in order to 'page' through memory. The real function isn't void but I don't want to pass in currAddr (I still don't think that would solve it anyway).
I've come across this issue before and after a bit of experimenting, I think I've narrowed the problem down to a general case:
// variable with file scope
DWORD* somePtr = (DWORD*) 0x00123ABC;
void someFunction(void)
{
somePtr++; //crashes program
}
If somePtr has global scope, why can't I perform pointer arithmetic on it from within the function?
Compiling with MSVC++ 6.0