Jump to content

MD5,SHA1,CRC32,RC4,BASE64,XXTEA machine code version


Ward
 Share

Recommended Posts

Finally I got a 64-bit windows. I recompiled the old CRC16/32 code and now it should work on both AutoItX32 and AutoItX64. It works for me, how about you?

Other code is pending......

; ------------------------------------------------------------------
; CRC Checksum UDF
; Purpose: Provide Fast CRC32/CRC16 Algorithm In AutoIt
; Author:  Ward
; ------------------------------------------------------------------

#Include <Memory.au3>

Func _CRC32($Data, $Initial = -1, $Polynomial = 0xEDB88320)
    If @AutoItX64 Then
        Local $Opcode = '0x554889E54881EC2004000048894D10488955184489452044894D28C745F800000000EB468B45F88945ECC745FC08000000EB1E8B45EC83E00184C0740D8B45ECD1E83345288945ECEB03D16DEC836DFC01837DFC007FDC8B45F848988B55EC899485E0FBFFFF8345F801817DF8FF0000007EB1488B4510488945F0C745F800000000EB318B452089C2C1EA088B45F84898480345F00FB6000FB6C033452025FF00000089C08B8485E0FBFFFF31D08945208345F8018B45F84898483B451872C48B4520F7D0C9C3'
    Else
        Local $Opcode = '0xC8000400538B5514B9000100008D41FF516A0859D1E8730231D0E2F85989848DFCFBFFFFE2E78B5D088B4D0C8B451085DB7416E3148A1330C20FB6D2C1E80833849500FCFFFF43E2ECF7D05BC9C21000'
    EndIf
    
    Local $CodeBufferMemory = _MemVirtualAlloc(0, BinaryLen($Opcode), $MEM_COMMIT, $PAGE_EXECUTE_READWRITE)
    Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]", $CodeBufferMemory)
    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", $Initial, _
                                                    "int", $Polynomial)

    $Input = 0
    $CodeBuffer = 0
    _MemVirtualFree($CodeBufferMemory, 0, $MEM_RELEASE)

    Return $Ret[0]
EndFunc

Func _CRC16($Data, $Initial = 0, $Polynomial = 0xA001)
    If @AutoItX64 Then
        Local $Opcode = '0x554889E54881EC2002000048894D10488955184489C24489C86689552066894528C745F800000000EB4F8B45F8668945EEC745FC08000000EB240FB745EE83E00184C074110FB745EE66D1E866334528668945EEEB0466D16DEE836DFC01837DFC007FD68B45F848980FB755EE66899445E0FDFFFF8345F801817DF8FF0000007EA8488B4510488945F0C745F800000000EB380FB7452089C166C1E9080FB755208B45F84898480345F00FB6000FB6C031D025FF00000048980FB78445E0FDFFFF31C8668945208345F8018B45F84898483B451872BD0FB74520C9C3'
    Else
        Local $Opcode = '0xC800020053668B5514B9000100006689C86648516A085966D1E873036631D0E2F6596689844DFEFDFFFFE2E28B5D088B4D0C668B451085DB7418E3168A1330C20FB6D266C1E8086633845500FEFFFF43E2EA5BC9C21000'
    EndIf

    Local $CodeBufferMemory = _MemVirtualAlloc(0, BinaryLen($Opcode), $MEM_COMMIT, $PAGE_EXECUTE_READWRITE)
    Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]", $CodeBufferMemory)
    DllStructSetData($CodeBuffer, 1, $Opcode)

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

    Local $Ret = DllCall("user32.dll", "word", "CallWindowProc", "ptr", DllStructGetPtr($CodeBuffer), _
                                                    "ptr", DllStructGetPtr($Input), _
                                                    "int", BinaryLen($Data), _
                                                    "word", $Initial, _
                                                    "word", $Polynomial)

    $Input = 0
    $CodeBuffer = 0
    _MemVirtualFree($CodeBufferMemory, 0, $MEM_RELEASE)

    Return $Ret[0]
EndFunc

CRC.ZIP

新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了

 

Link to comment
Share on other sites

