// Memory dump and overflow example // Written by Lee Devlin 1-19-2011 #include using namespace std; void print_bytes(const void *object, size_t size); int main() { char a = 'h'; int b =10; int c = 3000000000; //attempt to set int to number larger than it can hold // hint: set it to type 'unsigned' and see what happens char d[] = "hello world"; float e = 2.0; cout << "a is an character set to " << a << endl; cout << "b is an integer of value " << b << endl; cout << "c is an integer of value " << c << endl; // note it won't look like 3 billion... cout << "d is a string that is set to " << d << endl; cout << "e is a floating point number set to " << e << endl; cout << "Here are the hex dumps of these variables:" << endl; cout << "a is "; print_bytes(&a, sizeof a); cout << "b is "; print_bytes(&b, sizeof b); cout << "c is "; print_bytes(&c, sizeof c); cout << "d is "; print_bytes(&d, sizeof d); cout << "e is "; print_bytes(&e, sizeof e); system ("pause"); } void print_bytes(const void *object, size_t size) { size_t i; printf("[ "); for(i = 0; i < size; i++) { printf("%02x ", ((const unsigned char *) object)[i] & 0xff); } printf("]\n"); }