1

Our company has been able to successfully modify the PE Header of our compiled binaries using a third-party tool called Resource Hacker over the last few years. It has been working really well for all C++ and C# binaries after the compilation process.

With the introduction of dotnet.exe publish command as single-file by Microsoft in our build process, several binaries are now packed into a single executable bundle file. We have noticed that any modification done to the PE Header of this executable bundle file AFTER the publish process invalidates this executable. Apparently, the executable itself has some sort of self-consistency-check to detect if it was modified after the publish command, and then stops its own execution.

We were still interested in filling some fields of the PE Header of the executable bundle file, for marking our company's name, copyright, trademarks, version, etc.

Apparently AssemblyInfo.cs is not an available option anymore for .NET 6 applications, so we had to find another way. Please correct me if I am wrong here.

We stopped using the third-party Resource Hacker tool, and for the fields PRODUCT VERSION and FILE VERSION we just pass the following parameters directly to the dotnet.exe publish command:

dotnet.exe publish ... -p:AssemblyVersion=1.2.3.4 -p:Version=1.02

This works correctly, and we do it so because our build can then set the version information dynamically accordingly with the build number.

For other static fields, we decided to use the following project file settings (in the *.csproj file):

  <PropertyGroup>
    ...
    <Company>DUMMY COMPANY</Company>
    <Description>A dummy description for the assembly.</Description>
    <Product>DUMMY PRODUCT</Product>
    <Copyright>Copyright © DUMMY COMPANY. All rights reserved.</Copyright>
    <LegalTrademarks>DUMMY COMPANY, DUMMY PRODUCT</LegalTrademarks>
    ...
  </PropertyGroup>

The assembly now gets correctly marked for most PE Header fields, except for the "LegalTrademarks" field, which is missing, as shown in the image below:

enter image description here

This is how it should be:

enter image description here

Question:

Does anyone know how to set this "LegalTrademarks" field to the PE Header of the executable bundle file generated by the dotnet.exe publish command for .NET Core and .NET 6 apps when publishing as single-file?

Feel free to provide more examples on how to set other additional fields too.

sɐunıɔןɐqɐp
  • 3,332
  • 15
  • 36
  • 40
  • 1
    If resource hacker has a command line then you could add post build action which [call](https://learn.microsoft.com/en-us/visualstudio/msbuild/exec-task) it and do change. This should prevent from invalidating executable for rebuild – Selvin May 10 '23 at 09:11
  • I agree to this question being closed, but I would rather not delete it, since it better describes the issue and provides much more details than the other question which provided the answer. – sɐunıɔןɐqɐp May 10 '23 at 10:46
  • @Selvin: The post-build event can only modify the binaries after the compilation process. The publish process takes place after the compilation process, either in Visual Studio or directly with the `dotnet publish` command line. During the publish process is when the bundle executable is created. And if you add an post-publish event to modify the bundle executable, it then becomes invalid. – sɐunıɔןɐqɐp May 10 '23 at 10:49
  • Is this "LegalTrademarks" field important? I cannot see that it has any legal significance at all. The vast majority of your customers will likely never see the property page, and the ones that do are usually mostly interested in things like version numbers. – JonasH May 10 '23 at 11:06
  • @sɐunıɔןɐqɐp compilation process has nothing to do with invalidating ... it's up to build process and build tool (msbuild/dotnet/gradle/ninja/make/wahever) to keep tracking need for rebuild ... so as long as modification is part of the build process this should works ... But of course soulution in duplicate Q/A is more straight forward – Selvin May 10 '23 at 11:23
  • Selvin: exactly, you understood my point. I cannot do anything during the compilation or during the post-build process because the generation of the executable bundle only takes place during the publish process, which happens after the compilation process. And this executable generated during the publish process is the one which requires changes in its PE Header. – sɐunıɔןɐqɐp May 10 '23 at 11:46
  • @JonasH: I agree regarding practical/technical significance, but unfortunately due to my country's laws and official audits which happen for every release of the software, we are obligated to set this information correctly for the business my company works with. – sɐunıɔןɐqɐp May 10 '23 at 11:49

0 Answers0