Bug 56071 - Mono.Security.AuthenticodeBase Doesn't Support PE32+ image format
Summary: Mono.Security.AuthenticodeBase Doesn't Support PE32+ image format
Alias: None
Product: Class Libraries
Classification: Mono
Component: Mono.Security ()
Version: master
Hardware: PC All
: --- normal
Target Milestone: Future Release
Assignee: jaykrell
Depends on:
Reported: 2017-05-05 20:37 UTC by Sam Karim
Modified: 2018-02-11 16:30 UTC (History)
3 users (show)

Tags: bugpool-archive
Is this bug a regression?: No
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Sam Karim 2017-05-05 20:37:16 UTC
From Mono.Security.Authenticode.AuthenticodeBase

Lines 160/161
  dirSecurityOffset = BitConverterLE.ToInt32 (fileblock, peOffset + 152);
  dirSecuritySize = BitConverterLE.ToInt32 (fileblock, peOffset + 156);

The dirSecurityOffset should actually vary based on PE32 or PE32+. Official documentation from Microsoft:

On PE32+, the "Correct" values are 16 bytes bigger. So this code works on PE32+

  dirSecurityOffset = BitConverterLE.ToInt32 (fileblock, peOffset + 152 + 16
  dirSecuritySize = BitConverterLE.ToInt32 (fileblock, peOffset + 156 + 16);

You can determine if a binary is PE32 or PE32+ based on the "magic number" (Microsoft's words!) found here:

  UInt16 magicNumber = BitConverter.ToUInt16(firstBlock, peOffset + 0x18);

magicNumber 0x10b (PE32) vs 0x20b (PE32+) can be used to calculate the correct offset (152 | 152 + 16).
Comment 1 Marek Safar 2017-09-29 15:44:50 UTC
I think even more values needs to be updated according to https://msdn.microsoft.com/en-us/library/windows/desktop/ms680547(v=vs.85).aspx

Simplest way to create PR32+ is

csc /platform:x64 foo.cs
Comment 2 Ludovic Henry 2018-01-16 20:27:43 UTC