Skip to content

Instantly share code, notes, and snippets.

@baiyanhuang
Created December 8, 2012 12:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save baiyanhuang/4240126 to your computer and use it in GitHub Desktop.
Save baiyanhuang/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;
}
@baiyanhuang
Copy link
Author

@baiyanhuang
Copy link
Author

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