[英]Virtual Function Table entry from class that is not related
I am browsing through VFTs (VMTs) of a simple C++ Windows program (I don't have a source code, only binary), compiled by Visual Studio with some sort of optimization on. 我正在浏览一个简单的C ++ Windows程序(我没有源代码,只有二进制文件)的VFT(VMT),这些程序是由Visual Studio编译并进行了某种优化的。
I noticed that is uses inheritance and polymorphism. 我注意到这是使用继承和多态性。 I found the location of struct
s_RTTIBaseClassArray
for each class that the program has. 我找到了程序具有的每个类的struct
s_RTTIBaseClassArray
的位置。 In that location there is an array of pointers to struct _s_RTTIBaseClassDescriptor
. 在该位置,有一个指向
_s_RTTIBaseClassDescriptor
的指针数组。 The array of base class descriptors should give you information about all the classes that the current class is derived from. 基类描述符数组应为您提供有关当前类所源自的所有类的信息。
Virtual Function (Method) Table is a table that contains pointers to all the virtual functions of the current class. 虚函数(方法)表是一个表,其中包含指向当前类的所有虚函数的指针。 However in VFT of a few classes I found a pointer to a virtual method that actually belongs to a different class that is (acording to the Base Class Array) not related to the current class.
但是在一些类的VFT中,我找到了一个指向虚拟方法的指针,该方法实际上属于另一个类(根据基类数组),该类与当前类不相关。 Example below:
下面的例子:
ClassA_BaseClassArray:
dd offset ClassA_BaseClassDescriptor
dd offset ClassB_BaseClassDescriptor ; ClassA inherits from ClassB
ClassB_BaseClassArray:
dd offset ClassB_BaseClassDescriptor
ClassC_BaseClassArray:
dd offset ClassC_BaseClassDescriptor
ClassA_VMT:
dd offset ClassA_VM1 ; virtual method of ClassA
dd offset ClassA_VM2
dd offset ClassB_VM2 ; virtual method of ClassB - override
dd offset ClassC_VM3 ; virtual method of ClassC - NOTHING TO DO HERE
dd offset ClassA_VM3
The example is short, the actual classes have much more virtual methods. 这个例子很简短,实际的类有更多的虚方法。
After examination of ClassC_VM3
I noticed, that it consists of just two instructions: 在检查
ClassC_VM3
之后,我注意到它仅由两条指令组成:
mov eax, [ecx+10h]
retn
I found about 3 VMTs similar to this example so far, the unrelated method is always this short. 到目前为止,我发现大约有3个VMT与该示例相似,无关的方法总是这么短。
My question is: what is causing this? 我的问题是:是什么原因造成的? Could the code of
ClassC_VM3
be identical to the code of some ClassA
method, so the compiler just optimized it out? ClassC_VM3
的代码ClassC_VM3
可以与某些ClassA
方法的代码相同,所以编译器刚刚对其进行了优化?
This might be caused by COMDAT folding , an optimization that merges functions that have the same exact machine code into one. 这可能是由COMDAT折叠引起的,该优化将具有完全相同的机器代码的功能合并为一个优化。 Since it's such a simple function the chances of that are good.
由于它是如此简单的功能,因此机会很大。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.