-
-
Save retep998/9503145841a61551d3c6 to your computer and use it in GitHub Desktop.
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
auto bar2 = &bar; | |
00007FF6163D6647 lea rax,[bar] | |
00007FF6163D664B mov qword ptr [rbp+28h],rax | |
auto n = bar.func1(); | |
00007FF6163D664F lea rcx,[bar] | |
00007FF6163D6653 call Bar::func1 (07FF6163D11F4h) | |
00007FF6163D6658 mov dword ptr [rbp+44h],eax | |
auto foo = bar.func2(); | |
00007FF6163D665B lea rdx,[rbp+68h] | |
00007FF6163D665F lea rcx,[bar] | |
00007FF6163D6663 call Bar::func2 (07FF6163D137Fh) | |
auto bar2 = reinterpret_cast<WrongBarCOM*>(&bar); | |
00007FF6163D66CD lea rax,[bar] | |
00007FF6163D66D1 mov qword ptr [rbp+88h],rax | |
auto n = bar2->vtbl->func1(&bar); | |
00007FF6163D66D8 mov rax,qword ptr [rbp+88h] | |
00007FF6163D66DF mov rax,qword ptr [rax] | |
00007FF6163D66E2 lea rcx,[bar] | |
00007FF6163D66E6 call qword ptr [rax] | |
00007FF6163D66E8 mov dword ptr [rbp+0A4h],eax | |
auto foo = bar2->vtbl->func2(&bar); | |
00007FF6163D66EE mov rax,qword ptr [rbp+88h] | |
00007FF6163D66F5 mov rax,qword ptr [rax] | |
00007FF6163D66F8 lea rcx,[bar] | |
00007FF6163D66FC call qword ptr [rax+8] | |
00007FF6163D66FF mov qword ptr [rbp+204h],rax | |
00007FF6163D6706 mov rax,qword ptr [rbp+204h] | |
00007FF6163D670D mov qword ptr [rbp+0C8h],rax | |
auto bar2 = reinterpret_cast<CorrectBarCOM*>(&bar); | |
00007FF6163D6782 lea rax,[bar] | |
00007FF6163D6786 mov qword ptr [rbp+0E8h],rax | |
auto n = bar2->vtbl->func1(&bar); | |
00007FF6163D678D mov rax,qword ptr [rbp+0E8h] | |
00007FF6163D6794 mov rax,qword ptr [rax] | |
00007FF6163D6797 lea rcx,[bar] | |
00007FF6163D679B call qword ptr [rax] | |
00007FF6163D679D mov dword ptr [rbp+104h],eax | |
Foo foo; | |
bar2->vtbl->func2(&bar, &foo); | |
00007FF6163D67A3 mov rax,qword ptr [rbp+0E8h] | |
00007FF6163D67AA mov rax,qword ptr [rax] | |
00007FF6163D67AD lea rdx,[rbp+128h] | |
00007FF6163D67B4 lea rcx,[bar] | |
00007FF6163D67B8 call qword ptr [rax+8] |
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; | |
struct Foo { | |
int a; | |
int b; | |
}; | |
struct Bar { | |
virtual int __stdcall func1() { | |
return 273; | |
} | |
virtual Foo __stdcall func2() { | |
return { 100, 200 }; | |
} | |
}; | |
struct WrongBarVtbl { | |
int(*__stdcall func1)(Bar *); | |
Foo(*__stdcall func2)(Bar *); | |
}; | |
struct WrongBarCOM { | |
WrongBarVtbl * vtbl; | |
}; | |
struct CorrectBarVtbl { | |
int(*__stdcall func1)(Bar *); | |
Foo*(*__stdcall func2)(Bar *, Foo *); | |
}; | |
struct CorrectBarCOM { | |
CorrectBarVtbl * vtbl; | |
}; | |
int main() { | |
Bar bar{}; | |
{ | |
auto bar2 = &bar; | |
auto n = bar.func1(); | |
auto foo = bar.func2(); | |
cout << "C++: " << n << ", " << foo.a << ", " << foo.b << endl; | |
} | |
{ | |
auto bar2 = reinterpret_cast<WrongBarCOM*>(&bar); | |
auto n = bar2->vtbl->func1(&bar); | |
auto foo = bar2->vtbl->func2(&bar); | |
cout << "Wrong: " << n << ", " << foo.a << ", " << foo.b << endl; | |
} | |
{ | |
auto bar2 = reinterpret_cast<CorrectBarCOM*>(&bar); | |
auto n = bar2->vtbl->func1(&bar); | |
Foo foo; | |
bar2->vtbl->func2(&bar, &foo); | |
cout << "Correct: " << n << ", " << foo.a << ", " << foo.b << endl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment