Avatar billede cms Nybegynder
23. marts 2001 - 15:58 Der er 4 kommentarer og
2 løsninger

exe og dll-struktur

Hey.

Jeg har brug for strukturen på hhv. exe-filer (win32) og dll-filer (win32).
Dvs. hvor ligger resource-delen, headerne, osv. osv. osv.
Så detaljerede oplysninger som muligt.
Avatar billede cautoo Nybegynder
23. marts 2001 - 16:00 #1
vil du hive oplysninger ud af en exe/dll fil eller ud af dit delphi projekt????
Avatar billede borrisholt Novice
23. marts 2001 - 16:03 #2
mht resource-delen kan do downloade en resource editor fra http://borrisholt.com

Jens B
Avatar billede martinlind Nybegynder
23. marts 2001 - 16:04 #3
Fundet på www.undu.com :

Have you ever wanted to add something extra onto the end of an EXE file and then be able to find it easily from within the EXE\'s code?

A typical example of this is a self-extracting EXE file, where the EXE stub has an appended compressed archive. When the stub is executed, the code needs to know the size of the stub in order to find the offset to the beginning of the archive. The size of the stub is commonly \"hard coded\" (inserted into the code as a constant) once it has been determined by compiling the stub and then viewing it\'s file properties in Explorer. To access an appended file, the stub loads itself (stub with appended archive) into a filestream and set the stream\'s position to this hard coded offset.

The problem with this \"hard coded\" approach is that any change to the EXE\'s code is likely to change the size of the EXE. The following code snippet, solves this problem by examining the EXE\'s header to determine its size. A close examination of the numerous PE fileheader structures would help to fully understand this code but, as it\'s probably not worth the effort, I wont bore anyone with the details. However, one thing which may be very useful to know is the hInstance handle is actually a pointer to the base of the file image once it has been loaded into memory.

The downside is it adds a few extra bytes to the EXE stub of course...

{$IFDEF VER100}
{TImageDosHeader isn\'t defined in Delphi 3 so here\'s an
an abbreviated structure definition...}
type
  PImageDosHeader = ^TImageDosHeader;
  TImageDosHeader = packed record
    e_magic        : WORD;
    e_ignore        : packed array [0..28] of WORD;
    _lfanew        : Longint;
  end;
{$ENDIF}

function GetExeSize: cardinal;
var
  p: pchar;
  i, NumSections: integer;
const
  IMAGE_PE_SIGNATURE  = $00004550;
begin
  result := 0; // if error then result = 0
  p := pointer(hinstance);
  if PImageDosHeader(p).e_magic <> IMAGE_DOS_SIGNATURE then exit;
  inc(p, PImageDosHeader(p)._lfanew);
  if pDWord(p)^ <> IMAGE_PE_SIGNATURE then exit; {Win32 PE files only}
  inc(p,sizeof(dword));
  NumSections := PImageFileHeader(p).NumberOfSections;
  inc(p,sizeof(TImageFileHeader)+ sizeof(TImageOptionalHeader));
  for i := 1 to NumSections do
  begin
    with PImageSectionHeader(p)^ do
      if PointerToRawData+SizeOfRawData > result then
        result := PointerToRawData+SizeOfRawData;
    inc(p, sizeof(TImageSectionHeader));
  end;
end;
 
Resource-delen osv. det er winAPI kald du skal bruge eller måske en MSDOS Tech-ref.

/Martin
Avatar billede cms Nybegynder
23. marts 2001 - 17:35 #4
martin /andre >>

fed kode. nu tager den udgangspunkt i HInstance, dvs. den aktuelle applikation. Er det muligt at få fat i HInstance for en anden app, uden nødvendigvis at køre den anden app, eller skal man køre den i baggrunden, eller bruge en anden handle?
Jeg spørger fordi jeg altså gerne ville lave \"operationer\" på en anden fil end min egen (om man så må sige).
Avatar billede cms Nybegynder
23. marts 2001 - 18:00 #5
glem det. jeg fandt ud af det. (createfile-handle over i readfile ud i buffer, castet som thandle = hinstance)
thanx for your help ;o)
Avatar billede martinlind Nybegynder
23. marts 2001 - 19:11 #6
Selv tak *S* undu er et ok sted
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester