How to hack the virtual table?

前端 未结 9 874
谎友^
谎友^ 2021-01-31 21:41

I would like to know how to change the address of Test which is in the virtual table with that of HackedVTable.

void HackedVtable()
{
           


        
9条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-31 22:00

    I don't think there is a portable way. Mostly because of compiler optimization and different architecture ABI between every target.

    But C++ provides you with that exact same capability, why not use it?

    void HackedVtable()
    {
        cout << "Hacked V-Table" << endl;
    }
    
    class Base
    {
    public:
           virtual Test()  { cout <<"base";    }
           virtual Test1() { cout << "Test 1"; }
           void *prt;
           Base(){}
    };
    
    class Derived : public Base
    {
        public: 
               Test() 
               {
                    HackedVtable(); // <-- NOTE
               }
    };
    
    int main()
    {
        Derived b1; // <-- NOTE
    
        b1.Test();
    
        return 0;
    }
    

提交回复
热议问题