![]() |
Delphi-Version: 2009
Dateityp aus Dateiheader herausfinden
Hallo,
gibt es eine Möglichkeit aus einer Datei den Dateiheader auszulesen und daraus zu erkennen um was für einen Dateityp es sich handelt. Zum Beispiel, ob es eine JPEG-Datei ist? Wenn ja, wie kann ich den Dateiheader auslesen? wie bekomme ich den Dateityp heraus? Vielen Dank schon einmal für eure Hilfe :) |
AW: Dateityp aus Dateiheader herausfinden
Informationen zu vielen Dateiformaten findet man unter
![]() |
AW: Dateityp aus Dateiheader herausfinden
Es gibt auch schon hier und da fertige Funktionen.
Dieses Ungetüm hatte ich mir gestern zusammengeklickt und nun rate mal wo ich die ganzen Header-Infos her hatte?
Delphi-Quellcode:
Nja, das ist keine 100%ige Prüfung ... wenn man sicher gehn will und auch noch die Unterformate genauer rausbekommen möchte, dann muß man schon mehr, als nur die 2-4 Byte prüfen.
procedure TSMStreamAttachmentLoader.LoadContentType;
var i: Int64; L: Integer; H: array[0..3] of AnsiChar; M: array[0..1] of AnsiChar absolute H; K: Word; begin i := FData.Position; try ContentType := ''; FData.Position := 0; if FData.Size >= SizeOf(H) then begin FData.ReadBuffer(H, SizeOf(H)); for L := 0 to High(H) do if H[L] = #0 then H[L] := '°' else if H[L] <= #8 then H[L] := '¹' else if H[L] = #$89 then H[L] := '²'; K := (Ord(H[0]) shl 8) or Ord(H[1]); if M = 'PK' then ContentType := 'application/octet-stream' else if H = '%PDF' then ContentType := 'application/pdf' //else if H = 'PK¹¹' then ContentType := 'application/zip' else if H = 'Rar!' then ContentType := 'application/x-rar-compressed' else if H = 'GIF8' then ContentType := 'image/gif' else if K = $FFD8 then ContentType := 'image/jpeg' else if H = '²PNG' then ContentType := 'image/png' else if M = 'BM' then ContentType := 'image/bmp' else if H = 'MM°*' then ContentType := 'image/tiff' else if H = 'II*°' then ContentType := 'image/tiff' else if H = '<?xm' then ContentType := 'text/xml' else if H = '<°?°' then ContentType := 'text/xml'; end; finally FData.Position := i; end; end; [edit] schottige Codeausrichtung :cry: ... im Zitat/Beitragseditor sieht es hübscher aus |
AW: Dateityp aus Dateiheader herausfinden
Cool, Danke himitsu :)
Ist es korrekt, dass du dir die Dateien einfach mit Hex-Editor angeschaut hast und dann dementsprechend eingefügt hast? |
AW: Dateityp aus Dateiheader herausfinden
Google : Dateierweiterung + fileheader
Google : Dateierweiterung + magic number am Ende landet man jeweils bei Wiki, wotsit, und Co. ![]() Wobei ich das einfache Prinzip der sogenannten "Magic Number" / " ![]() |
Alle Zeitangaben in WEZ +1. Es ist jetzt 23:15 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz