[Implemented] MD5FileFingerprint() - Set Range for MD5

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

[Implemented] MD5FileFingerprint() - Set Range for MD5

Post 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
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post 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
Tranquil
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post by va!n »

@Tranquil:
loool, you were some seconds faster ^^

just check:
http://www.purebasic.fr/english/viewtopic.php?t=20114
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post 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 ;)
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
User avatar
Rescator
Addict
Addict
Posts: 1769
Joined: Sat Feb 19, 2005 5:05 pm
Location: Norway

Post 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.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post 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.
Tranquil
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post 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$)
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
va!n
Addict
Addict
Posts: 1104
Joined: Wed Apr 20, 2005 12:48 pm

Post 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
va!n aka Thorsten

Intel i7-980X Extreme Edition, 12 GB DDR3, Radeon 5870 2GB, Windows7 x64,
Post Reply