Created
September 30, 2010 01:55
-
-
Save mitsuji/603898 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iomanip> | |
// int version | |
void memdumpi(void* vptr, size_t len) | |
{ | |
std::cout << ">>>> memdump(int) ---------------------------" << std::endl; | |
unsigned int* cptr = reinterpret_cast<unsigned int*>( vptr ); | |
for (size_t i=0; i<(len/sizeof(int)); ++i ) | |
{ | |
if ( i%4 == 0 ) | |
{ | |
if ( i != 0 ) std::cout << std::endl; | |
std::cout << std::hex << std::setw(8) << std::setfill('0'); | |
std::cout << reinterpret_cast<int>(&cptr[i]) << ": "; | |
} | |
std::cout << std::hex << std::setw(8) << std::setfill('0'); | |
std::cout << static_cast<int>(cptr[i]) << " " ; | |
} | |
std::cout << std::endl; | |
std::cout << "--------------------------- memdump(int) <<<<" << std::endl; | |
} | |
// char version | |
void memdumpc(void* vptr, size_t len) | |
{ | |
std::cout << ">>>> memdump(char) --------------" << std::endl; | |
unsigned char* cptr = reinterpret_cast<unsigned char*>( vptr ); | |
for (size_t i=0; i<len; ++i ) | |
{ | |
if ( i%8 == 0 ) | |
{ | |
if ( i != 0 ) std::cout << std::endl; | |
std::cout << std::hex << std::setw(8) << std::setfill('0'); | |
std::cout << reinterpret_cast<int>(&cptr[i]) << ": "; | |
} | |
std::cout << std::hex << std::setw(2) << std::setfill('0'); | |
std::cout << static_cast<int>(cptr[i]) << " " ; | |
} | |
std::cout << std::endl; | |
std::cout << "-------------- memdump(char) <<<<" << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment