Jump to content

TheBrainiac

Members
  • Posts

    14
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

TheBrainiac's Achievements

  1. Ah, so it starts measuring CPU load and waits a second to get an average value. That explains the one second delay. Now this makes me wonder why it seemed to run fine in the past. Thank you!
  2. As water pointed out, if you want to make sure the executable file is found, you have to use the full file path. OS internal programs and ones in the same directory as yours can be found using only the file name, because the OS has specific shortcuts in place to make finding them easier, and because of relative file paths, which are a feature to let you easily navigate the directory of your program without knowing its absolute location in the directory tree.
  3. The original question seems innocent enough. I'll have a stab at it: If I'm not mistaken, you have two sets of functions that you'd like to merge into the same script, and you want one hotkey to run both registered functions, i.e. when you press F5, the script should run both Starts() functions you wrote. As far as I'm aware, a key combination can only be bound to one function at a time, even across multiple scripts. The easiest solution is to merge both function bodies into one: Func Starts () While 1 Send("aaaa") Sleep(300) WEnd While 1 Send("bbbb") Sleep(500) WEnd EndFunc or bind the hotkey to a new function that calls the original ones: HotKeySet("{F5}", "Starts") Func Starts() Starts1() Starts2() EndFunc Func Starts1() While 1 Send("aaaa") Sleep(300) WEnd EndFunc Func Starts2() While 1 Send("bbbb") Sleep(500) WEnd EndFunc(Of course you need exit conditions, but we're only talking examples here.) If you want both functions to be executed at the same time, you will have to either interweave the code so that the two functions proceed in an alternating fashion: While 1 Send("a") Sleep(300) Send("b") Sleep(500) WEnd(I call it 'pseudo-multithreading') Or stick to two scripts, because AutoIt does not feature true multithreading. Hope this helps! Edit: Looking at your older post water mentioned, it looks like you don't really understand program flow yet. You cannot simply put two While 1 - WEnd loops after each other. Your script will get stuck in the first loop, because "While 1" translates to "Do this until the end of forever". Furthermore, "Duplicate line" means you're trying to define two functions with the same name. This confuses the scripting engine, because it's like giving it two recipes for pie and then telling it to "make pie". It cannot decide which one to use. You need to give the two versions of your function two different names (Starts1 and Starts2), even at the cost of breaking the "symmetry" of your scripts.
  4. I'm using WMI to poll my system's CPU load: $objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2") $cpu = 0 While 1 $init = TimerInit() $colItems = $objWMIService.ExecQuery("SELECT LoadPercentage FROM Win32_Processor", "WQL", 0x30) For $objItem In $colItems $cpu = $objItem.LoadPercentage Next ConsoleWrite($cpu & "%" & @CRLF) ConsoleWrite(TimerDiff($init) & @CRLF) WEnd The For-loop in this example suspiciously always takes exactly one second (1008-1012ms) to finish, while not consuming large amounts of CPU time. Using debug lines, I have also confirmed that $colItems contains just one element. In fact it is For $objItem In $colItems​ that's taking this one second. I understand there will be some conversion from the WMI return value to actual usable data, but it looks very much like there is either a delay or a timeout of some sort going on. Has anyone had similar issues? Have you found a way to get rid of it? If not, is there a similarly easy way to get CPU load without WMI? Thanks for your feedback.
  5. Greetings! So I found a device named "X10 RF Remote Receiver" along with the remote in an old PC and it was connected to the motherboard with a 4-pole connector, so I soldered a USB plug on it and plugged it into my laptop - and it worked! But since programs don't usually come with support for all kinds of HIDs, this needed a little bit of software inbetween the drivers and whatever I want to control. After a few hours, I ran into a .NET tool that translated the remote signals into keystrokes, tailored to a wide variety of programs. Except they wanted money for it. After the free trial expired, my remote was once again useless, except for arrow keys and the power button. But today I managed to get hold of the raw signals! TL;DR: If your PC has an X10 type remote (and many other models are said to be compatible, I just can't guarantee this will work) and you've been wanting to directly control a script with it, this code is for you! (I seriously hope this is something new) First, you need the ActiveHome PRO SDK. After you've installed it, you can listen for key press events in your AutoIt script: $x10 = ObjCreate("X10.ActiveHome") If @error Then MsgBox(0,"",@error) EndIf $x10event = ObjEvent($x10, "_x10event", "_DIActiveHomeEvents") If @error Then MsgBox(0,"",Hex(@error)) Exit EndIf Func _x10eventRecvAction($parameter1,$parameter2,$parameter3,$parameter4,$parameter5,$parameter6,$parameter7) ConsoleWrite($parameter1 & @CRLF & $parameter2 & @CRLF & $parameter3 & @CRLF & $parameter4 & @CRLF & $parameter5 & @CRLF & $parameter6 & @CRLF & $parameter7) EndFunc While 1 Sleep(10) WEnd Your computer might still interpret remote key presses as keystrokes. To disable that, open your Control Panel and locate the Remote Control menu: Press any key on the remote to see which channel it sends on, then tell it to accept commands only from a different channel. The script will still work fine and Windows will leave you alone! Edit: It even survives unplugging and re-plugging the receiver. In fact, it fires a DeviseStop/DeviceStart event! Translating key presses on the remote into useful things is left as an exercise for the reader.
  6. Greetings. I have managed to cause a bug that makes AutoIt crash without giving me a syntax error or undefined variable. Instead, the exe sets off the "AutoIt v3 Script has stopped working" dialog and ultimately exits with an exit code of 255. Since I haven't specified that exit code anywhere in the script, I am assuming it might tell me something about the type and location of the error. The program is a chat client implementing my own protocol. As a side job, it bots a free-bitcoin website. The error occurs anywhere from minutes to hours after the program connects to to the chat server. It runs perfectly before that. My script is very expansive (1000 lines) and does not run productively if just pasted and executed, but I can tell you it uses a GUI with standard elements, GDIPlus (for a task outside the GUI), DLL Structs and TCP functions. While that is probably not enough information for you guys, it might be a start. My main question is: Do the AutoIt exit codes have any meaning, are they documented somewhere or can somebody tell me about the rough nature of my error? Here is my current code, if you do want to dig through it: <snip>
  7. Okay, I made it. I used Ws2_32.dll's functions. Here is my code: UDPStartup() $hWs2_32 = DllOpen("ws2_32.dll") $hSocket = _WinsockCreateSocket(2, 2, 17) _WinsockBind($hSocket, "192.168.178.20", 53); The source address and port for the Socket. The IP must be your LAN IP. I've found that 127.0.0.1 does not work. _WinsockConnect($hSocket, "192.168.178.22", 65432); The destination IP and port. _WinsockSend($hSocket, "This UDP Packet came from Port 53!") Func _WinsockCreateSocket($Address_Family, $Socket_Type, $Protocol) $iRet = DllCall($hWs2_32, "int", "socket", "int", $Address_Family, "int", $Socket_Type, "int", $Protocol) Return $iRet[0] EndFunc Func _WinsockBind($hSocket, $IP, $Port) $hAddr = _SocketAddr($IP, $Port) $iRet = DllCall($hWs2_32, "int", "bind", "uint", $hSocket, "ptr", DllStructGetPtr($hAddr), "int", DllStructGetSize($hAddr)) Return $iRet[0] EndFunc Func _WinsockConnect($hSocket, $IP, $Port) $hAddr = _SocketAddr($IP, $Port) $iRet = DllCall($hWs2_32, "int", "connect", "uint", $hSocket, "ptr", DllStructGetPtr($hAddr), "int", DllStructGetSize($hAddr)) EndFunc Func _WinsockSend($hSocket, $data) $hBuf = DllStructCreate("byte[" & BinaryLen($data) & "]") DllStructSetData($hBuf, 1, $data) $iRet = DllCall($hWs2_32, "int", "send", "uint", $hSocket, "ptr", DllStructGetPtr($hBuf), "int", DllStructGetSize($hBuf), "int", 0) EndFunc Func _SocketAddr($IP, $Port, $Address_Family = 2) $stAddress = DllStructCreate("short; ushort; uint; char[8]") DllStructSetData($stAddress, 1, $Address_Family) $iRet = DllCall($hWs2_32, "ushort", "htons", "ushort", $Port) DllStructSetData($stAddress, 2, $iRet[0]) $iRet = DllCall($hWs2_32, "uint", "inet_addr", "str", $IP) DllStructSetData($stAddress, 3, $iRet[0]) Return $stAddress EndFunc ;==>_SocketAddr Func _WSAGetLastError() $iRet = DllCall($hWs2_32, "int", "WSAGetLastError") Return $iRet[0] EndFunc ;==>_WSAGetLastError On the other computer, there was an AutoIt UDP listener running. It said the source port of the packet received is indeed 53. There is PLENTY of room to expand this and make it into an excellent UDF. I only implemented the functions I need for now, but you probably see where to expand this. Here's the list of functions that could potentially be adapted in the UDF: http://msdn.microsoft.com/en-us/library/windows/desktop/ms741394(v=vs.85).aspx
  8. I've found out about Ws2_32.dll and I'm examining its functions now. If I get it to work (never used DllCall outside of copy-pasting code) I'll post my results.
  9. Reverse DNS lookups aren't my problem, although I didn't know that and it might come in handy down the road.. It also explains what my phone has been doing with all the in-arpa queries. Edit: I'm being an egocentric whackjob, nevermind Anyway, is there no UDF or exotic DLL that lets me tweak a UDP socket handle's source port? I mean this is a frequently used feature of the UDP protocol, there's got to be something for Windows.
  10. Thank you, I will have a look at that! It seems the program does kind of what I'm doing, except it translates the data back and forth between two different protocols. What you are specifying in UDPOpen() is the remote port, that is the port where the packet is going to. What I have to set is the local port, which is the one where my packet comes from. UDPOpen() chooses a random port for that. I suppose there isn't a way to build IP packets in Windows, is there? I mean that would be bad news for the internet.
  11. Unfortunately, UDPBind() can only be used to wait for incoming packets. As for the code, I'll just dump the (extremely crude) script I have right now. I'll clean it up a lot once it's functional. #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Dim $dnslabels[10] Dim $dnsentries[10] Global $banned = ObjCreate("System.Collections.ArrayList") #Region ### START Koda GUI section ### Form=C:\Users\Dennis\Documents\dns.kxf $Form1 = GUICreate("DNS Visualizer", 266, 438, 192, 124) For $i = 0 To 9 $dnslabels[$i] = GUICtrlCreateLabel("", 8, 8 + 16 * $i, 252, 17) Next $Input1 = GUICtrlCreateInput("", 8, 200, 249, 21) $Button1 = GUICtrlCreateButton("Block", 8, 224, 75, 25) $Label3 = GUICtrlCreateLabel("Label3", 8, 256, 36, 17) $Label4 = GUICtrlCreateLabel("Label4", 8, 280, 36, 17) $Label5 = GUICtrlCreateLabel("Label5", 8, 304, 36, 17) $Button2 = GUICtrlCreateButton("Unblock", 182, 224, 75, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUIRegisterMsg($WM_COMMAND, "labelclick") OnAutoItExitRegister("Cleanup") UDPStartup() $socket = UDPBind(@IPAddress1, 53) If @error <> 0 Then Exit While 1 $packet = UDPRecv($socket, 512, 3) If $packet <> "" Then $data = $packet[0] ConsoleWrite($packet[1] & ":" & $packet[2] & @CRLF) visualize($data) $bdomain = BinaryMid($data, 13, BinaryLen($data) - 16) $sdomain = extractdomain($bdomain) ConsoleWrite("Extracted Domain Name: " & $sdomain & @CRLF) ConsoleWrite(@CRLF) If $banned.contains($sdomain) Then Dim $apacket[4] $apacket[0] = BinaryMid($data, 1, 2) $apacket[1] = "81800001000100000000" $apacket[2] = $bdomain $apacket[3] = "00010001C00C000100010000001C00045F735A8B" $rpacket = binarymerge($apacket) $sock = UDPOpen($packet[1], $packet[2]) UDPSend($sock, $rpacket) ConsoleWrite("->Sent deceiving packet" & @CRLF) entry_push("(" & $sdomain & ")") Else $abc = UDPOpen("8.8.8.8", 53) UDPSend($abc, $data) While 1 $dat = UDPRecv($abc, 512, 3) If $dat <> "" Then visualize($dat[0]) ConsoleWrite(@CRLF & $dat[1] & ":" & $dat[2] & @CRLF) ExitLoop EndIf Sleep(100) WEnd $sock = UDPOpen($packet[1], $packet[2]) If @error Then MsgBox(16, "", "ARGON") ConsoleWrite(IsBinary($dat) & @CRLF) UDPSend($sock, $dat[0]) UDPCloseSocket($abc) entry_push($sdomain) EndIf EndIf $data = "" Sleep(100) WEnd Func visualize($binary) $tab0 = "" $tab1 = "" ConsoleWrite("Len: " & BinaryLen($binary) & @CRLF) For $i = 1 To BinaryLen($binary) $tab0 &= Hex(BinaryMid($binary, $i, 1), 2) & " " $symbol = BinaryToString(BinaryMid($binary, $i, 1)) If StringInStr("abcdefghijklmnopqrstuvwxyz0123456789.-", $symbol) Then $tab1 &= $symbol & " " Else $tab1 &= "? " EndIf If Mod($i, 8) = 0 Then ConsoleWrite($tab0 & @TAB & $tab1 & @CRLF) $tab0 = "" $tab1 = "" EndIf Next If Mod($i, 8) <> 0 Then ConsoleWrite($tab0) For $j = 0 To 8 - Mod($i, 8) ConsoleWrite(" ") Next ConsoleWrite(@TAB & $tab1) EndIf ConsoleWrite(@CRLF) EndFunc ;==>visualize Func Cleanup() UDPCloseSocket($socket) UDPShutdown() EndFunc ;==>Cleanup Func extractdomain($binary) $domain = "" For $k = 2 To BinaryLen($binary) - 1 $symbol = BinaryToString(BinaryMid($binary, $k, 1)) If StringInStr("abcdefghijklmnopqrstuvwxyz0123456789.-", $symbol) Then $domain &= $symbol Else $domain &= "." EndIf Next Return $domain EndFunc ;==>extractdomain Func entry_push($entry) For $i = 0 To 8 $dnsentries[$i] = $dnsentries[$i + 1] GUICtrlSetData($dnslabels[$i], $dnsentries[$i]) Next $dnsentries[9] = $entry GUICtrlSetData($dnslabels[9], $entry) EndFunc ;==>entry_push Func labelclick($hwnd, $nmsg, $wparam, $lparam) For $i = 0 To 9 If $wparam = $dnslabels[$i] Then GUICtrlSetData($Input1, $dnsentries[$i]) Next If $wparam = $Button1 Then $banned.add(GUICtrlRead($Input1)) If $wparam = $Button2 Then $banned.remove(StringTrimLeft(StringTrimRight(GUICtrlRead($Input1), 1), 1)) EndFunc ;==>labelclick Func binarymerge($aBinary) Local $struct, $struct2 $ptr = 0 $len = 0 For $i = 0 To UBound($aBinary) - 1 $len += BinaryLen($aBinary[$i]) Next $struct = DllStructCreate("byte[" & $len & "]") For $i = 0 To UBound($aBinary) - 1 $struct2 = DllStructCreate("byte[" & BinaryLen($aBinary[$i]) & "]", DllStructGetPtr($struct) + $ptr) DllStructSetData($struct2, 1, $aBinary[$i]) $ptr += BinaryLen($aBinary[$i]) $struct2 = 0 Next $binary = DllStructGetData($struct, 1) $struct = 0 Return $binary EndFunc It contains a few goodies, such as a function that merges arrays of binary data into one variable and an Object that implements functions of an ArrayList. The attentive observer will notice that the aim of this project is to sniff DNS requests from mobile devices in order to detect and block potentially unwanted background traffic and ads. The user can block and unblock domains at runtime (blocked domains point to 127.0.0.1). Everything works except the UDP connections.
  12. Greetings, I have been trying to code a DNS server in AutoIt. I have learned the protocol and I am about to complete the implementation. However, I have hit a road-block: AutoIt's internal UDP functions do not allow choosing a source port for an outgoing UDP packet. I'll illustrate the problem with this imaginary scenario where a Client with the IP 1.2.3.4 makes a query to the DNS Server 8.8.8.8: Client's query packet goes from 1.2.3.4:65432 to 8.8.8.8:53 Server's response goes from 8.8.8.8:53 to 1.2.3.4:65432. The problem with AutoIt's UDP functions is that to respond to the UDP Packet, I have to first create a UDP "Socket" using UDPOpen, which does not give me the option to keep 53 as the source port for the response packet. The scenario with my AutoIt server now looks like this: Client's query packet goes from 1.2.3.4:65432 to 8.8.8.8:53 Server opens a new UDP Socket to send data to the Client Server's response goes from 8.8.8.8:61234 to 1.2.3.4:65432. It seems that the devices I am using to make DNS requests to my server discard the response packet because of its strange source port. I have learned that the native functions are unable to solve my problem, so I'd like to know whether there are any workarounds for this. Thank you -Brainiac
  13. And thus, the thread died. I have the same problem - I want to merge two binary variables into one, but AutoIt keeps treating it as a string. I'll tell you when I figure out how to do it (efficiently)!
  14. Hey guys, I'm having some problems with the server: I tried to transfer a file over the internet using my external IP and an open port. What happens is that sometimes, everything works just perfectly, but often the server does not close the file handle after the transfer has finished. You send a "close handle" request to the server with those two line breaks (line 147 I think). I tried using a different string for the request and replaced If $rBuff = "WMpHUWr0FEZg" Then with If stringright($rBuff,12) = "WMpHUWr0FEZg" Then which made it a little more reliable, but it still doesn't work every time. Any ideas?
×
×
  • Create New...