Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/01/2020 in all areas

  1. pixelsearch

    CSV file editor

    @jugador : that's great ! It will please mikell too, because his first wish was that people could reuse, for their personal need, the script core (901f, found at the very beginning of 1st post). That's exactly what you did
    2 points
  2. jugador

    CSV file editor

    @pixelsearch was in need of "Edit Listview" so modified your code slight bit using flag & it work Sample code #include <GUIConstantsEx.au3> #include <GuiEdit.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> ; ############# Global $g_hEdit, $g_sSubItemText_Old = "" Global $g_iItem = -1, $g_iSubItem = -1, $g_iItemEdit = -1, $g_iSubItemEdit = -1 Global $hGUI = GUICreate("Wandering through ListView (901f)", 460, 500) Global $idListView = GUICtrlCreateListView _ (" Col 0 | Col 1| Col 2| Col 3", 15, 60, 430, 400) Global $hListView = GuiCtrlGetHandle($idListView) For $iRow = 0 To 99 $sRow = StringFormat("%2s", $iRow) GUICtrlCreateListViewItem( _ "Row " & $sRow & " / Col 0 |" & _ "Row " & $sRow & " / Col 1 |" & _ "Row " & $sRow & " / Col 2 |" & _ "Row " & $sRow & " / Col 3", $idListView) Next Global $g_iColumnCount = _GUICtrlListView_GetColumnCount($idListView) -1 ; ############# ; ############# Local $Id_ButtonA = GUICtrlCreateButton("Edit", 10, 5, 40, 22) Local $k_Flag = 0 Local $idDummy_Enter = GUICtrlCreateDummy() Local $idDummy_Esc = GUICtrlCreateDummy() Local $aAccelKeys[2][2] = [["{ENTER}", $idDummy_Enter], ["{ESC}", $idDummy_Esc]] GUISetAccelerators($aAccelKeys) ; ############# GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE GUIDelete($hGUI) Exit Case $Id_ButtonA If $k_Flag = 0 Then $k_Flag = 1 Start_Edit() EndIf Case $idDummy_Esc If $k_Flag = 1 Then $k_Flag = 0 If $g_iItemEdit > -1 Then End_Edit(0) EndIf Case $idDummy_Enter If $k_Flag = 1 Then $k_Flag = 0 If $g_iItemEdit > -1 Then End_Edit(1) EndIf EndSwitch WEnd ;===== Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $tNMHDR, $hWndFrom, $iIDFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iCode = DllStructGetData($tNMHDR, "Code") Static $bMouseDown = False, $bNotXP = Not (@OSVersion = "WIN_XP") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $lParam) Local $iDrawStage = DllStructGetData($tCustDraw, "dwDrawStage") If $iDrawStage = $CDDS_PREPAINT Then Return $CDRF_NOTIFYITEMDRAW If $iDrawStage = $CDDS_ITEMPREPAINT Then Return $CDRF_NOTIFYSUBITEMDRAW Local $iItem = DllStructGetData($tCustDraw, "dwItemSpec") Local $iSubItem = DllStructGetData($tCustDraw, "iSubItem") Local $iColor = 0xFF000000 ; this is $CLR_DEFAULT in ColorConstants.au3 If $iItem = $g_iItem And $iSubItem = $g_iSubItem Then $iColor = 0xFFFFC0 ; light blue for 1 subitem (BGR) EndIf DllStructSetData($tCustDraw, "clrTextBk", $iColor) Return $CDRF_NEWFONT Case $LVN_KEYDOWN If $bMouseDown Or $g_iItem = -1 Then Return 1 ; don't process Local $tInfo = DllStructCreate($tagNMLVKEYDOWN, $lParam) Local $iVK = DllStructGetData($tInfo, "VKey") Switch $iVK Case $VK_RIGHT If $g_iSubItem < $g_iColumnCount Then $g_iSubItem += 1 If $bNotXP Then _GUICtrlListView_RedrawItems($hListview, $g_iItem, $g_iItem) EndIf Case $VK_LEFT If $g_iSubItem > 0 Then $g_iSubItem -= 1 If $bNotXP Then _GUICtrlListView_RedrawItems($hListview, $g_iItem, $g_iItem) EndIf Case $VK_SPACE ; spacebar would select the whole row Return 1 EndSwitch Case $NM_RELEASEDCAPTURE $bMouseDown = True Local $iItemSave = $g_iItem Local $aHit = _GUICtrlListView_SubItemHitTest($hListView) $g_iItem = $aHit[0] $g_iSubItem = $aHit[1] If $g_iItem = -1 And $iItemSave > -1 Then _GUICtrlListView_RedrawItems($hListview, $iItemSave, $iItemSave) EndIf Case $LVN_ITEMCHANGED Local $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam) Local $iNewState = DllStructGetData($tInfo, "NewState") Switch $iNewState Case BitOr($LVIS_FOCUSED, $LVIS_SELECTED) $g_iItem = DllStructGetData($tInfo, "Item") _GUICtrlListView_SetItemSelected($hListview, $g_iItem, False) EndSwitch Case $NM_CLICK, $NM_RCLICK $bMouseDown = False EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY ;===== Func Start_Edit() If $g_iSubItem <> 0 Then $g_aRect = _GUICtrlListView_GetSubItemRect($hListView, $g_iItem, $g_iSubItem) Else ; column 0 needs _GUICtrlListView_GetItemRect() in case it has been dragged elsewhere (LarsJ) $g_aRect = _GUICtrlListView_GetItemRect($hListView, $g_iItem, 2) ; 2 = bounding rectangle of the item text EndIf $g_iItemEdit = $g_iItem $g_iSubItemEdit = $g_iSubItem $g_sSubItemText_Old = _GUICtrlListView_GetItemText($hListView, $g_iItem, $g_iSubItem) $g_hEdit = _GUICtrlEdit_Create($hListView, $g_sSubItemText_Old, $g_aRect[0], $g_aRect[1], $g_aRect[2]-$g_aRect[0], $g_aRect[3]-$g_aRect[1], BitOR($WS_CHILD, $WS_VISIBLE, $ES_AUTOHSCROLL, $ES_LEFT)) _GUICtrlEdit_SetSel($g_hEdit, 0, -1) ; select all text _WinAPI_SetFocus($g_hEdit) EndFunc ;==>Start_Edit ;===== Func End_Edit($iUpdate_Text) Local $sText = (($iUpdate_Text) ? (_GUICtrlEdit_GetText($g_hEdit)) : ($g_sSubItemText_Old)) _GUICtrlListView_SetItemText($hListView, $g_iItemEdit, $sText, $g_iSubItemEdit) _WinAPI_DestroyWindow($g_hEdit) If $g_iItemEdit <> $g_iItem Or $g_iSubItemEdit <> $g_iSubItem Then _GUICtrlListView_RedrawItems($hListView, $g_iItemEdit, $g_iItemEdit) EndIf $g_iItemEdit = -1 ; -1 means no pending edition (+++) EndFunc ;==>End_Edit
    2 points
  3. Hi, I've required a streaming functionality written in plain AutoIt for in-memory streams based on AutoIt's binary data. I did not found it here, so I just wrote it down, feel free to use it. Shame on me if its a duplicate. #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_AU3Check_Parameters=-d -w 3 -w 4 -w 5 -w 6 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; Version 1.0.0 ; _BinaryStream_Create() ; _BinaryStream_Available($aStream) ; _BinaryStream_Clear($aStream) ; _BinaryStream_GetLength($aStream) ; _BinaryStream_SetLength($aStream, $iLength) ; _BinaryStream_GetPosition($aStream) ; _BinaryStream_SetPosition($aStream, $iPosition) ; _BinaryStream_Write($aStream, $bData [, $iLength]) ; _BinaryStream_Read($aStream [, $iLength]) ; _BinaryStream_Peek($aStream [, $iLength]) ; _BinaryStream_ToBinary($aStream [, $iPosition [, $iLength]) ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryStream_Create ; Description ...: Creates a new stream which is represented as a 1 dimensional array with 2 values: ; [0] = The binary data of the stream. ; [1] = The current position of the stream. ; Syntax ........: _BinaryStream_Create([$bData = Default]) ; Parameters ....: $bData - [optional] The initial value of the stream, empty by default. ; Return values .: On success: The stream represented as an array. ; Author ........: Veluxe ; =============================================================================================================================== Func _BinaryStream_Create($bData = Default) Local $aStream[2] = [BinaryMid(Null, 1, 0), 0] If ($bData <> Default) And (BinaryLen($bData) > 0) Then $aStream[0] &= Binary($bData) EndIf Return $aStream EndFunc ;==>_BinaryStream_Create ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryStream_Available ; Description ...: Returns the count of bytes available to read from the current stream position. ; Syntax ........: _BinaryStream_Available(Byref $aStream) ; Parameters ....: $aStream - [in/out] The array that represents the stream which was created by _BinaryStream_Create(). ; Return values .: On success: Returns the count of bytes available to read from the current stream position. ; On error: ; -1 : The passed stream is not a valid array! ; -2 : The passed stream has invalid dimensions, it must be a 1 dimensional array with a length of 2! ; -3 : The current position of the stream is outside the stream data boundaries! ; Author ........: Veluxe ; =============================================================================================================================== Func _BinaryStream_Available(ByRef $aStream) If Not IsArray($aStream) Then Return SetError(-1, Default, -1) If (UBound($aStream, 0) <> 1) Or (UBound($aStream, 1) > 2) Then Return SetError(-2, Default, -2) Local $iStreamLength = BinaryLen($aStream[0]) If ($aStream[1] < 0) Or ($aStream[1] > $iStreamLength) Then Return SetError(-3, Default, -3) ; Broken stream Return $iStreamLength - $aStream[1] EndFunc ;==>_BinaryStream_Available ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryStream_Clear ; Description ...: Clears the specified stream. This will set its length and position to 0. ; Syntax ........: _BinaryStream_Clear(Byref $aStream) ; Parameters ....: $aStream - [in/out] The array that represents the stream which was created by _BinaryStream_Create(). ; Return values .: On success: Returns 1. ; On error: ; -1 : The passed stream is not a valid array! ; -2 : The passed stream has invalid dimensions, it must be a 1 dimensional array with a length of 2! ; Author ........: Veluxe ; =============================================================================================================================== Func _BinaryStream_Clear(ByRef $aStream) If Not IsArray($aStream) Then Return SetError(-1, Default, -1) If (UBound($aStream, 0) <> 1) Or (UBound($aStream, 1) > 2) Then Return SetError(-2, Default, -2) $aStream[0] = BinaryMid(Null, 1, 0) $aStream[1] = 0 Return 1 EndFunc ;==>_BinaryStream_Clear ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryStream_GetLength ; Description ...: Returns the length of the stream in count of bytes. ; Syntax ........: _BinaryStream_GetLength(Byref $aStream) ; Parameters ....: $aStream - [in/out] The array that represents the stream which was created by _BinaryStream_Create(). ; Return values .: On success: Returns the length of the stream in count of bytes. ; On error: ; -1 : The passed stream is not a valid array! ; -2 : The passed stream has invalid dimensions, it must be a 1 dimensional array with a length of 2! ; Author ........: Veluxe ; =============================================================================================================================== Func _BinaryStream_GetLength(ByRef $aStream) If Not IsArray($aStream) Then Return SetError(-1, Default, -1) If (UBound($aStream, 0) <> 1) Or (UBound($aStream, 1) > 2) Then Return SetError(-2, Default, -2) Return BinaryLen($aStream[0]) EndFunc ;==>_BinaryStream_GetLength ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryStream_SetLength ; Description ...: Adjusts the length of the stream to the specified value. If the new length is lower than the previous length ; the stream position will be adjusted to the last byte of the new stream length. If the new stream length is ; greater than the previous length, the stream position will remain to its current value. The stream will get ; bytes of value 00 appended to its end until the length fits the new value. ; If the new length equals the old length the whole stream will remain to its current values. ; Syntax ........: _BinaryStream_SetLength(Byref $aStream, $iLength) ; Parameters ....: $aStream - [in/out] The array that represents the stream which was created by _BinaryStream_Create(). ; $iLength - The new length of the stream. ; Return values .: On success: Returns the new length of the stream in count of bytes. ; On error: ; -1 : The passed stream is not a valid array! ; -2 : The passed stream has invalid dimensions, it must be a 1 dimensional array with a length of 2! ; -3 : The passed length is lower than 0! ; Author ........: Veluxe ; =============================================================================================================================== Func _BinaryStream_SetLength(ByRef $aStream, $iLength) If Not IsArray($aStream) Then Return SetError(-1, Default, -1) If (UBound($aStream, 0) <> 1) Or (UBound($aStream, 1) > 2) Then Return SetError(-2, Default, -2) If $iLength < 0 Then Return SetError(-3, Default, -3) Local $iStreamLength = BinaryLen($aStream[0]) If $iLength > $iStreamLength Then Local $bPadding = BinaryMid(0, 1, 0) Local $iPaddingLength = 0 ; The following code creates a series of 00-bytes ; It will try to append 1 byte, if that fits into the specified length, it will double the 1 byte ... ; then it will retry to append 2 bytes, if that also fits into the length, it will double the 2 bytes ... ; then it will retry to append 4 bytes, if that ... etc. ; It will re-start at 1 byte again when the doubled data does not fit into the final series anymore. ; this will be continued until the series of n-bytes is finally created. While $iStreamLength < $iLength $bPadding = BinaryMid(0, 1, 1) $iPaddingLength = 1 While ($iStreamLength + $iPaddingLength * 2) < $iLength $bPadding &= $bPadding $iPaddingLength *= 2 WEnd $aStream[0] &= $bPadding $iStreamLength += $iPaddingLength WEnd ElseIf $iLength < $iStreamLength Then $aStream[0] = BinaryMid($aStream[0], 1, $iLength) If $aStream[1] > $iLength Then $aStream[1] = $iLength ; If the stream position would be outside the data it ... ; ... will be set to the end position within the new stream data - in any other ... ; ... case the stream position will remain to its value EndIf EndIf Return $iLength EndFunc ;==>_BinaryStream_SetLength ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryStream_GetPosition ; Description ...: Returns the current position of the specified stream. ; Syntax ........: _BinaryStream_GetPosition(Byref $aStream) ; Parameters ....: $aStream - [in/out] The array that represents the stream which was created by _BinaryStream_Create(). ; Return values .: On success: Returns the current position of the specified stream. ; On error: ; -1 : The passed stream is not a valid array! ; -2 : The passed stream has invalid dimensions, it must be a 1 dimensional array with a length of 2! ; Author ........: Veluxe ; =============================================================================================================================== Func _BinaryStream_GetPosition(ByRef $aStream) If Not IsArray($aStream) Then Return SetError(-1, Default, -1) If (UBound($aStream, 0) <> 1) Or (UBound($aStream, 1) > 2) Then Return SetError(-2, Default, -2) Return $aStream[1] EndFunc ;==>_BinaryStream_GetPosition ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryStream_SetPosition ; Description ...: Sets the stream position to the specified value related to an origin. ; Syntax ........: _BinaryStream_SetPosition(Byref $aStream, $iPosition[, $iOrigin = Default]) ; Parameters ....: $aStream - [in/out] The array that represents the stream which was created by _BinaryStream_Create(). ; $iPosition - The position to set the stream to related to the origin. ; $iOrigin - [optional] The origin where to set the position from, valid values are: ; 0 : From the begin of the stream (0) ; 1 : From the current position of the stream ; 2 : From the end of the stream (new position = length - offset) ; The default origin is 0 - from the begin of the stream. ; Return values .: On success: A value greater or equal to 0, representing the new position of the stream. ; On error: ; -1 : The passed stream is not a valid array! ; -2 : The passed stream has invalid dimensions, it must be a 1 dimensional array with a length of 2! ; -3 : The passed position is lower than 0! ; -4 : The passed origin value is invalid! Valid values are: 0, 1 and 2. (see parameter description) ; -5 : The passed position related to the passed origin is resulting in a position outside the stream data! ; Author ........: Veluxe ; =============================================================================================================================== Func _BinaryStream_SetPosition(ByRef $aStream, $iPosition, $iOrigin = Default) If Not IsArray($aStream) Then Return SetError(-1, Default, -1) If (UBound($aStream, 0) <> 1) Or (UBound($aStream, 1) > 2) Then Return SetError(-2, Default, -2) If $iPosition < 0 Then Return SetError(-3, Default, -3) ; Note No max validation here ... ; ... later on the calculated value will be validated against the max If $iOrigin = Default Then $iOrigin = 0 ; The origin is the start of the stream by default ElseIf ($iOrigin < 0) Or ($iOrigin > 2) Then Return SetError(-4, Default, -4) EndIf Local $iNewPosition = -1 Local $iStreamLength = BinaryLen($aStream[0]) Switch Int($iOrigin) Case 2 ; End $iNewPosition = $iStreamLength - $iPosition Case 1 ; Current $iNewPosition = $aStream[1] + $iPosition Case Else ; Begin $iNewPosition = $iPosition EndSwitch If $iNewPosition > $iStreamLength Then Return SetError(-5, Default, -5) $aStream[1] = $iNewPosition Return $aStream[1] EndFunc ;==>_BinaryStream_SetPosition ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryStream_Write ; Description ...: Writes the specified binary data to the current stream position. ; Syntax ........: _BinaryStream_Write(Byref $aStream, $bData[, $iLength = Default]) ; Parameters ....: $aStream - [in/out] The array that represents the stream which was created by _BinaryStream_Create(). ; $bData - The binary data to write to the stream. ; $iLength - [optional] The length of the passed binary data to write to the stream. (The whole data ; by default) ; Return values .: On success: Returns the new position of the stream after the bytes were written. ; On error: ; -1 : The passed stream is not a valid array! ; -2 : The passed stream has invalid dimensions, it must be a 1 dimensional array with a length of 2! ; -3 : The current position of the stream is outside the stream data boundaries! ; Author ........: Veluxe ; =============================================================================================================================== Func _BinaryStream_Write(ByRef $aStream, $bData, $iLength = Default) If Not IsArray($aStream) Then Return SetError(-1, Default, -1) If (UBound($aStream, 0) <> 1) Or (UBound($aStream, 1) > 2) Then Return SetError(-2, Default, -2) Local $iStreamLength = BinaryLen($aStream[0]) ; To avoid further BinaryLen() calls If ($aStream[1] < 0) Or ($aStream[1] > $iStreamLength) Then Return SetError(-3, Default, -3) ; Broken stream Local $iDataLength = BinaryLen($bData) If $iLength = Default Then $iLength = $iDataLength ; Write the whole input data ElseIf ($iLength <= 0) Or ($iDataLength <= 0) Or ($iLength > $iDataLength) Then Return SetError(-4, Default, -4) ; The length or the length of the input data is 0 ... ; ... or the length exceeds the length of the input data EndIf Local $bNewStreamData If $aStream[1] = $iStreamLength Then $bNewStreamData = $aStream[1] Else $bNewStreamData = BinaryMid($aStream[0], 1, $aStream[1]) EndIf ; The user must already pass binary to avoid unexpected serialization! ; See parameters notes. If $iLength = $iDataLength Then $bNewStreamData &= Binary($bData) Else $bNewStreamData &= BinaryMid($bData, 1, $iLength) EndIf Local $iTempLength = BinaryLen($bNewStreamData) If $iStreamLength > $iTempLength Then $bNewStreamData &= BinaryMid($aStream[0], ($iTempLength + 1)) EndIf $aStream[0] = $bNewStreamData $aStream[1] += $iLength Return $aStream[1] EndFunc ;==>_BinaryStream_Write ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryStream_Read ; Description ...: Reads a specified amount of bytes from the given stream and increments the stream position. ; Syntax ........: _BinaryStream_Read(Byref $aStream[, $iLength = Default]) ; Parameters ....: $aStream - [in/out] The array that represents the stream which was created by _BinaryStream_Create(). ; $iLength - [optional] an integer value. Default is Default. ; Return values .: On success: The bytes that have been read from the stream as binary. ; On error: ; -1 : The passed stream is not an array. ; -2 : The dimensions of the passed stream array do not represent a valid stream. ; -3 : The stream position is 0 but the stream already contains data. ; -4 : The stream position is outside the stream boundaries. ; Author ........: Veluxe ; =============================================================================================================================== Func _BinaryStream_Read(ByRef $aStream, $iLength = Default) If Not IsArray($aStream) Then Return SetError(-1, Default, -1) If (UBound($aStream, 0) <> 1) Or (UBound($aStream, 1) > 2) Then Return SetError(-2, Default, -2) Local $iStreamLength = BinaryLen($aStream[0]) ; To avoid multiple BinaryLen() calls If ($aStream[1] < 0) Or ($aStream[1] > $iStreamLength) Then Return SetError(-3, Default, -3) ; Broken stream If $iLength = Default Then $iLength = 1 ; Read 1 byte by default ElseIf ($iLength <= 0) Or ($iLength > ($iStreamLength - $aStream[1])) Then Return SetError(-4, Default, -4) ; The length is 0 or exceeds the length of the stream EndIf Local $bReadData = BinaryMid($aStream[0], ($aStream[1] + 1), $iLength) $aStream[1] += $iLength ; This is the difference to peek Return $bReadData EndFunc ;==>_BinaryStream_Read ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryStream_Peek ; Description ...: Peeks a specified length of bytes from the given stream. The return value behaves like a read, but the stream ; position will not be incremented. ; Syntax ........: _BinaryStream_Peek(Byref $aStream[, $iLength = Default]) ; Parameters ....: $aStream - [in/out] The array that represents the stream which was created by _BinaryStream_Create(). ; $iLength - [optional] The count of bytes to peek from the stream. Default = 1. ; Return values .: On success: The n-bytes read from the current position. ; On error: ; -1 : The passed stream is not a valid array! ; -2 : The passed stream has invalid dimensions, it must be a 1 dimensional array with a length of 2! ; -3 : The current position of the stream is outside the stream data boundaries! ; Author ........: Veluxe ; =============================================================================================================================== Func _BinaryStream_Peek(ByRef $aStream, $iLength = Default) If Not IsArray($aStream) Then Return SetError(-1, Default, -1) If (UBound($aStream, 0) <> 1) Or (UBound($aStream, 1) > 2) Then Return SetError(-2, Default, -2) Local $iStreamLength = BinaryLen($aStream[0]) ; To avoid multiple BinaryLen() calls If ($aStream[1] < 0) Or ($aStream[1] > $iStreamLength) Then Return SetError(-3, Default, -3) ; Broken stream If $iLength = Default Then $iLength = 1 ; Peek 1 byte by default ElseIf ($iLength <= 0) Or ($iLength > ($iStreamLength - $aStream[1])) Then Return SetError(-4, Default, -4) ; The length is 0 or exceeds the length of the stream EndIf Return BinaryMid($aStream[0], ($aStream[1] + 1), $iLength) EndFunc ;==>_BinaryStream_Peek ; #FUNCTION# ==================================================================================================================== ; Name ..........: _BinaryStream_ToBinary ; Description ...: Returns the specified data as binary from the stream. This will not affect the stream position nor the length. ; Syntax ........: _BinaryStream_ToBinary(Byref $aStream[, $iPosition = Default[, $iLength = Default]]) ; Parameters ....: $aStream - [in/out] The array that represents the stream which was created by _BinaryStream_Create(). ; $iPosition - [optional] The start position of the data to return from the stream. (0 by default) ; $iLength - [optional] The length of data to return from the specified position of the stream. (The ; whole data by default) ; Return values .: On success: The data of the specified length from the given position of the stream. ; On error: ; -1 : The passed stream is not a valid array! ; -2 : The passed stream has invalid dimensions, it must be a 1 dimensional array with a length of 2! ; -3 : The specified position is outside the stream boundaries! ; -4 : The passed length of data is not available from the specified position in the stream! ; Author ........: Veluxe ; =============================================================================================================================== Func _BinaryStream_ToBinary(ByRef $aStream, $iPosition = Default, $iLength = Default) If Not IsArray($aStream) Then Return SetError(-1, Default, -1) If (UBound($aStream, 0) <> 1) Or (UBound($aStream, 1) > 2) Then Return SetError(-2, Default, -2) Local $iStreamLength = BinaryLen($aStream[0]) If $iPosition = Default Then $iPosition = 0 ElseIf ($iPosition < 0) Or ($iPosition > $iStreamLength) Then Return SetError(-3, Default, -3) ; The position is out of range EndIf If $iLength = Default Then ; Everything from the specified position until the end of the stream $iLength = $iStreamLength - $iPosition ElseIf ($iLength <= 0) Or ($iLength > ($iStreamLength - $iPosition)) Then Return SetError(-4, Default, -4) ; The length is 0 or exceeds the length of the stream EndIf Return BinaryMid($aStream[0], $iPosition, $iLength) EndFunc ;==>_BinaryStream_ToBinary It can be done faster, and in terms of speed it is not comparable to anything you know of streams from other languages. Cheers BinaryStream.au3
    1 point
  4. TheXman

    StringBetween (SRER)

    Or if you want to stick with StringRegExpReplace, this is one way that'll work: $sOutput = StringRegExpReplace($str, "(?sm).*(^3[.].*^8[.].*?$).*", "\1") It's not pretty, but it will work.
    1 point
  5. Oh, looking at my old code, that couldn't work :), happy new year to everyone! ConsoleWrite((0x0A00 > 0x0601) & @CRLF) Local $__WINVER_GetVersionExW = "0x" & Hex(__WINVER_GetVersionExW(), 4) Local $__WINVER_RtlGetVersion = __WINVER_RtlGetVersion() ConsoleWrite("$__WINVER_GetVersionExW" & @TAB & @TAB & $__WINVER_GetVersionExW & @CRLF) ConsoleWrite("$__WINVER_RtlGetVersion" & @TAB & @TAB & $__WINVER_RtlGetVersion & @CRLF) If $__WINVER_RtlGetVersion >= 0x0604 Then ; Current OS is "Win10 - Technical Preview" or up ConsoleWrite("+" & @TAB & $__WINVER_RtlGetVersion & @CRLF) Else ConsoleWrite("-" & @TAB & $__WINVER_RtlGetVersion & @CRLF) EndIf Func __WINVER_RtlGetVersion() ; GetVersionEx ; https://msdn.microsoft.com/de-de/library/windows/desktop/ms724451(v=vs.85).aspx ; With the release of Windows 8.1, the behavior of the GetVersionEx API has changed in the value it will return for the operating system version. ; The value returned by the GetVersionEx function now depends on how the application is manifested. ; If you don't want to depend on manifests and reply on this deprecated API, use kernel-mode RtlGetVersion: ; https://msdn.microsoft.com/en-us/library/windows/hardware/ff561910(v=vs.85).aspx Local Const $tOSVERSIONINFO = 'dword OSVersionInfoSize;dword MajorVersion;dword MinorVersion;dword BuildNumber;dword PlatformId;wchar CSDVersion[128]' Local Const $tOSVERSIONINFOEX = $tOSVERSIONINFO & ';ushort ServicePackMajor;ushort ServicePackMinor;ushort SuiteMask;byte ProductType;byte Reserved' Local $tOSVI = DllStructCreate($tOSVERSIONINFOEX) DllStructSetData($tOSVI, 1, DllStructGetSize($tOSVI)) Local $Ret = DllCall("ntdll.dll", "int", "RtlGetVersion", "ptr", DllStructGetPtr($tOSVI)) If @error Or $Ret[0] <> 0 Then Return SetError(1, 0, 0) ; RtlGetVersion returns STATUS_SUCCESS = 0 ConsoleWrite("MajorVersion=" & DllStructGetData($tOSVI, "MajorVersion") & @CRLF) ConsoleWrite("MinorVersion=" & DllStructGetData($tOSVI, "MinorVersion") & @CRLF) ; https://docs.microsoft.com/ru-ru/windows/win32/api/winnt/ns-winnt-osversioninfoexa?redirectedfrom=MSDN Switch DllStructGetData($tOSVI, "MajorVersion") Case 10 Switch DllStructGetData($tOSVI, "MinorVersion") Case 0 If BitAND(DllStructGetData($tOSVI, "ProductType"), 0x0000001) Then ; 0x0000001 = VER_NT_WORKSTATION ConsoleWrite("+ Windows 10" & @CRLF) Else ConsoleWrite("+ Windows Server 2016" & @CRLF) EndIf Case Else ConsoleWrite("- No Windows Version determined" & @CRLF) EndSwitch Case 6 Switch DllStructGetData($tOSVI, "MinorVersion") Case 0 If BitAND(DllStructGetData($tOSVI, "ProductType"), 0x0000001) Then ; 0x0000001 = VER_NT_WORKSTATION ConsoleWrite("+ Windows Vista" & @CRLF) Else ConsoleWrite("+ Windows Server 2008" & @CRLF) EndIf Case 1 If BitAND(DllStructGetData($tOSVI, "ProductType"), 0x0000001) Then ; 0x0000001 = VER_NT_WORKSTATION ConsoleWrite("+ Windows 7" & @CRLF) Else ConsoleWrite("+ Windows Server 2008 R2" & @CRLF) EndIf Case 2 If BitAND(DllStructGetData($tOSVI, "ProductType"), 0x0000001) Then ; 0x0000001 = VER_NT_WORKSTATION ConsoleWrite("+ Windows 8" & @CRLF) Else ConsoleWrite("+ Windows Server 2012" & @CRLF) EndIf Case 3 If BitAND(DllStructGetData($tOSVI, "ProductType"), 0x0000001) Then ; 0x0000001 = VER_NT_WORKSTATION ConsoleWrite("+ Windows 8.1" & @CRLF) Else ConsoleWrite("+ Windows Server 2012 R2" & @CRLF) EndIf Case Else ConsoleWrite("- No Windows Version determined" & @CRLF) EndSwitch Case 5 Switch DllStructGetData($tOSVI, "MinorVersion") Case 0 ConsoleWrite("+ Windows 2000" & @CRLF) Case 1 ConsoleWrite("+ Windows XP" & @CRLF) Case 2 Local $aResult = DllCall("user32.dll", "int", "GetSystemMetrics", "int", 89) ; 89 = SM_SERVERR2 If @error Then Return SetError(@error, @extended, 0) If $aResult[0] Then ConsoleWrite("+ Windows Server 2003 R2" & @CRLF) Else If BitAND(DllStructGetData($tOSVI, "SuiteMask"), 0x00008000) Then ; 0x00008000 = VER_SUITE_WH_SERVER ConsoleWrite("+ Windows Home Server" & @CRLF) Else If BitAND(DllStructGetData($tOSVI, "ProductType"), 0x0000001) And StringRight(@OSArch, 2) = "64" Then ; 0x0000001 = VER_NT_WORKSTATION ; @OSArch should deliver the same info as SYSTEM_INFO.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64 ConsoleWrite("+ Windows XP Professional x64 Edition" & @CRLF) Else ConsoleWrite("+ Windows Server 2003" & @CRLF) EndIf EndIf EndIf Case Else ConsoleWrite("- No Windows Version determined" & @CRLF) EndSwitch Case Else ConsoleWrite("- No Windows Version determined" & @CRLF) EndSwitch Return "0x" & Hex(BitOR(BitShift(DllStructGetData($tOSVI, 2), -8), DllStructGetData($tOSVI, 3)), 4) EndFunc ;==>__WINVER_RtlGetVersion Func __WINVER_GetVersionExW() Local $tOSVI = DllStructCreate('dword;dword;dword;dword;dword;wchar[128]') DllStructSetData($tOSVI, 1, DllStructGetSize($tOSVI)) Local $Ret = DllCall('kernel32.dll', 'int', 'GetVersionExW', 'ptr', DllStructGetPtr($tOSVI)) If (@error) Or (Not $Ret[0]) Then Return SetError(1, 0, 0) Return BitOR(BitShift(DllStructGetData($tOSVI, 2), -8), DllStructGetData($tOSVI, 3)) EndFunc ;==>__WINVER_GetVersionExW
    1 point
  6. Kaspersky flagged as virus one program I did. I emailed them and they fixed it for the following updates
    1 point
×
×
  • Create New...