Mugicoco Posted July 14 Posted July 14 I am looking into how to calculate Adler32 using zlib_udf.au3. I know I need to use _Zlib_CalculateAdler32, but what arguments should I specify? _Zlib_CalculateAdler32($DataPtr, $DataSize) For example, I would be grateful if you could provide a detailed program for calculating the Alder32 of the string "hahahahahahahahahahahehe". What would $DataPtr and DataSize look like in the above example? Thank you
Andreik Posted July 14 Posted July 14 Try this: Local $sData = 'hahahahahahahahahahahehe' Local $bData = StringToBinary($sData) Local $tBuffer = DllStructCreate('byte Data[' & BinaryLen($bData) & ']') $tBuffer.Data = $bData _Zlib_CalculateAdler32(DllStructGetPtr($tBuffer), DllStructGetSize($tBuffer)) Mugicoco 1
Mugicoco Posted July 14 Author Posted July 14 Thank you for your quick reply. I tried it right away, but an error was displayed on the zlib_udf.au3 side. >Subscript used on non-accessible variable.: Return $call[0] The program I tried is as follows. Also, the Zlib_udf used is the attached file. #include <zlib_udf.au3> Local $sData = 'hahahahahahahahahahahehe' Local $bData = StringToBinary($sData) Local $tBuffer = DllStructCreate('byte Data[' & BinaryLen($bData) & ']') $tBuffer.Data = $bData $result = _Zlib_CalculateAdler32(DllStructGetPtr($tBuffer), DllStructGetSize($tBuffer)) ConsoleWrite($result) _Zlib_Shutdown() zlib_udf.zip
RTFC Posted July 14 Posted July 14 It helps if you open the dll first. #include "zlib_udf.au3" Local $sData = 'hahahahahahahahahahahehe' Local $bData = StringToBinary($sData) Local $tBuffer = DllStructCreate('byte Data[' & BinaryLen($bData) & ']') $tBuffer.Data = $bData _Zlib_Startup() $result = _Zlib_CalculateAdler32(DllStructGetPtr($tBuffer), DllStructGetSize($tBuffer)) ConsoleWrite($result & @CRLF) _Zlib_Shutdown() My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O
Mugicoco Posted July 14 Author Posted July 14 Thank you both very much. The results are now displayed correctly. I am very grateful. However, when I used "https://md5calc.com/hash/adler32" to check the calculation, the result was different. Do you know what the cause of this is? Autoit result: 0x76000974 Site result: 0x76180975
Andreik Posted July 15 Posted July 15 (edited) I don't know how this site or zlib1.dll implement the function but it seems like _Zlib_CalculateAdler32() function from zlib_udf.au3 use as base the number 65521. If you change this base to 65522 the result will be exactly like the online hash calculator used by you to check the result. Don't ask me why because I don't know how the function it's implemented inside the dll. Actually if you want just to calculate the adler32 for a certain string you don't necessarily need the entire udf. Here is a demo with the base modified: Local $sData = 'hahahahahahahahahahahehe' Local $bData = StringToBinary($sData) Local $tBuffer = DllStructCreate('byte Data[' & BinaryLen($bData) & ']') $tBuffer.Data = $bData Local $aCall = DllCall('zlib1.dll', "ulong:cdecl", "adler32", "ulong", 65522, "ptr", DllStructGetPtr($tBuffer), "int", DllStructGetSize($tBuffer)) ConsoleWrite(Hex($aCall[0], 8) & @CRLF) Edited July 15 by Andreik Mugicoco 1
Mugicoco Posted July 15 Author Posted July 15 I got the same value as the online calculator when I used other textbooks, so it's still a mystery, but I appreciate your help. Also, as you said, I'm only looking for Alder-32, so the program you provided is very helpful. This is my first time posting on this forum, and I appreciate your kind advice and your friendliness. Thank you.
Andreik Posted July 15 Posted July 15 You can calculate Adler32 without zlib_udf.au3 and without zlib1.dll. I made an example based on original code written by @Ward but using modern AutoIt features: #include <Memory.au3> MsgBox(0, '', Adler32('hahahahahahahahahahahehe')) Func Adler32($sData) ; Based on code written by Ward ; https://www.autoitscript.com/forum/topic/121985-autoit-machine-code-algorithm-collection/#comment-846714 Local $sCode If @AutoItX64 Then $sCode = '0x55450FB7D041C1E8104189D15756534883EC0885D27E69BEB0150000BB718007804181F9B01500008' & _ '9F54589CB410F4EE94889C84129EB83ED01488D7C29014589D90FB6104883C0014101D24501D04839F875EE4489D' & _ '0488D4C2901F7E34489C0C1EA0F69D2F1FF00004129D2F7E3C1EA0F69D2F1FF00004129D04585DB7FA14883C4084' & _ '489C05B5EC1E0105F4409D05DC3' Else $sCode = '0x5557565383EC048B5C24208B7C241C8B7424180FB7CBC1EB1085FF7E5181FFB015000089FD7E05BDB' & _ '015000029EF31C0893C240FB6140683C00101D101CB39C575F189C801EEBD71800780F7E589D8C1EA0F69D2F1FF0' & _ '00029D1F7E58B0424C1EA0F69D2F1FF000029D385C07FAF89D883C404C1E01009C85B5E5F5DC3' EndIf Local $bCode = Binary($sCode) Local $iCode = BinaryLen($bCode) Local $pCode = _MemVirtualAlloc(0, $iCode, $MEM_COMMIT, $PAGE_EXECUTE_READWRITE) Local $tCode = DllStructCreate('byte Data[' & $iCode & ']', $pCode) $tCode.Data = $bCode Local $bData = Binary($sData) Local $tBuffer = DllStructCreate('byte Data[' & BinaryLen($bData) & ']') $tBuffer.Data = $bData Local $aCall = DllCallAddress('int:cdecl', $pCode, 'ptr', DllStructGetPtr($tBuffer), 'int', DllStructGetSize($tBuffer), 'int', 1) Local $iResult = '0x' & Hex($aCall[0], 8) _MemVirtualFree($pCode, 0, $MEM_RELEASE) Return $iResult EndFunc Mugicoco and Werty 1 1
Mugicoco Posted July 15 Author Posted July 15 Thank you so so much!!! The program is long, but I'll use it depending on the situation. I also downloaded @Ward's program from the comment linked below. Thanks so much for the very useful content and forum!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now