4.7. MemDump Class

MemDump converts raw binary memory array into HEX/ASCII representation, much like od(1) does.

4.7.1. DEFINITION


class MemDump 
{
public:
    MemDump (const char* msg_, int len_);

    const char* getMemDump() const;

    static void dump_to_log (u_long mask_, const char* info_, 
                             const char* msg_, int len_);
};
	  

4.7.2. USAGE


void foo (const char* raw_data_, int len_)
{
    MemDump mdump (raw_data_, len_);

    DebugMsg(TRACE, "[foo]\n%s", mdump.getMemDump());
}
	  

The piece of the code above might write (depending on the content of your raw_data_ array) something like this to the log file:


7177 6572 7479 7569 6f70 6173 6466 6768  qwertyuiopasdfgh
6a6b 6c7a 7863 7662 6e6d 6173 6466 6768  jklzxcvbnmasdfgh
76                                       v
	  

If control characters are present in the binary array, they will be preceded by '\':


32 control characters:

0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a  \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a 0a0a  \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
	  

A convenience function dump_to_log(), instead of returning a std::string, dumps a hexadecimal representation of your memory chunk directly to the log file.