Page 1 of 1

[Implemented] MD5FileFingerprint() - Set Range for MD5

Posted: Mon Jan 06, 2003 12:26 am
by BackupUser
Restored from previous forum. Originally posted by MrVainSCL.

Hi Fred,
as we told some days ago... it would be really great to have an optional function to tell MD5FileFingerPrint() where to start and end inside a file....

Code: Select all

    Result$ = MD5FileFingerprint(Filename$,[StartPos,EndPos])     
You may ask why does someone would need this?

Its easy... It would be very usefull for getting the MD5 of a MP3 file for example (wihout his tags) ... or if you add (link) a data-package to the end of your executeable and you want to check if this package is not modified... so we know can directly check only this part of our file... But there are a lot more sample applications where such an optional function would make really sence!

So many thanks in advance, if you will add this feature to the next release... (maybe you could send me the lib if you have finished some day before releasing!? :wink: Stay cool.



PIII450, 256MB Ram, 80GB HD + 6,4 GB, RivaTNT, DirectX8.1, SB AWE64, Win2000 + all Updates...

greetz
MrVainSCL! aka Thorsten

Posted: Sun Mar 05, 2006 4:13 am
by Tranquil
Anything new on this? Could be very usefull to hash only several parts of a file.

for example: I want to get a MD5 hash of an mp3 file without his MP3-Tag Headers at the beginning (ID3v2) and at the end. (ID3v1)


Possible to get this optional? Should be easy to implement or?

Mike

Posted: Sun Mar 05, 2006 4:16 am
by va!n
@Tranquil:
loool, you were some seconds faster ^^

just check:
http://www.purebasic.fr/english/viewtopic.php?t=20114

Posted: Sun Mar 05, 2006 4:25 am
by va!n
looool - check the date of the original poste... havent noticed this before
1 again, -2 days and 3 years later we re-request this ;)

Posted: Sun Mar 05, 2006 7:25 am
by Rescator
Same thing for CRC32 would be nice.

The most usefull useage for this would be in cases where a checksum is at the end (very common that people add it on afterwards) of a file,
obviously checksumming the checksum is not wanted in those cases.

Posted: Sun Mar 05, 2006 12:03 pm
by Trond
Untested:

Code: Select all

Procedure.s MD5FileFingerprintEx(Filename.s, StartPos, EndPos)
  Protected InFile.l = ReadFile(#PB_Any, Filename)
  Protected Hash.s
  Protected Ptr.l
  Protected Length.l = EndPos - StartPos
    If IsFile(InFile)
      Ptr = AllocateMemory(Length)
      If Ptr
        FileSeek(InFile, StartPos)
        ReadData(InFile, Ptr, Length)
        Hash = MD5Fingerprint(Ptr, Length)
        FreeMemory(Ptr)
      EndIf
      CloseFile(InFile)
    EndIf
  ProcedureReturn Hash
EndProcedure

Posted: Sun Mar 05, 2006 4:10 pm
by Tranquil
Trond wrote:Untested:

Code: Select all

Procedure.s MD5FileFingerprintEx(Filename.s, StartPos, EndPos)
  Protected InFile.l = ReadFile(#PB_Any, Filename)
  Protected Hash.s
  Protected Ptr.l
  Protected Length.l = EndPos - StartPos
    If IsFile(InFile)
      Ptr = AllocateMemory(Length)
      If Ptr
        FileSeek(InFile, StartPos)
        ReadData(InFile, Ptr, Length)
        Hash = MD5Fingerprint(Ptr, Length)
        FreeMemory(Ptr)
      EndIf
      CloseFile(InFile)
    EndIf
  ProcedureReturn Hash
EndProcedure
Thanks for your suggestion. But I thing, the main reason why to use FileFingerprint() is not to load the complete File to memory. Creating a hash of, maybe, a media .vob file with a size of 2 GB coule be very uncomfortable.

Posted: Sun Mar 05, 2006 4:56 pm
by va!n
@Rescator:
Save as i posted here - http://www.purebasic.fr/english/viewtopic.php?t=20114 ;)

CRC32FileFingerprint(filename$, [startpos, endpos])
MD5FileFingerprint(Filename$, [startpos, endpos])

Base64FileEncoder(sourceFilename$, destinationFilename$)
Base64FileDecoder(sourceFilename$, destinationFilename$)

Posted: Sun Mar 05, 2006 5:10 pm
by va!n
Just a link titled "MD5 optimized for AMD64" and for CRC32 on files :)

http://etudiant.epita.fr/~bevand_m/pape ... amd64.html
http://www.codeproject.com/cpp/crc32.asp