Nice to see the x64 version ;). But something seems to be wrong. I tested the old x86 crc32 Opcode against the crc32 values created by Winzip, they are identical (and thus I assume them to be correct :) )... but now the new x86 Opcode is different ;)?

Old x86 crc32 Opcode
'0xC800040053BA2083B8EDB9000100008D41FF516A0859D1E8730231D0E2F85989848DFCFBFFFFE2E78B5D088B4D0C8B451085DB7416E3148A1330C20FB6D2C1E80833849500FCFFFF43E2ECF7D05BC9C21000'
        
New x86 crc32 Opcode
'0xC8000400538B5514B9000100008D41FF516A0859D1E8730231D0E2F85989848DFCFBFFFFE2E78B5D088B4D0C8B451085DB7416E3148A1330C20FB6D2C1E80833849500FCFFFF43E2ECF7D05BC9C21000'

Also if I test you example CRCFileTest.au3 against the same file, I get different results on x86 and x64. Additionally the results change when I change the $BufferSize.

Additionally I noticed the $Polynomial value for crc32 to be 0 in the old code (which I assume to be correct), now it is 0xEDB88320 by default. I'm not sure what to make of this one :shocked: ...

I would also recommend to initialize the $CodeBufferMemory & $CodeBuffer one time globally at the top of the Include crc.au3 and not every time the function is called. The memory should be released automatically on exit, to be clean _MemVirtualFree() and $CodeBuffer=0 called in a function registered with OnAutoItExitRegister() should do.

Edited by KaFu
Link to comment
Share on other sites

I rewrite the crc32 code to support different polynomial. Old code always use 0xEDB88320, and new code just use it as default. You can find out other polynomial at http://en.wikipedia.org/wiki/Cyclic_redundancy_check.

If x86 and x64 version generate different result, I think x86 version is correct. I not yet test x64 version very well until now, because I loss my new computer...... I can't compile x64 code now ;)

About innitialize $CodeBuffer as global variable. It should be, I just forget. But I think Static is better. (I hope Static will be the formal keyword in the furture)

新版 _ArrayAdd 的白痴作者,不管是誰,去死一死好了

 

Link to comment
Share on other sites

  • 2 weeks later...

Retested CRC32 and it seems to work good on x86 and x64 ;)... looking forward to the md5 and sha1 x64 implementation :), hope your x64 machine is back soon ;) ...

Here's a proposed change to speed up repetitive calls to the crc32 function:

#include <Memory.au3>

If @AutoItX64 Then
    Global $_CRC32Opcode = '0x554889E54881EC2004000048894D10488955184489452044894D28C745F800000000EB468B45F88945ECC745FC08000000EB1E8B45EC83E00184C0740D8B45ECD1E83345288945ECEB03D16DEC836DFC01837DFC007FDC8B45F848988B55EC899485E0FBFFFF8345F801817DF8FF0000007EB1488B4510488945F0C745F800000000EB318B452089C2C1EA088B45F84898480345F00FB6000FB6C033452025FF00000089C08B8485E0FBFFFF31D08945208345F8018B45F84898483B451872C48B4520F7D0C9C3'
Else
    Global $_CRC32Opcode = '0xC8000400538B5514B9000100008D41FF516A0859D1E8730231D0E2F85989848DFCFBFFFFE2E78B5D088B4D0C8B451085DB7416E3148A1330C20FB6D2C1E80833849500FCFFFF43E2ECF7D05BC9C21000'
EndIf

Global $_CRC32CodeBufferMemory = _MemVirtualAlloc(0, BinaryLen($_CRC32Opcode), $MEM_COMMIT, $PAGE_EXECUTE_READWRITE)
Global $_CRC32CodeBuffer = DllStructCreate("byte[" & BinaryLen($_CRC32Opcode) & "]", $_CRC32CodeBufferMemory)
DllStructSetData($_CRC32CodeBuffer, 1, $_CRC32Opcode)

OnAutoItExitRegister("_CRC32_Exit")

