Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/11/2016 in Posts

  1. Nice. Is it only me that always forgets StringSplit can do that?
    2 points
  2. $sString = "John.Smith@Company.com" $aTemp = StringSplit($sString, ".@") MsgBox(0, "Name", $aTemp[1]&$aTemp[2])
    2 points
  3. As you can see you are not the only one
    1 point
  4. Even better than my solution
    1 point
  5. Mat

    AutoIt Language Tools

    Sorry, didn't really have time to document what it does. Given an input file (ExampleScript.au3) of this: Local $a = 1, $b = 2 Local $foo = _MyFunction($a, $b) ConsoleWrite($foo & @LF)It will generate an array that looks like this: This is the syntax tree for the script, using an odd flat tree format documented here: https://github.com/MattDiesel/Ault/wiki/AST-Format The "tree" starts at row 1, with a file. For a file branch, the LEFT value is a comma separated list of child branches, in this case "2,5,8,15" which correspond to rows in the array (these are: the definition of $a, the definition of $b, the definition of $foo and the ConsoleWrite call). If we look at row 15 for example, this is the AST for the function call "ConsoleWrite($foo & @LF)": From this starting point, it would be possible to implement something like Tidy (which is what the messagebox shows afterwards, though a rather naive and not too useful Tidy), or other tools, including executing the code.
    1 point
  6. #include <Misc.au3> Global $hDll = DLLOpen("user32.dll") While (True) If (_IsPressed("01", $hDll)) Then Send("{q}") EndIf WEndDidn't look at the help file to confirm, pretty sure 01 is the left mouse button, double check it though.
    1 point
  7. $ChosenKey = "DEL" $T_INIT = TimerInit() Do Send("{" & $ChosenKey & " Down}") Until TimerDiff($T_INIT) >= 2000 Send("{" & $ChosenKey & " Up}")
    1 point
  8. Melba23

    TreeView to ListView

    incepator, You need to read the Managing Multiple GUIs tutorial in the Wiki. Here is how your code might look if you had read it: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GuiTreeView.au3> Opt("GUIOnEventMode", 1) $Form1 = GUICreate("Form1", 500, 500) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") $cTreeView = GUICtrlCreateTreeView(8, 8, 177, 169) $cTreeView_0 = GUICtrlCreateTreeViewItem("Base1", $cTreeView) GUICtrlCreateTreeViewItem("test1", $cTreeView_0) GUICtrlCreateTreeViewItem("test2", $cTreeView_0) GUICtrlCreateTreeViewItem("test3", $cTreeView_0) $cTreeView_2 = GUICtrlCreateTreeViewItem("Base2", $cTreeView) GUICtrlCreateTreeViewItem("test4", $cTreeView_2) GUICtrlCreateTreeViewItem("test5", $cTreeView_2) GUICtrlSetState($cTreeView_0, $GUI_EXPAND) GUICtrlSetState($cTreeView_2, $GUI_EXPAND) $cListView = GUICtrlCreateListView("Items|Items2", 192, 8, 250, 166) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") $Form2 = GUICreate("Form2", 336, 78, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_WINDOWEDGE),$Form1) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") $Button1 = GUICtrlCreateButton("add", 152, 16, 75, 25) GUICtrlSetOnEvent($Button1, "_Button1_add") $Input1 = GUICtrlCreateInput("exemple", 16, 16, 121, 21) GUISetState(@SW_HIDE, $Form2) ; Hide form2 While 1 Sleep(100) WEnd Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) Local $tStruct = DllStructCreate("hwnd hWndFrom;uint_ptr IDFrom;int Code", $lParam) Local $cCID = DllStructGetData($tStruct, "IDFrom") Local $iCode = DllStructGetData($tStruct, "Code") If $cCID = $cTreeView Then Switch $iCode Case $NM_DBLCLK $hItem = GUICtrlGetHandle(GUICtrlRead($cTreeView)) If _GUICtrlTreeView_Level($cTreeView, $hItem) Then $sItem = GUICtrlRead($cTreeView, 1) If $sItem = "test1" Then GUISetState(@SW_DISABLE, $Form1) ; Disable form1 GUISetState(@SW_SHOW, $Form2) ; Show form2 EndIf EndIf EndSwitch EndIf EndFunc ;==>_WM_NOTIFY Func _Button1_add() GUICtrlCreateListViewItem("test"&"|"&GUICtrlRead($Input1), $cListView) EndFunc ;==>_Button1_add Func SpecialEvents() ; Which GUI sent the event Switch @GUI_WinHandle Case $Form1 Switch @GUI_CtrlId Case $GUI_EVENT_CLOSE ; Check if form2 visible If Not BitAnd(WinGetState($Form2), 2) Then ; $WIN_STATE_VISIBLE ; If not then display MsgBox If MsgBox(260, "Info", "Are you sure you want to exit ?", "", $Form1) = 6 Then ;Yes Exit EndIf EndIf Case $GUI_EVENT_MINIMIZE Case $GUI_EVENT_RESTORE EndSwitch Case $Form2 Switch @GUI_CtrlId Case $GUI_EVENT_CLOSE GUISetState(@SW_ENABLE, $Form1) ; Re-enable form1 GUISetState(@SW_HIDE, $Form2) ; Hide form2 WinActivate($Form1) EndSwitch EndSwitch EndFunc ;==>SpecialEvents M23
    1 point
  9. Melba23

    TreeView to ListView

    incepator, I have to tell you that your words do not mean what you think (at least I hope that is the case), but as I believe it was meant as a compliment I shall reply as such. Glad I could help and comment much appreciated. M23
    1 point
  10. Hi, I have worked on a project for a friend and it needed to retreive some data in UDP packets, it was a challenge because I didn't know anything about that packets, and after few days of work I have managed to do what I wanted. The hardest part was to set a very strict filter for the cpu usage and for the script optimisation, so here is one : ;use filters with _PcapStartCapture ;retreive only tcp packets containing AABBCCDD, at the start of 8 and with a length of 4; like the StringMid func. tcp[8:4] == 0xAABBCCDD ;8th byte from the beginning of the tcp DATA, 4bytes length; always include the 0x to specify you are dealing with hex. And some funcs to split the different data from packets : ;$hCapture is the handle returned by _PcapStartCapture ; #FUNCTION# ==================================================================================================================== ; Name...........: _TCP_Recv ; Description ...: Retreives a TCP Packet and returns its data splitted ; Syntax.........: _TCP_Recv($hCapture, $iInstance = 0, $iTimeOut = 3000) ; Parameters ....: $hCapture - Capture handle ; $iInstance - Instance of the packet to retreive ; $iTimeOut - Timeout ; Return values .: Success - Array containing the packet data ; Failure - -1 (timedout) ; Author ........: FireFox (d3mon) ; Modified.......: ; Remarks .......: ; Related .......: _UDP_Recv ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _TCP_Recv($hCapture, $iInstance = 0, $iTimeOut = 3000) Local $blPacketCaptured = False, $iTimer_Capture, $aPacket, $iPacket $iTimer_Capture = TimerInit() While (TimerDiff($iTimer_Capture) < $iTimeOut Or $iTimeOut = -1) $aPacket = _PcapGetPacket($hCapture) If IsArray($aPacket) Then If $iPacket = $iInstance Then Local $aTCPPacket[21] $aTCPPacket[0] = StringMid($aPacket[3], 3, 12) ;Destination Mac Address $aTCPPacket[1] = StringMid($aPacket[3], 15, 12) ;Source Mac Address $aTCPPacket[2] = StringMid($aPacket[3], 27, 4) ;Type $aTCPPacket[3] = StringMid($aPacket[3], 31, 2) ;Version & Header length $aTCPPacket[4] = StringMid($aPacket[3], 33, 2) ;Differientiated Services Field $aTCPPacket[5] = StringMid($aPacket[3], 35, 4) ;Total Length $aTCPPacket[6] = StringMid($aPacket[3], 39, 4) ;Identification $aTCPPacket[7] = StringMid($aPacket[3], 43, 4) ;Fragment offset $aTCPPacket[8] = StringMid($aPacket[3], 47, 2) ;Time to live $aTCPPacket[9] = StringMid($aPacket[3], 49, 2) ;Protocol $aTCPPacket[10] = StringMid($aPacket[3], 51, 4) ;Header checksum $aTCPPacket[11] = StringMid($aPacket[3], 55, 8) ;Source IP Address $aTCPPacket[12] = StringMid($aPacket[3], 63, 8) ;Destination IP Address $aTCPPacket[13] = StringMid($aPacket[3], 71, 4) ;Source port $aTCPPacket[14] = StringMid($aPacket[3], 75, 4) ;Destination port $aTCPPacket[15] = StringMid($aPacket[3], 79, 8) ;Sequence number $aTCPPacket[16] = StringMid($aPacket[3], 87, 8) ;Acknowledgment number $aTCPPacket[17] = StringMid($aPacket[3], 95, 4) ;Flags $aTCPPacket[18] = StringMid($aPacket[3], 99, 4) ;Window size value $aTCPPacket[19] = StringMid($aPacket[3], 103, 4) ;Checksum ;107 to 110 = NULL data $aTCPPacket[20] = StringTrimLeft($aPacket[3], 110) ;Data Return $aTCPPacket EndIf $iPacket += 1 EndIf Sleep(50) WEnd Return -1 EndFunc ;==>_TCP_Recv ; #FUNCTION# ==================================================================================================================== ; Name...........: _UDP_Recv ; Description ...: Retreives an UDP Packet and returns its data splitted ; Syntax.........: _UDP_Recv($hCapture, $iInstance = 0, $iTimeOut = 3000) ; Parameters ....: $hCapture - Capture handle ; $iInstance - Instance of the packet to retreive ; $iTimeOut - Timeout ; Return values .: Success - Array containing the packet data ; Failure - -1 (timedout) ; Author ........: FireFox (d3mon) ; Modified.......: ; Remarks .......: ; Related .......: _TCP_Recv ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _UDP_Recv($hCapture, $iInstance = 0, $iTimeOut = 3000) Local $blPacketCaptured = False, $iTimer_Capture, $aPacket, $iPacket $iTimer_Capture = TimerInit() While (TimerDiff($iTimer_Capture) < $iTimeOut Or $iTimeOut = -1) $aPacket = _PcapGetPacket($hCapture) If IsArray($aPacket) Then If $iPacket = $iInstance Then Local $aUDPPacket[18] $aUDPPacket[0] = StringMid($aPacket[3], 3, 12) ;Source Mac Address $aUDPPacket[1] = StringMid($aPacket[3], 15, 12) ;Destination Mac Address $aUDPPacket[2] = StringMid($aPacket[3], 27, 4) ;Type $aUDPPacket[3] = StringMid($aPacket[3], 31, 2) ;Version & Header length $aUDPPacket[4] = StringMid($aPacket[3], 33, 2) ;Differientiated Services Field $aUDPPacket[5] = StringMid($aPacket[3], 35, 4) ;Total Length $aUDPPacket[6] = StringMid($aPacket[3], 39, 4) ;Identification $aUDPPacket[7] = StringMid($aPacket[3], 43, 4) ;Fragment offset $aUDPPacket[8] = StringMid($aPacket[3], 47, 2) ;Time to live $aUDPPacket[9] = StringMid($aPacket[3], 49, 2) ;Protocol $aUDPPacket[10] = StringMid($aPacket[3], 51, 4) ;Header checksum $aUDPPacket[11] = StringMid($aPacket[3], 55, 8) ;Source IP Address $aUDPPacket[12] = StringMid($aPacket[3], 63, 8) ;Destination IP Address $aUDPPacket[13] = StringMid($aPacket[3], 71, 4) ;Source port $aUDPPacket[14] = StringMid($aPacket[3], 75, 4) ;Destination port $aUDPPacket[15] = StringMid($aPacket[3], 79, 4) ;Length $aUDPPacket[16] = StringMid($aPacket[3], 83, 4) ;Checksum $aUDPPacket[17] = StringTrimLeft($aPacket[3], 86) ;Data Return $aUDPPacket EndIf $iPacket += 1 EndIf Sleep(50) WEnd Return -1 EndFunc ;==>_UDP_Recv ;for example convert the packet's source/dest IP Address to text ; #FUNCTION# ==================================================================================================================== ; Name...........: _HexIPAddressToText ; Description ...: Converts Hex IP Adress to text ; Syntax.........: _HexIPAddressToText($vhexIPAddress) ; Parameters ....: $vIPAddress - IP Address v4 (string, int) ; Return values .: Success - Converted IP Address ; Author ........: FireFox (d3mon) ; Modified.......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _HexIPAddressToText($vhexIPAddress) Local $sIPAddress For $iOffset = 1 To 8 Step 2 $sIPAddress &= Dec(StringMid($vhexIPAddress, $iOffset, 2)) & "." Next Return StringTrimRight($sIPAddress, 1) EndFunc ;==>_UDP_DecodeIPAddress Ops, almost forgot the Winpcap UDF available here : http://opensource.grisambre.net/pcapau3/ PS : If you find this helpful, please "like"/rate this post. Enjoy
    1 point
×
×
  • Create New...