From 023a70aaddcdeedf20764f6c73bb574fe2096573 Mon Sep 17 00:00:00 2001 From: Marc Durdin Date: Wed, 16 Dec 2020 11:34:39 +1100 Subject: [PATCH] fix(windows): sentrytool fails on mem realloc Fixes #4002. We needed to reseat the pointers after the realloc as the base address changed; this only affected us occasionally but nasty when it did! --- .../src/buildtools/sentrytool/Keyman.System.AddPdbToPe.pas | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/windows/src/buildtools/sentrytool/Keyman.System.AddPdbToPe.pas b/windows/src/buildtools/sentrytool/Keyman.System.AddPdbToPe.pas index f92b815172..0416c8bd54 100644 --- a/windows/src/buildtools/sentrytool/Keyman.System.AddPdbToPe.pas +++ b/windows/src/buildtools/sentrytool/Keyman.System.AddPdbToPe.pas @@ -265,6 +265,9 @@ begin s.SetSize(SectionOffset + SectionRawSize); FillChar((PByte(s.Memory) + SectionOffset)^, SectionRawSize, 0); + nh32 := PImageNtHeaders(NativeUInt(nh32)-NativeUInt(dh)+NativeUInt(s.Memory)); + section := PImageSectionHeader(NativeUInt(section)-NativeUInt(dh)+NativeUInt(s.Memory)); + // Increment the number of sections Inc(nh32.FileHeader.NumberOfSections); @@ -324,6 +327,9 @@ begin s.SetSize(SectionOffset + SectionRawSize); FillChar((PByte(s.Memory) + SectionOffset)^, SectionRawSize, 0); + nh64 := PImageNtHeaders64(NativeUInt(nh64)-NativeUInt(dh)+NativeUInt(s.Memory)); + section := PImageSectionHeader(NativeUInt(section)-NativeUInt(dh)+NativeUInt(s.Memory)); + // Increment the number of sections Inc(nh64.FileHeader.NumberOfSections);