get CRC-32 hash value, read file in chunks Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

get CRC-32 hash value, read file in chunks

02 May 2017, 22:38

Has anyone done any work on this. To get a CRC-32 hash, for a file that is read in chunks, e.g. that is too big to read into an AutoHotkey variable.

Potential uses: duplicate file checkers, file move/copy checking, and hashes for backing up files and external hard drive files (e.g. compare current file's hash, with a hash in a text file, for a file on a hard drive not currently plugged in).

Btw it might be possible to do CRC-32 calculations in AutoHotkey, but I'm not sure how much this might slow things down.

I know that jNizM has done a lot of work on file hashes, but not this particular problem.

Some links:

c# - Is it possible to do CRC-32 calculation in splits? - Stack Overflow
http://stackoverflow.com/questions/6491 ... -in-splits

c# - How is PNG CRC calculated exactly? - Stack Overflow
http://stackoverflow.com/questions/2408 ... ed-exactly

crc_v3.txt
http://www.ross.net/crc/download/crc_v3.txt
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jNizM
Posts: 3045
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: get CRC-32 hash value, read file in chunks  Topic is solved

03 May 2017, 00:47

Code: Select all

CRC32_File(filename)
{
    if !(f := FileOpen(filename, "r", "UTF-8"))
        throw Exception("Failed to open file: " filename, -1)
    f.Seek(0)
    while (dataread := f.RawRead(data, 262144))
        crc := DllCall("ntdll.dll\RtlComputeCrc32", "uint", crc, "ptr", &data, "uint", dataread, "uint")
    f.Close()
    return Format("{:#x}", crc)
}

MsgBox % CRC32_File("C:\Windows\notepad.exe")
Will upload this in my github repo
[AHK] 1.1.33.10 x64 Unicode (2.0-beta.3) | [WIN] 11 Pro (Version 21H2) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: get CRC-32 hash value, read file in chunks

03 May 2017, 00:55

Amazing! Thanks so much for this. Perhaps at some point this month, I'm going to look into the maths of CRC-32 and add it to my AHK maths tutorial that I'm working on. Cheers.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jNizM
Posts: 3045
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: get CRC-32 hash value, read file in chunks

03 May 2017, 01:08

The CRC32 Implementation (without dllcalls) is also in my github
[AHK] 1.1.33.10 x64 Unicode (2.0-beta.3) | [WIN] 11 Pro (Version 21H2) x64 | [GitHub] Profile
Donations are appreciated if I could help you
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: get CRC-32 hash value, read file in chunks

12 May 2017, 08:24

Thanks I will take a look.

Btw RtlComputeCrc32 appears to be undocumented, I wonder where you first came across it.

Did you use this as the definition?

Wine API: RtlComputeCrc32
https://source.winehq.org/WineAPI/RtlComputeCrc32.html

Cheers.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: get CRC-32 hash value, read file in chunks

09 Aug 2017, 17:22

I'm going to look into the maths of CRC-32
CRC-32 hash tutorial - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=35671
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: arczi_87, Green Astronaut, inseption86, mikeyww, one1tick, XMCQCX and 62 guests