home *** CD-ROM | disk | FTP | other *** search
/ Xentax forum attachments archive / xentax.7z / 13089 / UE4_locres_new_tools_source_code.7z / src / Binary.au3 next >
Encoding:
Text File  |  2011-09-15  |  26.1 KB  |  626 lines

  1. ; =============================================================================
  2. ;  AutoIt Binary UDF (2011.9.15)
  3. ;  Purpose: Functions About Binary Type Variable Management
  4. ;  Author: Ward
  5. ; =============================================================================
  6.  
  7. ; =============================================================================
  8. ;  Functions List
  9. ;   _BinaryPeek($Binary, $Start, $Type = "byte")
  10. ;   _BinaryPoke($Binary, $Start, $Value, $Type = "byte")
  11. ;   _BinaryAnd($Binary1, $Binary2)
  12. ;   _BinaryOR($Binary1, $Binary2)
  13. ;   _BinaryXOR($Binary1, $Binary2)
  14. ;   _BinaryNot($Binary)
  15. ;   _BinaryShift($Binary, $Shift)
  16. ;   _BinaryRotate($Binary, $Shift)
  17. ;   _BinaryReverse($Binary)
  18. ;   _BinaryInBin($Binary, $Search, $Occur = 1, $Start = 1)
  19. ;   _BinaryReplace($Binary, $Search, $Replace, $Occur = 0)
  20. ;   _BinarySplit($Binary, $Search)
  21. ;   _BinaryRandom($Length, $Start = 0, $To = 255)
  22. ;   _BinaryRight($Binary, $Count)
  23. ;   _BinaryLeft($Binary, $Count)
  24. ;   _BinaryTrimLeft($Binary, $Count)
  25. ;   _BinaryTrimRight($Binary, $Count)
  26. ;    _BinaryToInt16($Binary)
  27. ;    _BinaryFromInt16($Value)
  28. ;   _BinaryToInt32($Binary)
  29. ;   _BinaryFromInt32($Value)
  30. ;   _BinaryToInt64($Binary)
  31. ;   _BinaryFromInt64($Value)
  32. ;   _BinaryToDouble($Binary)
  33. ;   _BinaryFromDouble($Value)
  34. ;    _BinaryToMemory($Binary, $Ptr)
  35. ;    _BinaryFromMemory($Ptr, $Size)
  36. ;    _BinaryToDLLStruct($Binary)
  37. ;    _BinaryFromDLLStruct(ByRef $DLLStruct)
  38. ;    _BinaryFillDLLStruct($Binary, ByRef $DLLStruct)
  39. ;   _BitShift64($Value, $Shift)
  40. ;   _BitRotate64($Value, $Shift)
  41. ;   _BitNOT64($Value)
  42. ;   _BitOR64($Value1, $Value2, [$Value3, ...])
  43. ;   _BitAND64($Value1, $Value2, [$Value3, ...])
  44. ;   _BitXOR64($Value1, $Value2, [$Value3, ...])
  45. ;   _Hex64($Value, $Length = 16)
  46. ;   _Dec64($HexString)
  47. ; =============================================================================
  48.  
  49.  
  50. #Include-once
  51. #Include <Memory.au3>
  52.  
  53. Global $__Binary_Kernel32Dll = DllOpen("kernel32.dll")
  54. Global $__Binary_User32Dll = DllOpen("user32.dll")
  55. Global $__Binary_MsvcrtDll = DllOpen("msvcrt.dll")
  56.  
  57. Func __Binary_lstrlenA($Ptr)
  58.     Local $Ret = DllCall($__Binary_Kernel32Dll, "int", "lstrlenA", "ptr", $Ptr)
  59.     If @Error Then Return SetError(@Error, @Extended, 0)
  60.     Return $Ret[0]
  61. EndFunc
  62.  
  63. Func __Binary_lstrlenW($Ptr)
  64.     Local $Ret = DllCall($__Binary_Kernel32Dll, "int", "lstrlenW", "ptr", $Ptr)
  65.     If @Error Then Return SetError(@Error, @Extended, 0)
  66.     Return $Ret[0]
  67. EndFunc
  68.  
  69. Func __Binary_Realloc($Ptr, $Size)
  70.     Local $Ret = DllCall($__Binary_MsvcrtDll, "ptr:cdecl", "realloc", "ptr", $Ptr, "ulong_ptr", $Size)
  71.     If @Error Then Return SetError(@Error, @Extended, 0)
  72.     If $Ret[0] = 0 Then Exit MsgBox(16, "AutoIt Binary UDF Error", "Out of memory !!")
  73.     Return $Ret[0]
  74. EndFunc
  75.  
  76. Func __Binary_Free($Ptr)
  77.     DllCall($__Binary_MsvcrtDll, "ptr:cdecl", "free", "ptr", $Ptr)
  78.     If @Error Then Return SetError(@Error, @Extended, 0)
  79. EndFunc
  80.  
  81. Func __BinaryCodeBufferAlloc($Code)
  82.     Local $Ptr = _MemVirtualAlloc(0, BinaryLen($Code), $MEM_COMMIT, $PAGE_EXECUTE_READWRITE)
  83.     If $Ptr = 0 Then Exit MsgBox(16, "AutoIt Binary UDF Error", "Out of memory !!")
  84.     Local $Buffer = DllStructCreate("byte[" & BinaryLen($Code) & "]", $Ptr)
  85.     DllStructSetData($Buffer, 1, $Code)
  86.     Return $Ptr
  87. EndFunc
  88.  
  89. Func _BinaryPeek($Binary, $Start, $Type = "byte")
  90.     $Binary = Binary($Binary)
  91.     If $Start > BinaryLen($Binary) Or $Start = 0 Then Return SetError(1, 0, "")
  92.  
  93.     Local $Buffer = DllStructCreate("byte[" & (BinaryLen($Binary) + 8) & "]")
  94.     DllStructSetData($Buffer, 1, $Binary)
  95.  
  96.     Local $Ptr = DllStructGetPtr($Buffer) + $Start - 1, $Len = -1
  97.     If $Type = "str" Then
  98.         $Len = __Binary_lstrlenA($Ptr)
  99.         $Type = "char[" & $Len & "]"
  100.     ElseIf $Type = "wstr" Then
  101.         $Len = __Binary_lstrlenW($Ptr)
  102.         $Type = "wchar[" & $Len & "]"
  103.     EndIf
  104.     If $Len = 0 Then Return ""
  105.  
  106.     Local $Target = DllStructCreate($Type, $Ptr)
  107.     If DllStructGetSize($Target) = 0 Or DllStructGetSize($Target) > BinaryLen($Binary) - $Start + 1 Then Return SetError(1, 0, "")
  108.     Return DllStructGetData($Target, 1)
  109. EndFunc
  110.  
  111. Func _BinaryPoke($Binary, $Start, $Value, $Type = "byte")
  112.     $Binary = Binary($Binary)
  113.     If $Start > BinaryLen($Binary) Or $Start = 0 Then Return SetError(1, 0, "")
  114.  
  115.     Local $Buffer = DllStructCreate("byte[" & (BinaryLen($Binary)) & "]")
  116.     DllStructSetData($Buffer, 1, $Binary)
  117.  
  118.     Local $Ptr = DllStructGetPtr($Buffer) + $Start - 1
  119.     If $Type = "str" Then
  120.         $Value = String($Value)
  121.         $Type = "char[" & (StringLen($Value) + 1) & "]"
  122.     ElseIf $Type = "wstr" Then
  123.         $Value = String($Value)
  124.         $Type = "wchar[" & (StringLen($Value) + 1) & "]"
  125.     EndIf
  126.  
  127.     Local $Target = DllStructCreate($Type, $Ptr)
  128.     If DllStructGetSize($Target) = 0 Or DllStructGetSize($Target) > BinaryLen($Binary) - $Start + 1 Then Return SetError(1, 0, "")
  129.     DllStructSetData(DllStructCreate($Type, $Ptr), 1, $Value)
  130.     Return DllStructGetData($Buffer, 1)
  131. EndFunc
  132.  
  133. Func _BinaryAnd($Binary1, $Binary2)
  134.     Static $CodeBufferPtr
  135.     If Not $CodeBufferPtr Then
  136.         Local $Code
  137.         If @AutoItX64 Then
  138.             $Code = Binary("0x4989CA4863CA31D289C8FFC841F7F14863D2418A04104120440AFFE2E9C3")
  139.         Else
  140.             $Code = Binary("0x5589E556578B7D088B75108B4D0C31D289C848F775148A041620440FFFE2EF5F5E5DC21000")
  141.         EndIf
  142.         $CodeBufferPtr = __BinaryCodeBufferAlloc($Code)
  143.     EndIf
  144.  
  145.     $Binary1 = Binary($Binary1)
  146.     $Binary2 = Binary($Binary2)
  147.  
  148.     Local $Len1 = BinaryLen($Binary1)
  149.     Local $Buffer1 = DllStructCreate("byte[" & $Len1 & "]")
  150.     DllStructSetData($Buffer1, 1, $Binary1)
  151.  
  152.     Local $Len2 = BinaryLen($Binary2)
  153.     Local $Buffer2 = DllStructCreate("byte[" & $Len2 & "]")
  154.     DllStructSetData($Buffer2, 1, $Binary2)
  155.  
  156.     If $Len1 And $Len2 Then
  157.         DllCall($__Binary_User32Dll, "none", "CallWindowProc", "ptr", $CodeBufferPtr, _
  158.                                                                 "ptr", DllStructGetPtr($Buffer1), _
  159.                                                                 "uint", $Len1, _
  160.                                                                 "ptr", DllStructGetPtr($Buffer2), _
  161.                                                                 "uint", $Len2)
  162.     EndIf
  163.     Return DllStructGetData($Buffer1, 1)
  164. EndFunc
  165.  
  166. Func _BinaryOR($Binary1, $Binary2)
  167.     Static $CodeBufferPtr
  168.     If Not $CodeBufferPtr Then
  169.         Local $Code
  170.         If @AutoItX64 Then
  171.             $Code = Binary("0x4989CA4863CA31D289C8FFC841F7F14863D2418A04104108440AFFE2E9C3")
  172.         Else
  173.             $Code = Binary("0x5589E556578B7D088B75108B4D0C31D289C848F775148A041608440FFFE2EF5F5E5DC21000")
  174.         EndIf
  175.         $CodeBufferPtr = __BinaryCodeBufferAlloc($Code)
  176.     EndIf
  177.  
  178.     $Binary1 = Binary($Binary1)
  179.     $Binary2 = Binary($Binary2)
  180.  
  181.     Local $Len1 = BinaryLen($Binary1)
  182.     Local $Buffer1 = DllStructCreate("byte[" & $Len1 & "]")
  183.     DllStructSetData($Buffer1, 1, $Binary1)
  184.  
  185.     Local $Len2 = BinaryLen($Binary2)
  186.     Local $Buffer2 = DllStructCreate("byte[" & $Len2 & "]")
  187.     DllStructSetData($Buffer2, 1, $Binary2)
  188.  
  189.     If $Len1 And $Len2 Then
  190.         DllCall($__Binary_User32Dll, "none", "CallWindowProc", "ptr", $CodeBufferPtr, _
  191.                                                                 "ptr", DllStructGetPtr($Buffer1), _
  192.                                                                 "uint", $Len1, _
  193.                                                                 "ptr", DllStructGetPtr($Buffer2), _
  194.                                                                 "uint", $Len2)
  195.     EndIf
  196.  
  197.     Return DllStructGetData($Buffer1, 1)
  198. EndFunc
  199.  
  200. Func _BinaryXOR($Binary1, $Binary2)
  201.     Static $CodeBufferPtr
  202.     If Not $CodeBufferPtr Then
  203.         Local $Code
  204.         If @AutoItX64 Then
  205.             $Code = Binary("0x4989CA4863CA31D289C8FFC841F7F14863D2418A04104130440AFFE2E9C3")
  206.         Else
  207.             $Code = Binary("0x5589E556578B7D088B75108B4D0C31D289C848F775148A041630440FFFE2EF5F5E5DC21000")
  208.         EndIf
  209.         $CodeBufferPtr = __BinaryCodeBufferAlloc($Code)
  210.     EndIf
  211.  
  212.     $Binary1 = Binary($Binary1)
  213.     $Binary2 = Binary($Binary2)
  214.  
  215.     Local $Len1 = BinaryLen($Binary1)
  216.     Local $Buffer1 = DllStructCreate("byte[" & $Len1 & "]")
  217.     DllStructSetData($Buffer1, 1, $Binary1)
  218.  
  219.     Local $Len2 = BinaryLen($Binary2)
  220.     Local $Buffer2 = DllStructCreate("byte[" & $Len2 & "]")
  221.     DllStructSetData($Buffer2, 1, $Binary2)
  222.  
  223.     If $Len1 And $Len2 Then
  224.         DllCall($__Binary_User32Dll, "none", "CallWindowProc", "ptr", $CodeBufferPtr, _
  225.                                                                 "ptr", DllStructGetPtr($Buffer1), _
  226.                                                                 "uint", $Len1, _
  227.                                                                 "ptr", DllStructGetPtr($Buffer2), _
  228.                                                                 "uint", $Len2)
  229.     EndIf
  230.  
  231.     If $Len1 = 0 Then Return Binary("")
  232.     Return DllStructGetData($Buffer1, 1)
  233. EndFunc
  234.  
  235. Func _BinaryNot($Binary)
  236.     Static $CodeBufferPtr
  237.     If Not $CodeBufferPtr Then
  238.         Local $Code
  239.         If @AutoItX64 Then
  240.             $Code = Binary("0x4887CAF6540AFFE2FAC3")
  241.         Else
  242.             $Code = Binary("0x5589E58B45088B4D0CF65408FFE2FA5DC21000")
  243.         EndIf
  244.         $CodeBufferPtr = __BinaryCodeBufferAlloc($Code)
  245.     EndIf
  246.  
  247.     $Binary = Binary($Binary)
  248.  
  249.     Local $Len = BinaryLen($Binary)
  250.     Local $Buffer = DllStructCreate("byte[" & $Len & "]")
  251.     DllStructSetData($Buffer, 1, $Binary)
  252.  
  253.     If $Len Then
  254.         DllCall($__Binary_User32Dll, "none", "CallWindowProc", "ptr", $CodeBufferPtr, _
  255.                                                                 "ptr", DllStructGetPtr($Buffer), _
  256.                                                                 "uint", $Len, _
  257.                                                                 "int", 0, _
  258.                                                                 "int", 0)
  259.     EndIf
  260.  
  261.     Return DllStructGetData($Buffer, 1)
  262. EndFunc
  263.  
  264. Func _BinaryShift($Binary, $Shift)
  265.     Static $CodeBufferPtr
  266.     If Not $CodeBufferPtr Then
  267.         Local $Code
  268.         If @AutoItX64 Then
  269.             $Code = Binary("0x4989CA4C63CA4983F90074434183F800743D7F1F41F7D84C89C94C89D2F8D0129F48FFC9740648FFC29EEBF241FFC875E6EB1C4C89C9498D540AFFF8D01A9F48FFC9740648FFCA9EEBF241FFC875E4C3")
  270.         Else
  271.             $Code = Binary("0x5589E55657538B7D088B5D0C8B751083FB00743183FE00742C7F16F7DE89D989FAF8D0129F497404429EEBF64E75EEEB1489D98D540FFFF8D01A9F4974044A9EEBF64E75EC5B5F5E5DC21000")
  272.         EndIf
  273.         $CodeBufferPtr = __BinaryCodeBufferAlloc($Code)
  274.     EndIf
  275.  
  276.     $Binary = Binary($Binary)
  277.  
  278.     Local $Len = BinaryLen($Binary)
  279.     Local $Buffer = DllStructCreate("byte[" & $Len & "]")
  280.     DllStructSetData($Buffer, 1, $Binary)
  281.  
  282.     If $Len Then
  283.         DllCall($__Binary_User32Dll, "none", "CallWindowProc", "ptr", $CodeBufferPtr, _
  284.                                                                 "ptr", DllStructGetPtr($Buffer), _
  285.                                                                 "uint", $Len, _
  286.                                                                 "int", $Shift, _
  287.                                                                 "int", 0)
  288.     EndIf
  289.  
  290.     Return DllStructGetData($Buffer, 1)
  291. EndFunc
  292.  
  293. Func _BinaryRotate($Binary, $Shift)
  294.     Static $CodeBufferPtr
  295.     If Not $CodeBufferPtr Then
  296.         Local $Code
  297.         If @AutoItX64 Then
  298.             $Code = Binary("0x4989CA4C63CA4983F90074554183F800744F7F2941F7D84C89C9498D540AFF410FB602660FBAE000D01A9F48FFC9740648FFCA9EEBF241FFC875DCEB244C89C94C89D2430FB6440AFF660FBAE007D0129F48FFC9740648FFC29EEBF241FFC875DCC3")
  299.         Else
  300.             $Code = Binary("0x5589E55657538B7D088B5D0C8B751083FB00744183FE00743C7F1FF7DE89D98D540FFF0FB607660FBAE000D01A9F4974044A9EEBF64E75E5EB1B89D989FA0FB6441FFF660FBAE007D0129F497404429EEBF64E75E55B5F5E5DC21000")
  301.         EndIf
  302.         $CodeBufferPtr = __BinaryCodeBufferAlloc($Code)
  303.     EndIf
  304.  
  305.     $Binary = Binary($Binary)
  306.  
  307.     Local $Len = BinaryLen($Binary)
  308.     Local $Buffer = DllStructCreate("byte[" & $Len & "]")
  309.     DllStructSetData($Buffer, 1, $Binary)
  310.  
  311.     If $Len Then
  312.         DllCall($__Binary_User32Dll, "none", "CallWindowProc", "ptr", $CodeBufferPtr, _
  313.                                                                 "ptr", DllStructGetPtr($Buffer), _
  314.                                                                 "uint", $Len, _
  315.                                                                 "int", $Shift, _
  316.                                                                 "int", 0)
  317.     EndIf
  318.  
  319.     Return DllStructGetData($Buffer, 1)
  320. EndFunc
  321.  
  322. Func _BinaryReverse($Binary)
  323.     Static $CodeBufferPtr
  324.     If Not $CodeBufferPtr Then
  325.         Local $Code
  326.         If @AutoItX64 Then
  327.             $Code = Binary("0x4889C84863D2488D5410FFEB128A0A32088808320A880A300848FFCA48FFC04839D072E9C3")
  328.         Else
  329.             $Code = Binary("0x8B4424048B5424088D5410FFEB0E8A0A32088808320A880A30084A4039D072EEC21000")
  330.         EndIf
  331.         $CodeBufferPtr = __BinaryCodeBufferAlloc($Code)
  332.     EndIf
  333.  
  334.     $Binary = Binary($Binary)
  335.  
  336.     Local $Len = BinaryLen($Binary)
  337.     Local $Buffer = DllStructCreate("byte[" & $Len & "]")
  338.     DllStructSetData($Buffer, 1, $Binary)
  339.  
  340.     If $Len Then
  341.         DllCall($__Binary_User32Dll, "none", "CallWindowProc", "ptr", $CodeBufferPtr, _
  342.                                                                 "ptr", DllStructGetPtr($Buffer), _
  343.                                                                 "uint", $Len, _
  344.                                                                 "int", 0, _
  345.                                                                 "int", 0)
  346.     EndIf
  347.  
  348.     Return DllStructGetData($Buffer, 1)
  349. EndFunc
  350.  
  351. Func _BinaryInBin($Binary, $Search, $Occur = 1, $Start = 1)
  352.     Static $CodeBufferPtr
  353.     If Not $CodeBufferPtr Then
  354.         Local $Code
  355.         If @AutoItX64 Then
  356.             $Code = Binary("0x555756534883EC08448B51188B5120448B491C4C8B59108B4108488B294585D274504183F9007E5585D24989E8BB01000000741083EA0139D076374189D029D04D8D04284139C277294489D24863DBEB034901D84839D24C89C64C89DF4889D1F3A675064183E901741A83E8014139C276DF4883C40831C05B5E5F5DC375154989E8EBC04883C4084129E85B5E5F418D40015DC34189C041F7D9BBFFFFFFFF4529D04D8D0428EB9C")
  357.         Else
  358.             $Code = Binary("0x5589E583EC24895DF48B4D088975F8897DFC8B398B59088B51108B7104897DF08B45F0895DE88B590C8945E031C085DB8955E48B51148975EC743A837DE4007E51C745DC0100000085D27538395DEC7222FC8B75E039DB89D98B7DE8F3A67505FF4DE47455FF4DEC8B55DC0155E0395DEC73DF31C08B5DF48B75F88B7DFC89EC5DC210004A3B55EC73EB0155E02955ECEBBA7DDFF75DE48B45ECC745DCFFFFFFFF29D80145E085D274A24A31C03B55EC73C32955E02955ECEB928B4DF0294DE08B45E040EBAF")
  359.         EndIf
  360.         $CodeBufferPtr = __BinaryCodeBufferAlloc($Code)
  361.     EndIf
  362.  
  363.     $Binary = Binary($Binary)
  364.     $Search = Binary($Search)
  365.  
  366.     Local $Len1 = BinaryLen($Binary)
  367.     Local $Buffer1 = DllStructCreate("byte[" & $Len1 & "]")
  368.     DllStructSetData($Buffer1, 1, $Binary)
  369.  
  370.     Local $Len2 = BinaryLen($Search)
  371.     Local $Buffer2 = DllStructCreate("byte[" & $Len2 & "]")
  372.     DllStructSetData($Buffer2, 1, $Search)
  373.  
  374.     Local $Var = DllStructCreate("ptr bin1; uint len1; ptr bin2; uint len2;int occur; uint start")
  375.     DllStructSetData($Var, "bin1", DllStructGetPtr($Buffer1))
  376.     DllStructSetData($Var, "bin2", DllStructGetPtr($Buffer2))
  377.     DllStructSetData($Var, "len1", $Len1)
  378.     DllStructSetData($Var, "len2", $Len2)
  379.     DllStructSetData($Var, "occur", $Occur)
  380.     DllStructSetData($Var, "start", $Start)
  381.  
  382.     Local $Ret = DllCall($__Binary_User32Dll, "uint", "CallWindowProc", "ptr", $CodeBufferPtr, _
  383.                                                                         "ptr", DllStructGetPtr($Var), _
  384.                                                                         "int", 0, _
  385.                                                                         "int", 0, _
  386.                                                                         "int", 0)
  387.     Return $Ret[0]
  388. EndFunc
  389.  
  390. Func _BinaryReplace($Binary, $Search, $Replace, $Occur = 0)
  391.     Static $ReAlloc = DllCallbackRegister("__Binary_Realloc", "ptr:cdecl", "ptr;uint")
  392.     Static $ReAllocPtr = DllCallbackGetPtr($ReAlloc)
  393.     Static $CodeBufferPtr
  394.     If Not $CodeBufferPtr Then
  395.         Local $Code
  396.         If @AutoItX64 Then
  397.             $Code = Binary("0x41574531FF415641554154555756534883EC688B6918488B41204C898424C000000048899424B8000000448B592C448B412885ED48894424484C8B6110448B71084C8B2975144883C4684C89F85B5E5F5D415C415D415E415FC34585DBC744245C000000000F88DB0100004139E84489F276724589F24D89EFC74424400000000089EA4439D5774E4489D34C89F8EB0B83EB0139DD773F4883C0014839D24889C64C89E74889D1F3A675E54885C07426834424400144395C2440741289E94429F98D040189C14129C24901CFEBB58B74244085F674E64489C229EA0FAF542440418D54161031C9448944243844895C242841FFD1448B4424384531D24885C04989C74989C189EB448B5C24284589C04C894424400F842CFFFFFF48894424504589D74439F50F87940000004489F24C89E8EB0F83EA0139D50F87810000004883C0014839DB4889C64C89E74889D9F3A675E14885C0746889C74C89EA4C89C94429EF44895C24284C894C243089FE01EF4183C7014989F04129FEE8560100004C8B4C24304C8B442440488B542448498D34314889F1E83B010000448B5C24284C8B4C244089F84901C54539DF4E8D0C0E0F856CFFFFFF4585FF0F8463FFFFFF4589F64589FA4C89C94D89F04C89EA4C8B7C24504C894C24304489542438E8F30000004C8B4C24308B5C245C488B8C24C0000000448B542438488B8424B80000004D01F14529F985DB4489094489100F8432FEFFFF8B114C89F8498D5417FF4939D70F831FFEFFFF0FB60A32088808320A880A4883EA0130084883C0014839D072E6E900FEFFFF4489F241F7DB4C89E8498D5415FF4939D5731A0FB60A32088808320A880A4883EA0130084883C0014839D072E689EA4C89E0498D5414FF4939D4731A0FB60A32088808320A880A4883EA0130084883C0014839D072E6488B4424484489C2488D5410FF4839D0731A0FB60A32088808320A880A4883EA0130084883C0014839D072E6C744245C01000000E996FDFFFF56574889CF4889D64C89C1FCF3A45F5EC3")
  398.         Else
  399.             $Code = Binary("0x5557565383EC5C8B442470C744242C000000008B50188B580C8B48148B7010895424408B68088B500485DB8B00894C243C897424488954243089442434750E8B44242C83C45C5B5E5F5DC210008B742440C744244C0000000085F60F88D6010000395C243C8B4424300F8683000000894424288B442434896C242CC74424380000000089C53B5C2428775031C0EB0D8B54242883C00129C239D3773F8B7C242C8D74050039DB8974244489D9F3A675DF8B54244485D2742383442438018B4C2440394C2438740C29EA01DA01D529542428EBB28B4C243885C974EC8B44243C8B7424308B6C242C29D80FAF4424388D44061089442404C7042400000000FF54247CC74424440000000085C08944242C894424380F8426FFFFFF3B5C24300F87A40000008B4424308B4C243401C1894C2428EB0B83E80139C30F87890000008B74242889EF89D929C639DB8974241CF3A675E18B54241C85D2746D89D68B4424348B5424382B74243483442444018914248974240889442404E8320100008B7C24388B4C243C8B44244801F701DE893C24894C240889442404E8120100008B542440037C243C017424342974243039542444897C24380F855EFFFFFF8B44244485C00F8452FFFFFF8B7424308B4424348B5424388974240889442404891424E8CC0000008B4424388B4C24788B7C244C01F08B7424442B44242C85FF89018B44247489300F8436FEFFFF8B44242C8B118D5410FF39D00F8324FEFFFF0FB60A32088808320A880A83EA01300883C00139D072E9E908FEFFFF8D5410FFF75C244039D073170FB60A32088808320A880A83EA01300883C00139D072E98D541DFF89E839D573170FB60A32088808320A880A83EA01300883C00139D072E98B4424488B74243C8D5430FF39D073170FB60A32088808320A880A83EA01300883C00139D072E9C744244C01000000E9B2FDFFFF56578B7C240C8B7424108B4C241485C9742FFC83F9087227F7C7010000007402A449F7C702000000740566A583E90289CAC1E902F3A589D183E103F3A4EB02F3A45F5EC3")
  400.         EndIf
  401.         $CodeBufferPtr = __BinaryCodeBufferAlloc($Code)
  402.     EndIf
  403.  
  404.     $Binary = Binary($Binary)
  405.     $Search = Binary($Search)
  406.     $Replace = Binary($Replace)
  407.  
  408.     Local $BinaryLen = BinaryLen($Binary)
  409.     Local $SearchLen = BinaryLen($Search)
  410.     Local $ReplaceLen = BinaryLen($Replace)
  411.  
  412.     Local $Len1 = BinaryLen($Binary)
  413.     Local $Buffer1 = DllStructCreate("byte[" & $Len1 & "]")
  414.     DllStructSetData($Buffer1, 1, $Binary)
  415.  
  416.     Local $Len2 = BinaryLen($Search)
  417.     Local $Buffer2 = DllStructCreate("byte[" & $Len2 & "]")
  418.     DllStructSetData($Buffer2, 1, $Search)
  419.  
  420.     Local $Len3 = BinaryLen($Replace)
  421.     Local $Buffer3 = DllStructCreate("byte[" & $Len3 & "]")
  422.     DllStructSetData($Buffer3, 1, $Replace)
  423.  
  424.     Local $Var = DllStructCreate("ptr bin1; uint len1; ptr bin2; uint len2; ptr bin3; uint len3; int occur; ")
  425.     DllStructSetData($Var, "bin1", DllStructGetPtr($Buffer1))
  426.     DllStructSetData($Var, "bin2", DllStructGetPtr($Buffer2))
  427.     DllStructSetData($Var, "bin3", DllStructGetPtr($Buffer3))
  428.     DllStructSetData($Var, "len1", $Len1)
  429.     DllStructSetData($Var, "len2", $Len2)
  430.     DllStructSetData($Var, "len3", $Len3)
  431.     DllStructSetData($Var, "occur", $Occur)
  432.  
  433.     Local $Ret = DllCall($__Binary_User32Dll, "uint", "CallWindowProc", "ptr", $CodeBufferPtr, _
  434.                                                                         "ptr", DllStructGetPtr($Var), _
  435.                                                                         "uint*", 0, _
  436.                                                                         "uint*", 0, _
  437.                                                                         "ptr", $ReAllocPtr)
  438.  
  439.     Local $Result, $Count
  440.     If $Ret[0] Then
  441.         Local $Buffer = DllStructCreate("byte[" & $Ret[4] & "]", $Ret[0])
  442.         $Result = DllStructGetData($Buffer, 1)
  443.         $Count = $Ret[3]
  444.         __Binary_Free($Ret[0])
  445.     Else
  446.         $Result = DllStructGetData($Buffer1, 1)
  447.         $Count = 0
  448.     EndIf
  449.  
  450.     Return SetExtended($Count, $Result)
  451. EndFunc
  452.  
  453. Func _BinarySplit($Binary, $Search)
  454.     $Binary = Binary($Binary)
  455.     $Search = Binary($Search)
  456.  
  457.     Local $SearchLen = BinaryLen($Search)
  458.     Local $Array[1] = [0]
  459.     Do
  460.         Local $Pos = _BinaryInBin($Binary, $Search)
  461.  
  462.         $Array[0] += 1
  463.         ReDim $Array[$Array[0] + 1]
  464.         $Array[$Array[0]] = BinaryMid($Binary, 1, $Pos - 1)
  465.  
  466.         $Binary = BinaryMid($Binary, $Pos + $SearchLen)
  467.     Until $Pos = 0
  468.  
  469.     Return $Array
  470. EndFunc
  471.  
  472. Func _BinaryRandom($Length, $Start = 0, $To = 255, $Seed = 0)
  473.     Static $CodeBufferPtr
  474.     If Not $CodeBufferPtr Then
  475.         Local $Code
  476.         If @AutoItX64 Then
  477.             $Code = Binary("0x41574156415541545531ED5756534881ECF80900004585C948C78424D009000000000000745E4C8D54241044894C2410B801000000498D72044489CBC1EB1E4431CB4469CB6589076C468D0C0883C00144890E4883C6043D7002000075DB498D42044C899424D00900004C89D548898424D8090000498D823406000048898424E00900004589C341C1E8084538C376034587D885D20F84730100004C8D542410450FB6C0410FB6C34183C00183EA014129C0498D8238060000488D5C1101498D7204498DBA340600004D8D8AC00900004889442408EB4789C2C1EA0B31C289D0C1E0072580562C9D31D031D289C5C1E50F81E50000C6EF31C589E8C1E81231E841F7F0418D141388114883C1014839D90F84F8000000488BAC24D00900004885ED0F84870000004C8BBC24E00900004C8BA424D80900004D8D6F044C89E0448B308B55004C89A424D00900004983C4044C89AC24E00900004C89A424D80900004489F081E2000000804183E60125FFFFFF7F41F7DE09D04181E6DFB00899D1E84431F04133074D39CD89450074164D39CC0F8540FFFFFF4C899424D8090000E933FFFFFF4C899424E0090000EBE00F3131D04989F4BD010000008944241089C2C1EA1E31C269C26589076C01E883C501418904244983C40481FD7002000075DE4C899424D00900004889B424D80900004889F04889BC24E00900004C8B6C24084C89D54989FF4989F4E930FFFFFF4881C4F80900005B5E5F5D415C415D415E415FC3")
  478.         Else
  479.             $Code = Binary("0x5531D257565381ECE40900008BB424040A00008B9C24000A0000C78424D80900000000000085F6744C89742418B8010000008D4C241889F2C1EA1E31F269F26589076C8D343089348183C0013D7002000075E38D44241C89CA898424DC0900008D84244C060000898C24D8090000898424E0090000885C2413C1EB08385C2413760A0FB644241393884424138B8424FC09000085C00F84690100000FB6DB0FB644241383C3018DB424D8090000895C240C8D4C241831DB2944240C893424EB5289C2C1EA0B31C289D0C1E0072580562C9D31D031D289C6C1E60F81E60000C6EF31C689F0C1E81231F0F774240C8B8424F80900000254241388141883C301399C24FC0900000F86F90000008B9424D809000085D20F84850000008BAC24E00900008BBC24DC0900008D750489F8897424048B008B3289BC24D809000083C70489BC24DC0900008944240825FFFFFF7F81E60000008009F08B742408D1E883E601F7DE81E6DFB0089931F08B342433450089028B54240439F2899424E009000074153B3C240F8536FFFFFF898C24DC090000E92AFFFFFF898C24E0090000EBE20F3131D0BE010000008944241889C2C1EA1E31C269C26589076C01F08904B183C60181FE7002000075E38D44241C8D94244C06000089C78DB42450060000899424E00900008DAC244C06000089CA898C24D8090000898424DC09000089742404E92DFFFFFF81C4E40900005B5E5F5DC21000")
  480.         EndIf
  481.         $CodeBufferPtr = __BinaryCodeBufferAlloc($Code)
  482.     EndIf
  483.  
  484.     If $Length = 0 Then Return Binary("")
  485.  
  486.     Local $Buffer = DllStructCreate("byte[" & $Length & "]")
  487.     Local $Ret = DllCall($__Binary_User32Dll, "uint", "CallWindowProc", "ptr", $CodeBufferPtr, _
  488.                                                                         "ptr", DllStructGetPtr($Buffer), _
  489.                                                                         "uint", $Length, _
  490.                                                                         "word", $To * 256 + $Start, _
  491.                                                                         "uint", $Seed)
  492.     Return DllStructGetData($Buffer, 1)
  493. EndFunc
  494.  
  495. Func _BinaryRight($Binary, $Count)
  496.     Return BinaryMid($Binary, BinaryLen($Binary) - $Count + 1)
  497. EndFunc
  498.  
  499. Func _BinaryLeft($Binary, $Count)
  500.     Return BinaryMid($Binary, 1, $Count)
  501. EndFunc
  502.  
  503. Func _BinaryTrimLeft($Binary, $Count)
  504.     Return BinaryMid($Binary, $Count + 1)
  505. EndFunc
  506.  
  507. Func _BinaryTrimRight($Binary, $Count)
  508.     Return BinaryMid($Binary, 1, BinaryLen($Binary) - $Count)
  509. EndFunc
  510.  
  511. Func _BinaryToInt16($Binary)
  512.     Return BitAND(Int(Binary($Binary)), 0xFFFF)
  513. EndFunc
  514.  
  515. Func _BinaryFromInt16($Value)
  516.     Return _BinaryLeft(Binary(BitAND($Value, 0xFFFF)), 2)
  517. EndFunc
  518.  
  519. Func _BinaryToInt32($Binary)
  520.     Return BitAND(Int(Binary($Binary)), 0xFFFFFFFF)
  521. EndFunc
  522.  
  523. Func _BinaryFromInt32($Value)
  524.     Return Binary(BitAND($Value, 0xFFFFFFFF))
  525. EndFunc
  526.  
  527. Func _BinaryToInt64($Binary)
  528.     Local $Buffer = DllStructCreate("byte[8]")
  529.     DllStructSetData($Buffer, 1, Binary($Binary))
  530.  
  531.     Return DllStructGetData(DllStructCreate("int64", DllStructGetPtr($Buffer)), 1)
  532. EndFunc
  533.  
  534. Func _BinaryFromInt64($Value)
  535.     Local $Buffer = DllStructCreate("int64")
  536.     DllStructSetData($Buffer, 1, $Value)
  537.  
  538.     Return DllStructGetData(DllStructCreate("byte[8]", DllStructGetPtr($Buffer)), 1)
  539. EndFunc
  540.  
  541. Func _BinaryToDouble($Binary)
  542.     Local $Buffer = DllStructCreate("byte[8]")
  543.     DllStructSetData($Buffer, 1, Binary($Binary))
  544.  
  545.     Return DllStructGetData(DllStructCreate("double", DllStructGetPtr($Buffer)), 1)
  546. EndFunc
  547.  
  548. Func _BinaryFromDouble($Value)
  549.     Local $Buffer = DllStructCreate("double")
  550.     DllStructSetData($Buffer, 1, $Value)
  551.  
  552.     Return DllStructGetData(DllStructCreate("byte[8]", DllStructGetPtr($Buffer)), 1)
  553. EndFunc
  554.  
  555. Func _BinaryToMemory($Binary, $Ptr)
  556.     Local $Buffer = DllStructCreate("byte[" & BinaryLen($Binary) & "]", $Ptr)
  557.     DllStructSetData($Buffer, 1, $Binary)
  558. EndFunc
  559.  
  560. Func _BinaryFromMemory($Ptr, $Size = 1)
  561.     Local $Buffer = DllStructCreate("byte[" & $Size & "]", $Ptr)
  562.     Return DllStructGetData($Buffer, 1)
  563. EndFunc
  564.  
  565. Func _BinaryToDLLStruct($Binary)
  566.     Local $Buffer = DllStructCreate("byte[" & BinaryLen($Binary) & "]")
  567.     DllStructSetData($Buffer, 1, $Binary)
  568.     Return $Buffer
  569. EndFunc
  570.  
  571. Func _BinaryFromDLLStruct(ByRef $DLLStruct)
  572.     Local $Buffer = DllStructCreate("byte[" & DllStructGetSize($DLLStruct) & "]", DllStructGetPtr($DLLStruct))
  573.     Return DllStructGetData($Buffer, 1)
  574. EndFunc
  575.  
  576. Func _BinaryFillDLLStruct($Binary, ByRef $DLLStruct)
  577.     Local $Buffer = DllStructCreate("byte[" & DllStructGetSize($DLLStruct) & "]", DllStructGetPtr($DLLStruct))
  578.     DllStructSetData($Buffer, 1, $Binary)
  579. EndFunc
  580.  
  581. Func _BitShift64($Value, $Shift)
  582.     Return _BinaryToInt64(_BinaryShift(_BinaryFromInt64($Value), $Shift))
  583. EndFunc
  584.  
  585. Func _BitRotate64($Value, $Shift)
  586.     Return _BinaryToInt64(_BinaryRotate(_BinaryFromInt64($Value), $Shift))
  587. EndFunc
  588.  
  589. Func _BitNOT64($Value)
  590.     Return _BinaryToInt64(_BinaryNOT(_BinaryFromInt64($Value)))
  591. EndFunc
  592.  
  593. Func _BitXOR64($Value1, $Value2, $Value3 = 0, $Value4 = 0, $Value5 = 0, $Value6 = 0, $Value7 = 0, $Value8 = 0, $Value9 = 0, $Value10 = 0, $Value11 = 0, $Value12 = 0, $Value13 = 0, $Value14 = 0, $Value15 = 0, $Value16 = 0, $Value17 = 0, $Value18 = 0, $Value19 = 0, $Value20 = 0)
  594.     Local $Ret = _BinaryFromInt64($Value1)
  595.     For $i = 2 To @NumParams
  596.         $Ret = _BinaryXOR($Ret, _BinaryFromInt64(Eval("Value" & $i)))
  597.     Next
  598.     Return _BinaryToInt64($Ret)
  599. EndFunc
  600.  
  601. Func _BitAND64($Value1, $Value2, $Value3 = 0, $Value4 = 0, $Value5 = 0, $Value6 = 0, $Value7 = 0, $Value8 = 0, $Value9 = 0, $Value10 = 0, $Value11 = 0, $Value12 = 0, $Value13 = 0, $Value14 = 0, $Value15 = 0, $Value16 = 0, $Value17 = 0, $Value18 = 0, $Value19 = 0, $Value20 = 0)
  602.     Local $Ret = _BinaryFromInt64($Value1)
  603.     For $i = 2 To @NumParams
  604.         $Ret = _BinaryAND($Ret, _BinaryFromInt64(Eval("Value" & $i)))
  605.     Next
  606.     Return _BinaryToInt64($Ret)
  607. EndFunc
  608.  
  609. Func _BitOR64($Value1, $Value2, $Value3 = 0, $Value4 = 0, $Value5 = 0, $Value6 = 0, $Value7 = 0, $Value8 = 0, $Value9 = 0, $Value10 = 0, $Value11 = 0, $Value12 = 0, $Value13 = 0, $Value14 = 0, $Value15 = 0, $Value16 = 0, $Value17 = 0, $Value18 = 0, $Value19 = 0, $Value20 = 0)
  610.     Local $Ret = _BinaryFromInt64($Value1)
  611.     For $i = 2 To @NumParams
  612.         $Ret = _BinaryOR($Ret, _BinaryFromInt64(Eval("Value" & $i)))
  613.     Next
  614.     Return _BinaryToInt64($Ret)
  615. EndFunc
  616.  
  617. Func _Hex64($Value, $Len = 16)
  618.     Local $Binary = _BinaryReverse(_BinaryFromInt64($Value))
  619.     Return StringRight(StringTrimLeft($Binary, 2), $Len)
  620. EndFunc
  621.  
  622. Func _Dec64($Hex)
  623.     If Mod(StringLen($Hex), 2) = 1 Then $Hex = "0" & $Hex
  624.     Return _BinaryToInt64(_BinaryReverse("0x" & $Hex))
  625. EndFunc
  626.