CRC32 of Zipped files? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
TheDewd
Posts: 1391
Joined: 19 Dec 2013, 11:16
Location: USA

CRC32 of Zipped files?

16 Sep 2019, 09:07

Is there a more painless way to get the CRC32 value for files within a ZIP file?

I'm really only interested in the CRC32 to use for checking the validity of the files against a database.

Here's some code I put together that uses 7za.exe to display information about files in an archive...

I'm using RegExMatch to pick and choose the values I want to see. The example below is showing the filenames within a zip archive.

I'm not sure how to go about this...

Code: Select all

#SingleInstance, Force
DetectHiddenWindows, On

Run, %ComSpec% /K,, Hide UseErrorLevel, cPid
WinWait, ahk_pid %cPid%,, 10
DllCall("AttachConsole", "UInt", cPid)
hCon := DllCall("CreateFile", "Str", "CONOUT$", "UInt", 0xC0000000, "UInt", 7, "UInt", 0, "UInt", 3, "UInt", 0, "UInt", 0)

Contents := RunWaitOne("7za l -slt ""TEST.zip""")

Pos := 0
While (Pos := RegExMatch(Contents, "Path\s=\s(.*)", Match, Pos + 1)) {
	If (A_Index = 1) {
		Continue
	}

	MsgBox, % Match1
}

RunWaitOne(Command) {
	Shell := ComObjCreate("WScript.Shell")
	Exec := Shell.Exec(ComSpec " /C " Command)
	return Exec.StdOut.ReadAll()
}

DllCall("Kernel32.dll\CloseHandle", "UInt", hCon)
DllCall("Kernel32.dll\FreeConsole")
Process, Close, %cPid%
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
tmplinshi
Posts: 1561
Joined: 01 Oct 2013, 14:57

Re: CRC32 of Zipped files?  Topic is solved

16 Sep 2019, 16:02

7-zip dll?

7-zip32: http://www.csdinc.co.jp/archiver/lib/7-zip32.html
7-zip64: http://ayakawa.o.oo7.jp/soft/ntutil.html#7z
7-zip32 wrapper by shajul: https://autohotkey.com/board/topic/64362-7zip-7-zip32dll-library-without-commandline-ahk-l/

Code: Select all

7zipDll := (A_PtrSize = 8) ? "7-zip64.dll" : "7-zip32.dll"
if !hModule := DllCall("LoadLibrary", "str", 7zipDll, "ptr")
	throw "LoadLibrary fail"

arr := 7ZipGetCRC(7zipDll, "test.zip")

MsgBox,, % arr.MaxIndex() . " Files found."
       , % "First File: " . arr.1.FileName . "," . arr.1.CRC

DllCall("FreeLibrary", "ptr", hModule)
ExitApp

7ZipGetCRC(7zipDll, FileName, sSearch := "") {
	if !hArc := DllCall(7zipDll . "\SevenZipOpenArchive", "ptr", 0, "astr", FileName, "int", 0)
		throw "SevenZipOpenArchive fail"

	VarSetCapacity(info, 558, 0)
	ret := DllCall(7zipDll . "\SevenZipFindFirst", "ptr", hArc, "astr", sSearch, "ptr", &info)

	result := []
	while (ret = 0) {
		result[A_Index, "CRC"     ] := Format("{:X}", NumGet(info, 8, "uint"))
		result[A_Index, "FileName"] := StrGet(&info+26, 513, "cp0")
		ret := DllCall(7zipDll . "\SevenZipFindNext", "ptr", hArc, "ptr", &info)
	}

	DllCall(7zipDll . "\SevenZipCloseArchive", "ptr", hArc)
	return result.MaxIndex() ? result : ""
}
7ZipGetCRC_Test.zip
User avatar
TheDewd
Posts: 1391
Joined: 19 Dec 2013, 11:16
Location: USA

Re: CRC32 of Zipped files?

16 Sep 2019, 16:12

That's exactly what I needed! Thank you very much!
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.

Return to “Ask For Help”

Who is online

Users browsing this forum: dentopolis, Google [Bot], RubbeH, Xtra and 69 guests