繁体   English   中英

在哪里可以找到有关Delphi VMT结构的信息?

[英]Where can I find information on the structure of the Delphi VMT?

System.pas文件包含有关硬编码VMT偏移量的大量信息,但实际上似乎并未真正说明VMT本身的结构。 我真正想知道的是,有没有办法在运行时找出VMT的大小,或者换句话说,给定类有多少虚拟方法?

你想知道VMT结构怎么样? 您还知道它是一个内部实现细节,可能会发生变化(并且随着时间的推移而发生变化)。

要回答您的具体问题,以下是查找给定类的虚拟方法数的简单方法:

function GetVirtualMethodCount(AClass: TClass): Integer;
begin
  Result := (PInteger(Integer(AClass) + vmtClassName)^ - 
    (Integer(AClass) + vmtParent) - SizeOf(Pointer)) div SizeOf(Pointer);
end;

这是有效的,因为我碰巧知道表示类名的字符串紧跟在VMT中的所有虚拟方法向量之后。

我还知道在所有TObject上有11个虚拟方法(对于D2009,对于D2007和之前的9个),它们与VMT指针本身有负向偏移。

这就是vmtParent引用的原因。

最后,通过使用TClass类引用,您可以将任何TObject派生类传递给此函数并获取虚拟方法的数量。

我很确定Hallvard在VMT上有一些东西。 果然,他有Hack#8:显式VMT调用 ,它引用了Delphi 2中的 Ray Lischner SecretsDelphi中的Delphi

这是他的黑客攻击版本的VMT

type
  PClass = ^TClass;
  PSafeCallException = function  (Self: TObject; ExceptObject:
    TObject; ExceptAddr: Pointer): HResult;
  PAfterConstruction = procedure (Self: TObject);
  PBeforeDestruction = procedure (Self: TObject);
  PDispatch          = procedure (Self: TObject; var Message);
  PDefaultHandler    = procedure (Self: TObject; var Message);
  PNewInstance       = function  (Self: TClass) : TObject;
  PFreeInstance      = procedure (Self: TObject);
  PDestroy           = procedure (Self: TObject; OuterMost: ShortInt);
  PVmt = ^TVmt;
  TVmt = packed record
    SelfPtr           : TClass;
    IntfTable         : Pointer;
    AutoTable         : Pointer;
    InitTable         : Pointer;
    TypeInfo          : Pointer;
    FieldTable        : Pointer;
    MethodTable       : Pointer;
    DynamicTable      : Pointer;
    ClassName         : PShortString;
    InstanceSize      : PLongint;
    Parent            : PClass;
    SafeCallException : PSafeCallException;
    AfterConstruction : PAfterConstruction;
    BeforeDestruction : PBeforeDestruction;
    Dispatch          : PDispatch;
    DefaultHandler    : PDefaultHandler;
    NewInstance       : PNewInstance;
    FreeInstance      : PFreeInstance;
    Destroy           : PDestroy;
   {UserDefinedVirtuals: array[0..999] of procedure;}
  end;

你需要阅读他的文章,了解有关黑客的更多信息。

谷歌搜索:-P为“德尔福vmt”产生这个 也许这会给你一个开始。

我将插入我自己的网站:

什么是虚方法表?

我认为,从Delphi 2005开始,它是准确的。

VMT没有任何给出它所拥有的虚方法指针数的值。 除了编译器需要知道该信息之外什么都没有,因此没有理由将其记录下来以便在运行时使用。

我记得有一些关于delphi vmt的信息,请参阅“delphi简介”一书。 ü可以从开始德尔福简而言之第2章

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM