Leaderboard
Popular Content
Showing content with the highest reputation on 07/19/2018 in all areas
-
It's about running exe from memory as it's often called. So you have some binary data that you want to embed in your script and run afterward like some additional program. In this post I will try to explain how to do it. First to deal with mentioned binary as that's, in spite of the plainness of retrieving it, often insuperable. To avoid questions about that this is one way of getting it: Global $sModule = "E:Program filesGUIDGenGUIDGEN.EXE" ; change to yours wanted Global $hModule = FileOpen($sModule, 16) If @error Then Exit Global $bBinary = FileRead($hModule) FileClose($hModule) Global Const $MAX_LINESIZE = 4095 Global $iNewLine, $j Global $iChinkSize = 32 Global $sBinary For $i = 1 To BinaryLen($bBinary) Step $iChinkSize $j += 1 If 4*($j * $iChinkSize) > $MAX_LINESIZE - 129 Then $iNewLine = 1 EndIf If $iNewLine Then $iNewLine = 0 $j = 0 $sBinary = StringTrimRight($sBinary, 5) $sBinary &= @CRLF & '$bBinary &= "' & StringTrimLeft(BinaryMid($bBinary, $i, $iChinkSize), 2) & '" & _' & @CRLF ContinueLoop EndIf If $i = 1 Then $sBinary &= '$bBinary = "' & BinaryMid($bBinary, $i, $iChinkSize) & '" & _' & @CRLF Else $sBinary &= ' "' & StringTrimLeft(BinaryMid($bBinary, $i, $iChinkSize), 2) & '" & _' & @CRLF EndIf Next $sBinary = StringTrimRight($sBinary, 5) ClipPut($sBinary) ConsoleWrite($sBinary)Now for what's really important... Executable file causes a computer to perform indicated tasks according to encoded instructions. Files that we talk about are in PE format. When exe file is run special loader reads it and performs act of loading. That's how that particular exe gets in touch with a processor. Processor then executes different actions described by the opcodes. Main requirement for any PE file required by the loader is for it to actually exist. To be written on the drive. It can't be in the air. That's not allowed and when you think of it it's only logical. So how to run from memory? I'm gonna fool the system. It will think that all works as it should and will have no idea that it plays my game. There is more than way of doing that. Method described here has been used by different peoples before. When doing research for this post I have encountered many implementations. And I must say that I was very disappointed seeing that even the writers of the code often lack understanding of it. It's kind of pathetic when you see some code used and when asking author what's this or that you get answer "I don't know". And if you ask for the code to be explained by words (any fucking human language) coders fail terribly. How can you write code if you can't explain it?!? Anyway, this is the procedure: Start your script Create new process using CreateProcess function with CREATE_SUSPENDED flag Use GetThreadContext function to fill CONTEXT structure Read and interpret passed binary Allocate enough memory for the new module inside the victim process Simulate loader. Construct the new module (load) in place of allocated space. Make use of mentioned CONTEXT structure. Change entry point data and ImageBaseAddress data. Resume execution If all that went well windows should now be running not the original module but the new, saved in script as a variable. The script: RunBinary.au3 Script is well commented so it shouldn't be too hard to get a grip. New script is taking all possible advantages of PE format. That means if your module (embedded) has relocation directory it will run for sure.If not it could fail. When it will fail? Modules with no reloc directory (IMAGE_DIRECTORY_ENTRY_BASERELOC) ought to be loaded at precise address (stored within module; IMAGE_OPTIONAL_HEADER ImageBase). If for some reason not enough space can be allocated at that address within victim's memory space, function will fail. Thing is system makes rules, if we are not allowed to some memory space of a process there is nothing to do then to try again. So, try again if it fails. Maybe change the 'victim'. edit: 64bit support added. That means you can embed either x64 or x86 modules. If your AutoIt is x64 you embed x64 modules. If AutoIt is x86 embed x86. x64 AutoIt could also use embedded x86 modules but I don't like that because needed structures would have to be changed to something that's not meeting aesthetics standards .1 point
-
I needed a function to automate programs at work that can't be fully automated via Autoits built in functions. For example a virtual machine running on your physical machine, meaning you would need to run an extra script within the virtual machine (if it is even running Windows) in order to automate everything. I came across OpenCV which allows matching/finding a picture in another picture. This would also allow searching for a button/text on the screen in order to press the exact position. Fortunately @mylise already translated all the required OpenCV functions to Autoit, I just had to remove all unnecessary functions to make the script as small as possible. The problem: Using this method, you will never be able to fully automate everything dynamically, as it will only work on the machine with same resolution/dpi settings, same theme etc.. This is only a last resort for programs that can't be automated using the built in Autoit functions. Features: Find a given picture on the entire screen (all monitors) or a certain area on the screen and execute mouse clicks on this position. Adjust the threshold so that the picture doesn't have to match 100%. Debugging options like logging and marking the screen where the picture was found etc. Includes a Snapshot-Tool that creates snapshots of a certain area(buttons, text etc.) on the screen and generates the code that is required for the matching. It can also be used to get the coordinates to a marked area on the screen in order to check only on a certain area for the match picture. Example: Note: The example will probably not work on your computer, depending on the display resolution and dpi settings, as the picture has to match the exact same size on the screen. Please use the included Snapshot-Tool to generate new match pictures and code very easily. #AutoIt3Wrapper_UseX64=n ; In order for the x86 DLLs to work #include "OpenCV-Match_UDF.au3" _OpenCV_Startup();loads opencv DLLs _OpenCV_EnableLogging(True,True,True) ;Logs matches, errors in a log file and autoit console output. ;Please note that these examples might not work as the match pictures have to be found with the exact same size on your screen. ;Example 1 ShellExecute("http://www.tv.com/");Open Website tv.com $Match1 = _MatchPicture(@ScriptDir&"\Match\1.png", 0.70,False,10,500);Try to find the match picture on the screen. Number of tries: 10, Sleep between each try: 500ms. If Not @error Then _MarkMatch($Match1) ;Debugging: Draws a rect on the screen/coordinates of the match to show the user where the match was found Sleep(100) _ClickMouse($Match1, "left",1) ;Calculates the center of the match and clicks the left mouse once on click position EndIf Sleep(1000) ;Example 2, matching on a specific area of the screen ShellExecute("notepad.exe");open nodepad WinWait("[CLASS:Notepad]","",5) WinMove("[CLASS:Notepad]","",0,0,500,500) Local $sCoords[4] = [0, 0, 500,500] $Match2 = _MatchPicture(@ScriptDir&"\Match\2.png", 0.80,$sCoords,3,500) If Not @error Then _MarkMatch($Match2) Sleep(100) _ClickMouse($Match2, "left", 1) EndIf _OpenCV_Shutdown();Closes DLLs So basically, all you need to do is provide a path to the match picture and the function will return you the coordinates (x1,y1,x2,y2) of where the picture has been found on the screen. With these, you can either calculate an exact position for the mouse click or use the "_ClickMouse" function which will execute a mouse click on the center of the coordinates where the picture was found. Credits: @mylise for the OpenCV UDF Download: Includes the required .DLL files of OpenCV. You can also manually download them on the website of OpenCV (Version 3.x doesn't include these anymore, you need to download 2.x). OpenCV_Match.zip1 point
-
CronToTime.au3 UDF - Cron expression parser
Earthshine reacted to ergo for a topic
CronToTime.au3 UDF converts a Unix Cron expression into a DateTime string. On Unix systems a Cron expression made of five fields separated by blanks/tabs followed by a shell command to execute. e.g. 15-30 2,3,4,5 29 1-12 0-6 reboot +------------- minute (0 - 59) ¦ +------------- hour (0 - 23) ¦ ¦ +------------- day of month (1 - 31) ¦ ¦ ¦ +------------- month (1 - 12) ¦ ¦ ¦ ¦ +------------- day of week (0 - 6) (Sunday to Saturday, 7 is also Sunday) ¦ ¦ ¦ ¦ ¦ +------------- some shell command ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ * * * * * reboot (In this UDF the 6th field has no meaning and no influence on the result). For more information see https://en.wikipedia.org/wiki/Cron Finds the next event of the specified Cron expression, starting from current UTC/GMT. _pce_findNextTimeUTC($sCronExp [, $bForwardSearch = True [, $minutesOffset = 0]]]) Finds the next event of the specified Cron expression. If $sDateTime is not set, local time will be used. _pce_findNextTime($sCronExp [, $bForwardSearch = True [, $sDateTime = "" [, $minutesOffset = 0]]]) Convert names in usable Cron expression values. e.g. "15-30 2,3,4,5 29 July-December Mo-Su" to "15-30 2,3,4,5 29 7-12 1-7" _pce_convertNames( $sCronExp ) See the include for details. New version on GitHub: https://github.com/seizu/CronToTime1 point -
autoit and windows 8
FrancescoDiMuro reacted to careca for a topic
I think you win the prize for the greatest ressurection, i've seen so far. 20121 point -
Accessing a variable with an array element.
Earthshine reacted to Malkey for a topic
If this is what you were after in BrewManNH's example, ConsoleWrite("$Active" & $i & " = " & Eval($array[$i][1]) & @CRLF) then this does the same thing (in BrewManNH's example). ConsoleWrite("$Active" & $i & " = " & Execute("$" & $array[$i][1]) & @CRLF)1 point -
All these examples return what you have specified in your examples. ConsoleWrite('Should be: 40 ' & _RoundDown(45, 10) & @CRLF) ConsoleWrite('Should be: 40 ' & _RoundDown(45, 20) & @CRLF) ConsoleWrite('Should be: 30 ' & _RoundDown(45, 30) & @CRLF) ConsoleWrite('Should be: 30 ' & _RoundDown(45, 15) & @CRLF) ConsoleWrite('Should be: 0 ' & _RoundDown(45, 50) & @CRLF) ConsoleWrite('Should be: 0 ' & _RoundDown(0, 50) & @CRLF) ConsoleWrite('Should be: -50 ' & _RoundDown(-10, 50) & @CRLF) ConsoleWrite('Should be: -20 ' & _RoundDown(-10, 20) & @CRLF) ConsoleWrite('--------------------------' & @CRLF) ConsoleWrite('Should be: 80 ' & _RoundUp(45, 40) & @CRLF) ConsoleWrite('Should be: 60 ' & _RoundUp(45, 30) & @CRLF) ConsoleWrite('Should be: 60 ' & _RoundUp(45, 20) & @CRLF) ConsoleWrite('Should be: 45 ' & _RoundUp(45, 15) & @CRLF) ConsoleWrite('Should be: 50 ' & _RoundUp(45, 50) & @CRLF) ConsoleWrite('--------------------------' & @CRLF) ConsoleWrite('Should be: -40 ' & _RoundEx(-45, 40) & @CRLF) ConsoleWrite('Should be: -40 ' & _RoundEx(-40, 40) & @CRLF) ConsoleWrite('Should be: 0 ' & _RoundEx(-39, 40) & @CRLF) ConsoleWrite('Should be: -20 ' & _RoundEx(-39, 20) & @CRLF) ConsoleWrite('Should be: -30 ' & _RoundEx(-39, 30) & @CRLF) ConsoleWrite('Should be: -20 ' & _RoundEx(-39, 20) & @CRLF) ConsoleWrite('Should be: 0 ' & _RoundEx(-25, 30) & @CRLF) ConsoleWrite('Should be: 80 ' & _RoundEx(45, 40) & @CRLF) ConsoleWrite('Should be: 60 ' & _RoundEx(45, 30) & @CRLF) ConsoleWrite('Should be: 60 ' & _RoundEx(45, 20) & @CRLF) ConsoleWrite('Should be: 45 ' & _RoundEx(45, 15) & @CRLF) ConsoleWrite('Should be: 50 ' & _RoundEx(45, 50) & @CRLF) ConsoleWrite('Should be: 40 ' & _RoundEx(45, -10) & @CRLF) ConsoleWrite('Should be: 40 ' & _RoundEx(45, -20) & @CRLF) ConsoleWrite('Should be: 30 ' & _RoundEx(45, -30) & @CRLF) ConsoleWrite('Should be: 30 ' & _RoundEx(45, -15) & @CRLF) ConsoleWrite('Should be: 0 ' & _RoundEx(45, -50) & @CRLF) ConsoleWrite('Should be: 0 ' & _RoundEx(0, -50) & @CRLF) ConsoleWrite('Should be: -50 ' & _RoundEx(-10, -50) & @CRLF) ConsoleWrite('Should be: -20 ' & _RoundEx(-10, -20) & @CRLF) Func _Roundex($a, $b) If Mod($a, $b) = 0 And $a <> 0 Then $a -= 1 Return (Ceiling($a / $b) & @CRLF) * $b EndFunc ;==>_RoundUp Func _RoundDown($a, $b) If Mod($a, $b) = 0 And $a <> 0 Then $a -= 1 Return (Floor($a / $b) & @CRLF) * $b EndFunc ;==>_RoundDown Func _RoundUp($a, $b) Return (Ceiling($a / $b) & @CRLF) * $b EndFunc ;==>_RoundUp1 point
-
VBS convert to Au3 [Help]
ufukreis1212 reacted to water for a topic
Global $oFirewall = ObjCreate("HNetCfg.FwMgr") Global $oPolicy = $oFirewall.LocalPolicy.CurrentProfile $oPolicy.FirewallEnabled = TRUE1 point -
[SOLVED] mp3 tags ( raw file read )
argumentum reacted to Danyfirex for a topic
Hello. Maybe this UDF helps. https://www.autoitscript.com/forum/topic/43950-id3-udf-id3v1-id3v2-mp3-tags/ Saludos1 point -
I think the device has not Unique ID so It's generate by the system. check here: It says: Note: If the second character of the unique instance ID is a '&', then the ID was generated by the system, as the device did not have a serial number. Saludos1 point
-
hey, once again another quick question. I have an input box but i want to save what the user puts in the box as a variable. how would i do that?1 point