Sign in to follow this  
Followers 0
tip

CRC32 Hash Calculation crashes while compiled...

6 posts in this topic

#1 ·  Posted (edited)

Hi to all,

I was intending to write a little script that compares to files CRC32 hash. My script runs perfectly from Scite but when I compile it to an exe file it crashes.(It crashes right after ProgressOn(). See the code below.)

Do you have any idea how to fix it...

Thanks in advance

Here is my full code

Global $BufferSize = 0x20000
Global $TimerGlobal = 0

$File1=FileOpenDialog("Select file",@ScriptDir,"All (*.*)",3)
If $File1 = "" Then Exit
$File2=FileOpenDialog("Select file",@ScriptDir,"All (*.*)",3)
If $File1 = "" Or $File2 = "" then Exit

$File1CRC32 = _Crc32_EU($File1)

$File2CRC32 = _Crc32_EU($File2)


If $File1CRC32 = $File2CRC32 Then
    
MsgBox(64,"CRC32 Hash Check Completed","CRC32 Hash check verifies that two selected files are identical." _
                                        & @Crlf & "Completed in " & $TimerGlobal & " seconds.")

Else

MsgBox(64,"CRC32 Hash Check Completed","CRC32 Hash Check Failed" & @CRLF & @CRLF & $File1CRC32 & @CRLF & $File2CRC32 _
                                        & @Crlf & "Completed in " & $TimerGlobal & " seconds.")

EndIf


Func _Crc32_EU($Filename)
$FileHandle = FileOpen($Filename, 16)
Global $CRC32 = 0
$CRC32Filesize = FileGetSize($Filename)
ProgressOn("CRC32 Hash Check","CRC32 Hash Status: ","0%",@DesktopWidth/2-50,@DesktopHeight/2+30,16)

$Timer = TimerInit()

For $i = 1 To Ceiling(FileGetSize($Filename) / $BufferSize)
    $CRC32 = _CRC32(FileRead($FileHandle, $BufferSize), BitNot($CRC32))
    ProgressSet($i/Ceiling($CRC32Filesize / $BufferSize)*100,Int($i/Ceiling($CRC32Filesize / $BufferSize)*100) & "%")
Next

ProgressOff()
FileClose($FileHandle)
$TimerGlobal += Round(TimerDiff($Timer)/1000,1)
$Timer = 0
Return $CRC32
EndFunc



Func _CRC32($Data, $CRC32 = -1)
Local $Opcode = '0xC800040053BA2083B8EDB9000100008D41FF516A0859D1E8730231D0E2F85989848DFCFBFFFFE2E78B5D088B4D0C8B


451085DB7416E3148A1330C20FB6D2C1E80833849500FCFFFF43E2ECF7D05BC9C21000'

    Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]")
    DllStructSetData($CodeBuffer, 1, $Opcode)

    Local $Input = DllStructCreate("byte[" & BinaryLen($Data) & "]")
    DllStructSetData($Input, 1, $Data)

    Local $Ret = DllCall("user32.dll", "uint", "CallWindowProc", "ptr", DllStructGetPtr($CodeBuffer), _
                                                    "ptr", DllStructGetPtr($Input), _
                                                    "int", BinaryLen($Data), _
                                                    "uint", $CRC32, _
                                                    "int", 0)

    $Input = 0
    $CodeBuffer = 0

    Return $Ret[0]
EndFunc
Edited by tip

[center]MsgBox_Tipped: Eye candy msgboxes/inputboxes/loginboxes. | CreateBlankBox: Semi-transparent layers with borders and rounded corners.[/center]

Share this post


Link to post
Share on other sites



I replaced this:

Local $Opcode = '0xC800040053BA2083B8EDB9000100008D41FF516A0859D1E8730231D0E2F85989848DFCFBFFFFE2E78B5D088B4D0C8B



451085DB7416E3148A1330C20FB6D2C1E80833849500FCFFFF43E2ECF7D05BC9C21000'

with this:

Local $Opcode = '0xC800040053BA2083B8EDB9000100008D41FF516A0859D1E8730231D0E2F85989848DFCFBFFFFE2E78B5D088B4D0C8B

451085DB7416E3148A1330C20FB6D2C1E80833849500FCFFFF43E2ECF7D05BC9C21000'

and it worked just fine in both SciTE and after being compiled.

Share this post


Link to post
Share on other sites

If @exodius is correct (I didn't test either) and you were attempting to keep it neat then use a different method to set $Opcode. Either use line continuation

;
Local $Opcode = "0xC800040053BA2083B8EDB9000100008D41FF516A0859D1E873" & _
"0231D0E2F85989848DFCFBFFFFE2E78B5D088B4D0C8B451085DB7416E3148A" & _
"1330C20FB6D2C1E80833849500FCFFFF43E2ECF7D05BC9C21000"
;

Or use string concantination

;
Local $Opcode = "0xC800040053BA2083B8EDB9000100008D41FF516A0859D1E873"
$Opcode &= "0231D0E2F85989848DFCFBFFFFE2E78B5D088B4D0C8B451085DB7416E3148A"
$Opcode &= "1330C20FB6D2C1E80833849500FCFFFF43E2ECF7D05BC9C21000"
;

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

True true, the odd thing is, his original code did not work for me in SciTE uncompiled. (obviously because he had a string that wasn't terminated and another string that was never started with an apostrophe)

Share this post


Link to post
Share on other sites

True true, the odd thing is, his original code did not work for me in SciTE uncompiled. (obviously because he had a string that wasn't terminated and another string that was never started with an apostrophe)

It may also have been a copy/paste error in the code he provided but the corrected code should prove if he has a problem or not. Like I said, I didn't test his problem I simply provided a couple of tips.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

İt was a copy/paste error that $opcode is spread to several lines. In original code it was a single line...

And when I divided the single line code to several lines -like GEOsoft suggested- it worked...

Thanks everyone for helping

Cheers :D


[center]MsgBox_Tipped: Eye candy msgboxes/inputboxes/loginboxes. | CreateBlankBox: Semi-transparent layers with borders and rounded corners.[/center]

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0