Jump to content

AutoIt Machine Code Algorithm Collection


Ward
 Share

Recommended Posts

I am having trouble with the AES, both AESTest files are giving this error:

C:\Users\Tech\Desktop\AutoIt Machine Code Algorithm Collection\Encode\AES.au3(16,14) : ERROR: syntax error
Global Const Enum

Changing to:

Global $AES_CBC_MODE, $AES_CFB_MODE, $AES_OFB_MODE
resolves it and all is well.

In AutoIt 3.3.6.1, this line is OK.

If "Enum" is not supported, it may replace as following:

Global Const $AES_CBC_MODE = 0
Global Const $AES_CFB_MODE = 1
Global Const $AES_OFB_MODE = 2

My only request at this point is for salt support, or is that already somehow possible?

Thanks

Ian

You can write your own key derivation function.

For example (PBKDF1):

$Key = _MD5($Password & $Salt)
For $i = 1 To 1000
    $Key = _MD5($Hash)
Next

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

 

Link to comment
Share on other sites

  • 1 month later...

Hello

The CHECKSUM.au3 is reporting that _CHECKSUM_Init() Does not exist - Should it be _CHECKSUM_Startup() ?

Also in Hashesfiletest.au3, This

Dim $State = _HashInit(Eval('_HASH_' & $HashName))

Is generating this error - "_HashInit() previously called with Const or expression on ByRef param(s)."

I fixed with

local $fixthis = Eval('_HASH_' & $HashName)
Dim $State = _HashInit($fixthis)

Appart from that they work a treat - Many thanks

Paul

Link to comment
Share on other sites

Just wanted to thank you. Very usefully and somewhat unbelievable.

I don't know if its just me but LZF(.au3) crashes when decompressing PNG attached.

; -----------------------------------------------------------------------------
; LZF Compression Machine Code UDF Example
; Purpose: Provide The Machine Code Version of LZF Algorithm In AutoIt
; Author: Ward
; LZF Copyright (C) 2000-2007 Marc Alexander Lehmann 
; -----------------------------------------------------------------------------

#Include "LZF.au3"

Dim $Original = Binary(FileRead("test.png"))

Dim $Compressed = _LZF_Compress($Original)
Dim $Decompressed = _LZF_Decompress($Compressed)
Dim $Result = 'Original Size: ' & BinaryLen($Original) & @CRLF
$Result &= 'Compressed Size: ' & BinaryLen($Compressed); & @CRLF
$Result &= 'Decompress Succeed: ' & ($Decompressed = $Original)
MsgBox(0, 'LZF Test', $Result)

post-39800-0-94628200-1310456093_thumb.p

Edited by dexto
Link to comment
Share on other sites

  • 4 weeks later...

So, can this be somehow modified as to allow the decompressing/unzipping of files?

These are only compression algorithm, not archiver. I have no intent to make machine code of archiver now.

I think you can use MemoryDll UDF with some archiver DLL.

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

 

Link to comment
Share on other sites

So, can this be somehow modified as to allow the decompressing/unzipping of files?

If you take Ward's zlib udf; you can really create your own zip handling solution (compress/decompress) without any external dll. It works great, and I've used it myself to create such.
Link to comment
Share on other sites

  • 2 months later...

Hi Ward, seems like your example "HASHESFileTest.au3" does not seem to work (for me a last :D ), it throws an

ERROR: _HashInit() called with Const or expression on ByRef-param(s).

Edit:

Oh, has already been reported before :oops:...

I fixed with

local $fixthis = Eval('_HASH_' & $HashName)
Dim $State = _HashInit($fixthis)

Here's an example for md5 (was asked by someone else).

#include "MD5.au3"
 
Dim $BufferSize = 0x100000
Dim $Filename = FileOpenDialog("Open File", "", "Any File (*.*)")
If $Filename = "" Then Exit
 
Dim $Timer = TimerInit()
Dim $State = _MD5Init()
 
Dim $FileHandle = FileOpen($Filename, 16)
For $i = 1 To Ceiling(FileGetSize($Filename) / $BufferSize)
    _MD5Input($State, FileRead($FileHandle, $BufferSize))
Next
Dim $Hash = _MD5Result($State)
FileClose($FileHandle)
 
ConsoleWrite($Hash & @TAB & TimerDiff($Timer) & @CRLF)
Edited by KaFu
Link to comment
Share on other sites

  • 1 month later...

@Ward

Is there a known issue with crc32 on 64-bit? It crashes inside my Windows 7 x64 vm. Most of the other ones seems to work fine though.

Edit: It seems to be my implementation of it that is the problem. But works fine on 32-bit though, so is strange..

Edited by joakim
Link to comment
Share on other sites

  • 1 month later...

well, good job!

but, now, i have a puzzle.

i try to use the _crypt* udf with some algorithm that marked in msdn but i cannot get the same result between them?

#include'des.au3'
#include<crypt.au3>
local $CALG_DES = 0x00006601  ; http://msdn.microsoft.com/en-us/library/ms937014.aspx
Dim $hKey=_Crypt_DeriveKey("The Key", $CALG_DES)
Dim $Encrypt = _Crypt_EncryptData("The quick brown fox jumped over the lazy dog", $hKey, $CALG_USERKEY) & @crlf
$Encrypt &= _DesEncrypt("The Key", "The quick brown fox jumped over the lazy dog")
MsgBox(0, 'Encrypt String by DES Algorithm', $Encrypt)

anybody would like to help?

Edited by netegg
Link to comment
Share on other sites

The Crypto API derives a key from the given phrase, it does not use it directly. You'll have to use CryptImportKey, I have implemented a simple version here: http://www.autoit.de/index.php?page=Thread&postID=236228#post236228

Edit: This is nearly correct, I don't know why the last 8 bytes differ. It is the same when using the JS-Implementation here: http://www.tero.co.uk/des/test.php 8 bytes are different to the other functions.

#include "AlgorithmsEncodedes.au3"

#include<crypt.au3>
_Crypt_Startup()
$Key = "The Key"
$IV = "12345678"
$data = Binary("The quick brown fox jumped over the lazy dog")

Const $KP_IV = 1
; local $CALG_DES = 0x00006601  ; http://msdn.microsoft.com/en-us/library/ms937014.aspx
Dim $hKey=_CryptImportKey($CALG_DES, $Key, 8)
Const $KP_MODE = 4
Const $CRYPT_MODE_CBC = 1
_CryptSetKeyParam($hKey, $KP_MODE, $CRYPT_MODE_CBC, 0, "dword*")
_CryptSetKeyParam($hKey, $KP_IV, $IV, 0, "str")



$Encrypt1 = _Crypt_EncryptData($data, $hKey, $CALG_USERKEY)

$Encrypt2 = _DesEncrypt($Key, $data, $IV)

MsgBox(0, 'Encrypt String by DES Algorithm', $Encrypt1 & @CRLF & _
    BinaryMid($Encrypt2, 9) & @CRLF & _  ; The first 8 bytes are the IV when using _DesEncrypt
    $Encrypt2 )

_Crypt_DestroyKey($hKey)
_Crypt_Shutdown()

Func _CryptImportKey($CALG, $bKey, $iKeyLength = -1)
    ; Author: ProgAndy
    If $iKeyLength < 1 Then $iKeyLength = BinaryLen($bKey)
    Local $blob = DllStructCreate("align 1;BYTE   bType;BYTE   bVersion;WORD   reserved;dword aiKeyAlg;dword keysize;byte key[" & $iKeyLength & "]")
    DllStructSetData($blob, 1, 0x8)
    DllStructSetData($blob, 2, 2)
    DllStructSetData($blob, 4, $CALG)
    DllStructSetData($blob, 5, $iKeyLength)
    DllStructSetData($blob, 6, Binary($bKey))
    Local $aRet = DllCall(__Crypt_DllHandle(), "bool", "CryptImportKey", "handle", __Crypt_Context(), "ptr", DllStructGetPtr($blob), "dword", DllStructGetSize($blob), "ptr", 0, "dword", 0, "ptr*", 0)
    If @error Then Return SetError(2, @error, 0)
    Return SetError(Not $aRet[0], 0, $aRet[6])
EndFunc

Func _CryptSetKeyParam($hKey, $iParam, $vValue, $iFlags=0, $sValType=Default)
    ; Author: ProgAndy
    If Not $sValType Or $sValType = Default Then $sValType = "ptr"
    Local $aRet = DllCall(__Crypt_DllHandle(), "bool", "CryptSetKeyParam", "handle", $hKey, "uint", $iParam, $sValType, $vValue, "dword", $iFlags)
    If @error Then Return SetError(2, @error, 0)
    Return SetError(Not $aRet[0], 0, $aRet[0])
EndFunc

Edit: OK, That should be the result of different padding.

Edit: You'll have to modify des.au3 to use PKCS#5 (#7) padding in order to decrypt it with the Crypto-API. The used bit-padding is not supported.

http://en.wikipedia.org/wiki/Padding_%28cryptography%29#Padding_methods

Func _DesEncryptCBC_Pad(ByRef $DesCtx, ByRef $IV, $Data)
    $Data = Binary($Data)

    Local $PadLen = 8 - Mod(BinaryLen($Data), 8)
    If $PadLen = 0 Then $PadLen = 8
    Local $Pad = Binary('')
    For $i = 1 To $PadLen
        $Pad &= Binary(Chr($PadLen))
    Next

    Return _DesEncryptCBC($DesCtx, $IV, $Data & $Pad)
EndFunc
Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Hi ProgAndy,

Another question. Which one is exactly or more correct between with crypt api and with _des*(callwindowproc function)?

I think that the answer will decide the trans- method!

Thanks!

Edited by netegg
Link to comment
Share on other sites

Both functions produce a valid result, the padding is not standardized. I suppose, most libraries use PKCS by default.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • 4 weeks later...

Hi Ward

As dexto had notified post #23 there is a problem with png files.

I didn't try _LZF_Compress, but _LZMA_Compress Function ( LZMATest.au3 ).

I have tried several filetype succesfully, but with png files i get true or false to Decompress result.

After a moment i remark that only "bigger" png files return false.

So i have resized a png until i get a true result :

- LZMA Level 5 Test png file : Original Size: 95739 png 203x203

Compressed Size: 96767

Decompress Succeed: False

- LZMA Level 5 Test png file : Original Size: 94880 png 201x201

Compressed Size: 95850

Decompress Succeed: True

It's strange ... :)

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

This error only happen when "Compressed Size" > "Original Size".

In this situation, just don't use LZMA.

If you want to fix that. You can modify _LZMA_Compress_Core function in LZMA.au3:

;Local $OutputLen = $InputLen + 1024
Local $OutputLen = $InputLen + 4096 ; or more...

Or you can check the $Ret[0] value at the end of this function, it can be

$SZ_OK = 0
$SZ_ERROR_MEM = 2
$SZ_ERROR_PARAM = 5
$SZ_ERROR_OUTPUT_EOF = 7

In your example, the $Ret[0] = 7 so the result is not OK.

Edited by Ward

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

 

Link to comment
Share on other sites

  • 2 months later...
  • 2 months later...

I download AutoIt Machine Code Algorithm Collection.zip and test to run AESTest 2.au3.

I got this error message.

#Include "AES.au3"

Dim $Key = Binary('0x11111111111111111111111111111111')
Dim $Data = Binary('0x000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F')
Dim $Encrypt = _AesEncryptECB(_AesEncryptKey($Key), $Data)
Dim $Decrypt = _AesDecryptECB(_AesDecryptKey($Key), $Encrypt)
ConsoleWrite('=== Encrypt Two Block With AES128 ECB Mode ===' & @CRLF)
ConsoleWrite('Encrypt: ' & $Encrypt & @CRLF & 'Decrypt: ' & $Decrypt & @CRLF & @CRLF)

Error Message:

>"D:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "D:\Ftproot\Software\Autoit 3.0\ScriptNew\AutoIt Machine Code Algorithm Collection\Encode\AESTest 2.au3" /UserParams

+>19:08:50 Starting AutoIt3Wrapper v.2.1.0.33 Environment(Language:0404 Keyboard:00000404 OS:WIN_7/Service Pack 1 CPU:X64 OS:X64)

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

D:\AutoIt Machine Code Algorithm Collection\Encode\AESTest 2.au3(14,58) : ERROR: _AesEncryptECB() called with Const or expression on ByRef-param(s).

Dim $Encrypt = _AesEncryptECB(_AesEncryptKey($Key), $Data)

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

D:\AutoIt Machine Code Algorithm Collection\Encode\AES.au3(171,42) : REF: definition of _AesEncryptECB().

Func _AesEncryptECB(ByRef $AesCtx, $Data)

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

D:\AutoIt Machine Code Algorithm Collection\Encode\AESTest 2.au3(15,61) : ERROR: _AesDecryptECB() called with Const or expression on ByRef-param(s).

Dim $Decrypt = _AesDecryptECB(_AesDecryptKey($Key), $Encrypt)

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

post-74315-0-29826600-1342437494_thumb.p

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...