Hi,
I'm new to C++ so please help me...
I have an address in memory, and I want to print out 100 bytes from this address on.
one by one in HEX.
How do I do that?
Thanks
Hi,
I'm new to C++ so please help me...
I have an address in memory, and I want to print out 100 bytes from this address on.
one by one in HEX.
How do I do that?
Thanks
You'll probably cause your program to crash. But, if you want to try, show us what you have and we'll go from there.
ok...
The pointer to the data is in the second cell in a given array (parameter to my function). and I take it like this:
All this code is trying to everything with int... and I want byte by byte...Code:void myFunction(void** const args) { DWORD32* datapointer = (DWORD32*)(args[1]); // if I print out this datapointer I get good address, I checked with some memview. for (int i=0; i<100; i++) { int val = (int)(*datapointer); // the values that I get in val, are not what I expect... datapointer++; } }
no idea how to do that...
seems that I'm way off...
Thanks for your help!
It would be easier to think about if you had the pointer passed as a separate arg.
It would also be a lot easier if you accessed datapointer as an array of DWORD32s rather than doing pointer arithmetic. Pointer arithmetic can be confusing even for the best of us.Code:void myFunction(DWORD32 *datapointer) { // use datapointer }
But remeber that DWORDs are 4 bytes, so you could use uint8_t, a type defined in stdint.h.Code:void myFunction(DWORD32 *datapointer) { for (int i=0; i<100; i++) { DWORD32 val = datapointer[i]; // print val } }
Code:#include <stdint.h> // required for uint8_t void myFunction(uint8_t *datapointer) { for (int i=0; i<100; i++) { uint8_t val = datapointer[i]; cout << (unsigned int)val; } }
Last edited by User Name:; 01-25-2011 at 04:24 PM.
Thanks! it was VERY helpful!
now maybe we can go on with the last thing that I have here...
On this array I have 4 bytes that I don't need (just skip them)
After that, I have a string (terminated by 0), I need to print it out.
after that, another 4 useless bytes.
and after that, an int that I need to print too...
please please....
THANKS!
bump
comon if this is soooo easy, can someone post a short code that does that?
I'll pay $1000... well ok not.. but I'll be thankful
Yeah, so easy, we're waiting for you to make a stab at it.
You've already got all the components you need, all it now needs from you is a bit of application to the problem.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.