Código
(* * PEFileSize function, inspired by The Swash * by Khronos *) function PEFileSize(FileName: string): Cardinal; var i: integer; FileStream: TFileStream; IDH: IMAGE_DOS_HEADER; INH: IMAGE_NT_HEADERS; ISH: IMAGE_SECTION_HEADER; begin result:= 0; try FileStream:= TFileStream.Create(FileName, fmOpenRead or fmShareDenyWrite); FileStream.Read(IDH, SizeOf(IDH)); if IDH.e_magic = IMAGE_DOS_SIGNATURE then begin FileStream.Seek(IDH._lfanew, 0); FileStream.Read(INH, SizeOf(INH)); if INH.Signature = IMAGE_NT_SIGNATURE then begin for I := 0 to INH.FileHeader.NumberOfSections - 1 do begin FileStream.Seek(IDH._lfanew + SizeOf(INH) + SizeOf(ISH) * i, 0); FileStream.Read(ISH, SizeOf(ISH)); result:= result + ISH.SizeOfRawData; end; result:= result + INH.OptionalHeader.SizeOfHeaders; end; end; finally FileStream.Free; end; end;
Saludos.