Skip to content

Instantly share code, notes, and snippets.

@hpcx82
Created December 8, 2012 12:40
Show Gist options
  • Select an option

  • Save hpcx82/4240126 to your computer and use it in GitHub Desktop.

Select an option

Save hpcx82/4240126 to your computer and use it in GitHub Desktop.

Revisions

  1. hpcx82 revised this gist Dec 8, 2012. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions programsegment.cpp
    Original file line number Diff line number Diff line change
    @@ -29,13 +29,13 @@ class VTableTest
    int main()
    {
    cout << ".data: " << &rwdata << endl;
    cout << ".rodata: " << &rodata << 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 << ".text-vtable: " << vptr << endl;
    }
    cout << ".rodata-vtable: " << vptr << endl;
    }
  2. hpcx82 created this gist Dec 8, 2012.
    41 changes: 41 additions & 0 deletions programsegment.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    #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: " << &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 << ".text-vtable: " << vptr << endl;
    }