Func _CRC32($Data, $Initial = -1, $Polynomial = 0xEDB88320)
    Local $Input = DllStructCreate("byte[" & BinaryLen($Data) & "]")
    DllStructSetData($Input, 1, $Data)
    Local $Ret = DllCall("user32.dll", "uint", "CallWindowProc", "ptr", DllStructGetPtr($_CRC32CodeBuffer), _
            "ptr", DllStructGetPtr($Input), _
            "int", BinaryLen($Data), _
            "uint", $Initial, _
            "int", $Polynomial)
    $Input = 0
    Return $Ret[0]
EndFunc   ;==>_CRC32

Func _CRC32_Exit()
    $_CRC32CodeBuffer = 0
    _MemVirtualFree($_CRC32CodeBufferMemory, 0, $MEM_RELEASE)
EndFunc   ;==>_CRC32_Exit

; Example
$sFile = @WindowsDir & "\explorer.exe"
For $i = 1 To 10
    ConsoleWrite("CRC32 for " & $sFile & @TAB & "0x" & Hex(_CRC32(FileRead($sFile), 8)) & @CRLF)
Next
Edited by KaFu
Link to comment
Share on other sites

  • 3 months later...
Your post is empty Edited by iEvKI3gv9Wrkd41u

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

  • 1 month later...

Problem with windows server 2008

How is that helpful? Think you might need to say what the problem is rather than just saying "it's broke, don't work"?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I'm missing the joke?

Perhaps posting an Example over in the General Support section will Help you, but only if you stop continuing to post uninformative details!

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

  • 2 months later...

I tried the Base64 in Windows Server 2008 and it didn't work. When the function is called, windows reports the application has crashed. I don't have AutoIt on the server, but if you need some information on the error, let me know what you need and I could install AutoIt and provide the output.

The same script works fine in Windows 7, so i'm not too sure what is going wrong. Maybe it's the dll being called causing the error.

If you have an example script I can use that will output some debugging information that would be useful.

Thank you.

Link to comment
Share on other sites

You are correct, in both cases.

Windows Server 2008 is only 64-bit, whereas Windows 7 has both versions, this UDF still works on Windows 7 x64 though.

I tried the new UDF you mentioned and it worked perfectly.

Thank you for the quick reply.

Link to comment
Share on other sites

  • 3 months later...

I have a sneaking suspicion this will not work if the target machine has DEP (NX bit) on OptOut (or AlwaysOn). I'm running WinXP in a VM right now, but I'll try to test it and confirm when I get to a Windows box.

Edited by Unsigned

.

Link to comment
Share on other sites

Link to comment
Share on other sites

  • 4 weeks later...

Well, I downloaded the code from http://www.autoitscript.com/forum/index.php?app=core&module=attach&section=attach&attach_id=22412, and tried both SHA1Test and MD5Test. Both caused an error and autoit to crash. Here is the log for MD5Test:

>Running:(3.3.6.1):C:\Program Files (x86)\AutoIt3\autoit3_x64.exe "C:\X\SHA1_MD5_RC4_BASE64_CRC32_XXTEA\MD5Test.au3"

!>16:46:16 AutoIT3.exe ended.rc:-1073741819

>Exit code: -1073741819 Time: 3.023

My OS is windows 2008 R1. Is something escaping me?

Thanks!

Link to comment
Share on other sites

Link to comment
Share on other sites

OK, I downloaded that one and tried HashesFileTest.au3. It finds that there is a missing function, _Checksum_Init() in the include fie CHECKSum.au3.

The error:

>Running AU3Check (1.54.19.0) from:C:\Program Files (x86)\AutoIt3

C:\X\AutoIt Machine Code Algorithm Collection\Hash\CHECKSUM.au3(104,64) : ERROR: _CHECKSUM_Init(): undefined function.

If Not IsDllStruct($_CHECKSUM_CodeBuffer) Then _CHECKSUM_Init()

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

C:\X\AutoIt Machine Code Algorithm Collection\Hash\HASHESFileTest.au3 - 1 error(s), 0 warning(s)

!>17:22:31 AU3Check ended.rc:2

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...