Created
December 8, 2012 12:40
-
-
Save hpcx82/4240126 to your computer and use it in GitHub Desktop.
Display address of program segments
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> | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://www.cnblogs.com/baiyanhuang/admin/EditPosts.aspx?opt=1