Skip to content

Instantly share code, notes, and snippets.

@hpcx82
Created December 8, 2012 12:40
Show Gist options
  • Save hpcx82/4240126 to your computer and use it in GitHub Desktop.
Save hpcx82/4240126 to your computer and use it in GitHub Desktop.
Display address of program segments
#include <iostream>
using namespace std;
// .data - read-write data
int rwdata = 100;
// .rodata - read-only data
const char* rodata = "hello, world";
// .bss - non-initialized data
int bssdata;
// .text
void text_code()
{
cout << "text_code" << endl;
}
class VTableTest
{
public:
virtual void virtualfunc()
{
cout << "virtualfunc" << endl;
}
};
int main()
{
cout << ".data: " << &rwdata << endl;
cout << ".rodata: " << reinterpret_cast<const void*>(rodata) << endl;
cout << ".bss: " << &bssdata << endl;
cout << ".text-normal-function: " << reinterpret_cast<void*>(text_code) << endl;
VTableTest* pV = new VTableTest();
long* pVlong = reinterpret_cast<long*>(pV);
void* vptr = reinterpret_cast<void*>(*pVlong);
cout << ".rodata-vtable: " << vptr << endl;
}
@hpcx82
Copy link
Author

hpcx82 commented Dec 8, 2012

@hpcx82
Copy link
Author

hpcx82 commented Dec 11, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment