title: Completely overriding the VMT (Virtual Method Table)
body: <p>I'm calling a virtual method on the vmt by dereferencing until I get the pointer to the method.</p>
  <p><strong>This is all good however, how would I completely change the pointer to the VM table on the object?</strong></p>
  <p><em><strong>Example:</strong></em></p>
  <blockquote>
  <p>PP A; // points to its default VM table</p>
  <p>PP B; // points to a completely different VM table</p>
  <p>A-&gt;MethodOne() // calls as mentioned above</p>
  <p>B-&gt;MethodOne() // calls a completely different method since we override its pointer to the VM table to an alternate table with different method pointers</p>
  </blockquote>
  <p>How would I accomplish this?</p>
  <p><em><strong>My Code:</strong></em></p>
  <pre><code>#include &lt;Windows.h&gt;
  #include &lt;iostream&gt;
  
  class PP
  {
  public:
      PP() { }
      ~PP() { }
  
      virtual void MethodOne() { std::cout &lt;&lt; &quot;1&quot; &lt;&lt; std::endl; }
      virtual void MethodTwo() { std::cout &lt;&lt; &quot;2&quot; &lt;&lt; std::endl; }
  };
  
  typedef void (*MyFunc)(void);
  
  int main()
  {
      PP* A = new PP();
  
      //(*(void(**)(void))(*(DWORD*)A + (4*1)))();
                        
      ( *(MyFunc*) ( *(DWORD*)A + (4*0) ) )(); // call index 0 (4bytes*0)
      A-&gt;MethodOne();
      A-&gt;MethodTwo();
      system(&quot;PAUSE&quot;);
      delete A;
      return 0;
  }
  </code></pre>