Recent

Author Topic: Getting File Size from PE Header Fails with Lazarus  (Read 9087 times)

440bx

  • Hero Member
  • *****
  • Posts: 4472
Re: Getting File Size from PE Header Fails with Lazarus
« Reply #30 on: October 28, 2023, 07:15:10 pm »
Once again, many thanks!!!

Much gratitude for all your kind and patient assistance.
You're welcome.

From the output shown, it looks like you appended 36,392 bytes to the executable before running it.  I say that because the sum "COFF symbol table size" + "string table size" should equal "size of entire COFF table (entries + strings)".  The only way those don't match is if data has been appended to the file.  In this case 103099 - (21348 + 45359) = 36392 = number of appended bytes.

(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

msintle

  • Full Member
  • ***
  • Posts: 116
Re: Getting File Size from PE Header Fails with Lazarus
« Reply #31 on: December 14, 2023, 12:08:06 pm »
I seem to have a new problem - does the algorithm above work if strip has been done on the file in question using the Free Pascal strip utility after a Windows executable has already been built?

440bx

  • Hero Member
  • *****
  • Posts: 4472
Re: Getting File Size from PE Header Fails with Lazarus
« Reply #32 on: December 14, 2023, 01:53:01 pm »
It should work because if strip removes the COFF symbol table (which it probably does) then it should set the value "Pointer to symbol table" to zero.  If it does not set it to zero then that is a bug in the strip utility.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

msintle

  • Full Member
  • ***
  • Posts: 116
Re: Getting File Size from PE Header Fails with Lazarus
« Reply #33 on: December 16, 2023, 03:32:46 pm »
The file sizes do come down really nicely after the strip, but they all seem to be affected by the same issue.

I've tried the Free Pascal strip, and some tools from the Android NDK that were already present on my system from RAD Studio / Visual Studio installations - three strip.exe's so far, all with the same result.

It really is such a shame that we ultimately cannot use your brilliant work again, this time due to bugs in external tools.

More constricting is the fact that it doesn't seem to be possible to turn off debug information generation from the command line while using lazbuild:

https://forum.lazarus.freepascal.org/index.php/topic,65521.msg499324.html#msg499324

I honestly haven't had the chance to turn back to our raw test cases (hoping to do so once crunch time here is over), but I strongly doubt a thorough re-examination of the issue would yield different findings where scenarios involving removal of debug information post-build are concerned.

At least we tried :)

440bx

  • Hero Member
  • *****
  • Posts: 4472
Re: Getting File Size from PE Header Fails with Lazarus
« Reply #34 on: December 16, 2023, 05:42:44 pm »
FWIW:

When I tried the strip utility that was included with FPC v3.0.4, the utility would not recognize the executable as a valid file to strip.  I didn't investigate the problem any further since I didn't think it was worth it.

When I tried the strip utility that is distributed with Lazarus I had no problems at all.  Everything worked as it should have (with the same executable that failed with the FPC distributed utility.)

Note: I only tried the 64bit version of the Lazarus distributed version of strip.exe
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

msintle

  • Full Member
  • ***
  • Posts: 116
Re: Getting File Size from PE Header Fails with Lazarus
« Reply #35 on: January 08, 2024, 01:12:06 am »
I was just able to check our base test cases due to the holidays!

I actually have great news - your code works perfectly fine with stripped executables, too.

The only value that is reported by your testing code in this scenario is:

Code: [Select]
PE size using PE sections :    <whatever the true file size is>
Clearly I made a mistake in converting your console code to my GUI app after that, as it failed with stripped files.

So thank you once again, and I am surely grateful I double checked this when I had the chance.

I hope your new year is off to a great start!

440bx

  • Hero Member
  • *****
  • Posts: 4472
Re: Getting File Size from PE Header Fails with Lazarus
« Reply #36 on: January 08, 2024, 06:15:21 am »
I hope your new year is off to a great start!
Thank you and I hope that is the case for you as well.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018