Home Delphi 64-Bit Code Hook Possible for Runtime VCL Style AV?
Reply: 0

Delphi 64-Bit Code Hook Possible for Runtime VCL Style AV?

DelphiGuy Published in 2017-11-08 19:10:57Z

It appears as though there may not be a user solution without a Delphi Tokyo fix, but it seems worth asking.

The simplest way to make this AV reproducible.

  1. Start a new VCL project.
  2. Change Platform to 64-Bit.
  3. Link with Runtime Packages.
  4. Set Style to "Amakrits".
  5. Add High Entropy ASLR Flag. Note - This surfaces out a lot of Win64 bugs.

My Dpr file looks like this (there is no code in the main unit).

program MaskedCrash2;

{$SETPEOPTFLAGS $160} //High Entropy ASLR Flag causes issues with incorrect 64-bit programs.

  MaskedCrashed2MainUnt in 'MaskedCrashed2MainUnt.pas' {Form3},

{$R *.res}

  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TForm3, Form3);

The AV appears in Delphi Tokyo in StyleUtils.inc in the procedure TseBitmapLink.CheckingMasked(const Margin: TRect); .

Despite the warning I just recently found at the top of StyleUtils.inc:

//TODO -oUnassigned -cImplement : x64 : Implement PlatformNotImplemented in this unit or disable for x64.

This part of the code was very stable in Delphi Berlin. Dialogs are another matter as posts here show. I have submitted the offending code to the Quality Portal.

Note: In order to get High Entropy ASLR (as shown by process explorer), using runtime packages and setting the High Entropy bit ($20) is necessary as well as $40 for DEP and $100 for ASLR.

In addition to making a program more secure, using High Entropy ASLR has definitely contributed to finding errors in Windows Messages (e.g. using Integer cast in SendMessage, etc.). Using High Entropy ASLR caught many errors in my code when switching to 64-bit that were being masked.

Recompiling Runtime Packages does not seem to be a possibility and using a runtime hook was correctly suggested.

However, the method procedure TseBitmapLink.CheckingMasked(const Margin: TRect); is included in the implementation section:


  System.Types, System.UITypes, System.SysUtils, Winapi.UxTheme, Vcl.StdCtrls, Vcl.ComCtrls,
  Vcl.Mask, Vcl.GraphUtil, Vcl.ImgList, Vcl.Menus, Vcl.Grids, Vcl.CategoryButtons,
  Vcl.ButtonGroup, Vcl.ExtCtrls, Vcl.Consts, Vcl.SysStyles;

{$I StyleUtils.inc}
{$I StyleAPI.inc}

So is there any way to use a runtime hook as the TseBitmapLink is not available to end users who use runtime packages?

Is this correct?

Does anyone have any suggestions for keeping High Entropy ASLR and Delphi Tokyo?

Sorry this took so long, trying to be complete.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.673598 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO