Ward Posted July 20, 2011 Share Posted July 20, 2011 (edited) "Binary" is a built-in variable type in AutoIt. But functions that deal with binary variable are inadequate. Someone says string functions can also deal with binary variable, but actually, it may cause some problem. For example, using StringInStr to search "0x11" in "0x0110" will return a false result. This UDF solves the problem. It provide a lot of binary related functions. Furthermore, most functions in the UDF are optimized by machine code, so the speed is incredible. Here is the function list: _BinaryAnd($Binary1, $Binary2) _BinaryOR($Binary1, $Binary2) _BinaryXOR($Binary1, $Binary2) _BinaryNot($Binary) _BinaryShift($Binary, $Shift) _BinaryRotate($Binary, $Shift) _BinaryReverse($Binary) _BinaryInBin($Binary, $Search, $Occur = 1, $Start = 1) _BinaryReplace($Binary, $Search, $Replace, $Occur = 0) _BinarySplit($Binary, $Search) _BinaryRight($Binary, $Count) _BinaryLeft($Binary, $Count) _BinaryTrimLeft($Binary, $Count) _BinaryTrimRight($Binary, $Count)The usage of these functions are just like the built-in StringXXXX or BitXXXX functions. Attentions:BinarySplit has a little bit different, it don't support flag parameter in StringSplit.BinaryInBin and BinaryReplace also don't need casesense parameter. _BinaryPeek($Binary, $Start, $Type = "byte") _BinaryPoke($Binary, $Start, $Value, $Type = "byte") _BinaryToInt32($Binary) _BinaryFromInt32($Value) _BinaryToInt64($Binary) _BinaryFromInt64($Value) _BinaryRandom($Length, $Start = 0, $To = 255)These functions are some helper function. BinaryPeek and BinaryPoke work like stardand BASIC keyword peek and poke. They can handle types defined in DllStructCreate and DllCall (include str and wstr). The $Start are also like other AutoIt functions, count from 1, not from 0. BinaryRandom generate a random binary data for test or something. It has built-in Mersenne Twister PRNG. BinaryToXXX and BinaryFromXXX convert variable type between binary and int32/int64. _BitShift64($Value, $Shift) _BitRotate64($Value, $Shift) _BitNOT64($Value) _BitOR64($Value1, $Value2, [$Value3, ...]) _BitAND64($Value1, $Value2, [$Value3, ...]) _BitXOR64($Value1, $Value2, [$Value3, ...]) _Hex64($Value, $Length = 16) _Dec64($HexString)These functions are just the same as built-in functin in the same name, but these can handle 64 bit signed integer.(Built-in function only for 32 bit integer) Binary UDF.zip 2011/09/15 Update Note:Add following functions: _BinaryToInt16($Binary) _BinaryFromInt16($Value) _BinaryToDouble($Binary) _BinaryFromDouble($Value) _BinaryToMemory($Binary, $Ptr) _BinaryFromMemory($Ptr, $Size) _BinaryToDLLStruct($Binary) _BinaryFromDLLStruct(ByRef $DLLStruct) _BinaryFillDLLStruct($Binary, ByRef $DLLStruct)_BinaryRandom can specify the random seed now. $Seed = 0 mean no seed is specified. _BinaryRandom($Length, $Start = 0, $To = 255, $Seed = 0)Use static variable to store the binary code to avoid repeat memory allocation.Binary UDF.zip Edited November 23, 2015 by Ward Skitty 1 新版 _ArrayAdd 的白痴作者，不管是誰，去死一死好了。 Link to comment Share on other sites More sharing options...
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
Already have an account? Sign in here.Sign In Now