He de reconocer que aún me falta mucho para conocer bien la cabecera PE, esta función la he conseguido terminar gracias a la lectura de códigos de steve10120, linkgl y Pink, gracias a los 3 :thumb_yello:
Lo que hace es leer el EOF del ejecutable partiendo de la información que la PE nos proporciona, la función nos devuelve el EOF en una String en caso de existir.
Código: Seleccionar todo
(*
Función: ReadEOFData
Utilidad: Leer el EOF de un fichero ejecutable
Fecha: 30/09/2012
Web: udtools.net
Ejemplo de uso: mWriteFileFromStr(ReadEOFData('C:\Server.exe'), 'C:\SoloEOF.exe');
mWriteFileFromStr: http://foro.udtools.net/showthread.php?7543
Agradecimientos: steve10120, linkgl, Pink
*)
Function ReadEOFData(Ruta: String): string;
var
IDH: TImageDosHeader;
INH: TImageNtHeaders;
ISH: TImageSectionHeader;
hTam: DWORD;
pUltSect: DWORD;
sFile: HFile;
Buff: array of byte;
uBytes: Cardinal;
i: integer;
begin
sFile:= _lopen(PChar(Ruta), OF_READ);
if sFile = HFILE_ERROR then exit;
uBytes:= GetFileSize(sFile, nil);
SetLength(Buff, uBytes);
_lread(sfile, @Buff[0], uBytes);
_lclose(sFile);
CopyMemory(@IDH, @Buff[0], 64);
if IDH.e_magic = IMAGE_DOS_SIGNATURE then
begin
CopyMemory(@INH, @Buff[IDH._lfanew], 248);
if INH.Signature = IMAGE_NT_SIGNATURE then
begin
pUltSect:= IDH._lfanew + 248 + ((INH.FileHeader.NumberOfSections - 1) * 40);
CopyMemory(@ISH, @Buff[pUltSect], 40);
hTam:= ish.PointerToRawData + ish.SizeOfRawData;
end;
end;
if ubytes > htam then
begin
for i:= hTam to uBytes-1 do
Result:= Result + chr(buff[i]);
end;
end;