Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to determine the size of an executable from its exe header Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
20-Oct-02
Category
Files Operation
Language
Delphi 3.x
Views
158
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How to determine the size of an executable from its exe header

Answer:

This code does not work with 16 bit executables. It assumes that the application is 
trying to find the size of itself, but could easily be modified to find the size of 
any 32bit exe loaded into a stream.

1   {$IFDEF VER100}
2   
3   {TImageDosHeader isn't defined in Delphi 3 so here's an an abbreviated structure 
4   definition}
5   type
6     PImageDosHeader = ^TImageDosHeader;
7     TImageDosHeader = packed record
8       e_ignore: packed array[0..29] of WORD;
9       _lfanew: Longint;
10    end;
11  
12  {$ENDIF}
13  
14  function GetExeSize: cardinal;
15  var
16    p: PChar;
17    i, NumSections: integer;
18  begin
19    result := 0;
20    {hInstance is actually a pointer to the exe's image base in memory}
21    p := pointer(hinstance);
22    inc(p, PImageDosHeader(p)._lfanew);
23    inc(p, sizeof(dword));
24    NumSections := PImageFileHeader(p).NumberOfSections;
25    inc(p, sizeof(TImageFileHeader) + sizeof(TImageOptionalHeader));
26    for i := 1 to NumSections do
27    begin
28      with PImageSectionHeader(p)^ do
29        if PointerToRawData + SizeOfRawData > result then
30          result := PointerToRawData + SizeOfRawData;
31      inc(p, sizeof(TImageSectionHeader));
32    end;
33  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC