Hex memory dump

I use a pointer to indicate some kind of "shared memory" that I use to exchange data between different processes / threads. Now I would like to have a hexadecimal dump of the contents of the shared buffer. Does anyone know how to do this?

thanks R

+3
source share
2 answers

Use throws, of course :-) The function should look something like this:

void Dump( const void * mem, unsigned int n ) {
  const char * p = reinterpret_cast< const char *>( mem );
  for ( unsigned int i = 0; i < n; i++ ) {
     std::cout << hex << int(p[i]) << " ";
  }
  std::cout << std::endl;
}

Then used:

Foo * f = GetSharedFoo();
Dump( f, somesize );

where somesize is what you want to dump.

+13
source

On Windows you can use ReadProcessMemory. I do not know the equivalent of Linux.

0
source

Source: https://habr.com/ru/post/1715305/


All Articles