Jump to content

Robinson1

Active Members
  • Posts

    48
  • Joined

  • Last visited

Recent Profile Visitors

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

Robinson1's Achievements

Seeker

Seeker (1/7)

3

Reputation

  1. I just notice that documentation for MapAppend() and others are only available in french: https://www.autoitscript.fr/autoit3/docs/functions/ Log.htm 2019-12-30 21:45 6.2K MapAppend.htm 2019-12-30 21:45 8.5K MapExists.htm 2019-12-30 21:45 6.9K MapKeys.htm 2019-12-30 21:45 7.6K Map Management.htm 2019-12-30 21:45 1.2K MapRemove.htm 2019-12-30 21:45 17K Math Management.htm 2019-12-30 21:45 3.8K ... and did find their way into the international documentation: https://www.autoitscript.com//autoit3/docs/functions/ Log.htm 2018-03-16 10:39 6.1K Math Management.htm 2018-03-16 10:39 2.8K Well I'm just asking because also in au3.api all the map functions are not listed. I had a look at the history, Since 3.3.13.15 (5th August, 2014) map management seems to be 'settled down' and working. EDIT: I just issued a ticket about here: https://www.autoitscript.com/trac/autoit/ticket/3795
  2. @argumentum Oh well I should have done this in first place - Well now I did: ... UPDATE #1: Now I created a ticket for this:https://autoitscript.com/trac/autoit/ticket/3752 ... Let's see what happens.
  3. Good point. Mod() is good candidate for a mod and a POC. Nice to have some challenges. Doing MATE gave me some good inside and idea how AutoIt works - I guess just for fun I may create some MODed AutoIT that'll accept $result = mod(3,2)  as well as $result = 3 mod 2 Token opcodes 0x40 .. 0x58 are in used for operators. 0x59 .. 0x7E are still *free* to use. So I may use 0x60 for the new infix mod operator
  4. Cool thanks for your reply. Fully go ya point. The pragmatic programmer. No matter how it's done - as long as it is done. However I see coding and code as kinda of art. So it that context such puerile questions matters.
  5. Okay it's about the style of the AutoIT Language. Concerning: BitAND, BitOR, BitXOR, BitXOR, BitShift, BitRotate That's a very simple but fundamental question: Why BitAND is not infix? In most other common programming languages it is. Let's take JavaScript. Here I write: Result = Value & Mask But on AutoIT it's $Result = BitAND ( $Value , $Mask ) That's more the Lisp / prefix way. While the logical and is indeed infix $bIsEnable = $bIsGUI_chkEnabled and $bIsGUI_chkChecked So I wonder why it is like this. What is the Idea behind this language design decision? Okay Autoit is a matured Language but yeah - It's never to late for a change. Wasn't there ideas to unify it any way? So we also make the 'Bit' operations infix as well? ... while Just keeping the 'old' prefix version -for backwards compatibility - as well. UPDATE #1: Now I created a ticket for this: https://autoitscript.com/trac/autoit/ticket/3752 Well to generalise/modulate It more I may bring it down to the Subject Verb Object thing you have with language. "I go swimming" that's S-V-O or some infix. "Swimming I go". is O-S-V - postfix and sound much like yoda-style. While "go I swimming" is V-S-O - prefix and 'feels' more like kinda question. There is no right or wrong here - however personally I find infix is most appropriate here.
  6. Okay so in the end I decided for some hybrid Implementation: 1.Do a test to find out which chars RegExp can not match and store it. 2. Do a search on char level ( in the match pattern a replace all not working chars with '.' Any char 3. Check each match by converting the the match to a hexnumber string ( and the match pattern as well to match a hexnumber string) . Func init_NotWorkingBytes()         ;Create TestData         local $TestData = "0x"         for $i=00 to 0xff             $TestData &= StringFormat( "%02X", $i)         Next         $TestData = BinaryToString ($TestData)         Global $RegExpNotWorkingBytes    =    "(?|\\x80)"         for $i=0x0 to 0xFF             $pat = StringFormat( "\x%02X", $i)             $match = StringRegExp( $TestData ,$pat  ,$STR_REGEXPARRAYFULLMATCH)             if @error<>0 then ;~             ConsoleWrite('$match = ' & _ ;~                 $pat& ' - ' & $match & '  > ' & chr($i) ) ;### Debug Console                 $RegExpNotWorkingBytes &= "|(?|\" & $pat & ")" ;~                 ConsoleWrite( @CRLF)             EndIf         Next     Return $RegExpNotWorkingBytes EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: BinRegExp ; Description ...: Use RegExp with binary data ; Syntax ........: BinRegExp($test, $pattern[, $flag = 0[, $offset = 1]]) ; Parameters ....: $test                - a dll struct value. ;                  $pattern             - a pointer value. ;                  $flag                - [optional] a floating point value. Default is 0. ;                  $offset              - [optional] an object. Default is 1. ; Return values .: None ; Remarks .......: That's kind of workaround since the ;That's a kinda hybrid for /x00-/x7F it uses StringRegExp with binary data and ;                   checks each match again with the slower StringRegExp hexnumberstring binary data ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func BinRegExp($test, $pattern, $flag = 0, $offset = 1)     $RegExpNotWorkingBytes = init_NotWorkingBytes() ;~     ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $RegExpNotWorkingBytes = ' & $RegExpNotWorkingBytes & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ;~     $RegExpNotWorkingBytes = '\\x[7-9A-Fa-f][0-9A-Fa-f]'     ;Replace not working in Range of /x7F-/xFF with .     $SafePattern = StringRegExpReplace( $pattern, _             $RegExpNotWorkingBytes, _             '.') ;~     ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $SafePattern = ' & $SafePattern & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console     for $Round = 1 to 0x7FFFFFFF         Local $RetVal         = StringRegExp($test, $SafePattern, $flag, $offset)         Local $RetError     = @error         Local $RetExtended     = @extended         If $RetError = 0 Then             $MatchData      = $RetVal[0]             $MatchLength = StringLen($MatchData)                 $MatchStart         =  $RetExtended                 $MatchStart     -=  $MatchLength                 $MatchStart     -= 1             $RetVal2 = _BinRegExp($MatchData, $pattern, $flag)             If @error = 0 Then                 ; Match is valid                 ExitLoop             ElseIf @error = 3 Then               ; the match was to big - apply delta; seek back from end of current match                 $offset = $MatchStart + @extended             else                 ; ... was not a real match - look for more                 $offset = $RetExtended             EndIf         Else             ExitLoop         EndIf         ConsoleWrite('.') ;~         myLog(@ScriptLineNumber ,"$offset = " & hex($offset) )     Next     Return SetError($RetError, $RetExtended, $RetVal) EndFunc   ;==>BinRegExp Func _BinRegExp($test, $pattern, $flag = 0, $offset = 1)         const $xdigit = "." ;"[0-9A-Fa-f]"     ; Replace \xXX with .     $Numberstring = StringReplace($pattern, '\x', '')     $Numberstring = StringReplace($Numberstring, ".", "(?:" & $xdigit & $xdigit & ")")     $test = StringToBinary($test)     Local $RetVal = StringRegExp( $test, $Numberstring, $STR_REGEXPARRAYMATCH  )     Local $RetError     = @error     Local $RetExtended     = @extended     If $RetError = 0 Then         $MatchData      = $RetVal[0]         $MatchLength = StringLen($MatchData)         $testLength = StringLen( $test ) - 2 ; no '0x'         $delta = $testLength - $MatchLength         if $delta >= 2 then             ; the match was to big - set Error 4 and return adjustment delta ;~             $delta = $MatchLength - $delta ; set delta to how many bytes to seek back from end of current match             $delta = DivBy2($delta)             Return SetError(3, $delta)         EndIf     endif     Return SetError($RetError, $RetExtended, $RetVal) EndFunc   ;==>_BinRegExp Func DivBy2($Divident)     Return BitShift($Divident, 1) EndFunc   ;==>DivBy2 Full sample using this is here: http://bit.do/TeamViewerNA
  7. Cool that what I was looking for. But well avoid using 'naked literals' like this '8'. Or when ya do be aware that this is a bad coding style. The thing is it's hard to read. Put at least a comment behide what this '8' means. Using const's (or enum ) you define once - or import from somewhere is even better: #include <WinAPI.au3> #include <WindowsConstants.au3> $BorderWidth = _WinAPI_GetSystemMetrics( $SM_CYDLGFRAME ) ; 0x8 Well while most common ide's will show you the value that's behind some const when you just move the mouse over it. SciTe is not that advanced yet so maybe put the real value just behind as comment ; 0x8 So and in the end here is some Script that will call Call GetSystemMetrics with all SM_* value that are defined in WindowsConstants.au3 and show the return value. ; ; - = GetSystemMetrics demo = - ; ; Runs GetSystemMetrics with all possible values that are defined in Autoit ; #include <WinAPI.au3> ; Get all SM_* const's listed in WindowsConstants.au3 $SM_AllKnowValues = StringRegExp( _ _AutoIT_IncludeFile_Load("WindowsConstants.au3"), _ "\$(SM_\w+)\s*=\s*(0x)?(\d+)", _ $STR_REGEXPARRAYGLOBALFULLMATCH _ ) $HelpUrl = "https://msdn.microsoft.com/en-us/library/ms724385(VS.85).aspx" #include<array.au3> ;~ GetNShowData () AdlibRegister( GetNShowData ) Sleep(500) Func GetNShowData() local $OutputLines[0][4];=[["-", "-", "-","-"]] For $i = 0 To UBound($SM_AllKnowValues) - 1 Local $aMatch = $SM_AllKnowValues[$i] $SM_Name = $aMatch[1] $IsHex = $aMatch[2] $SM_Value= $aMatch[3] $SM_Value= $IsHex? dec($SM_Value): $SM_Value $ret= _WinAPI_GetSystemMetrics($SM_Value) $OutputLine = StringFormat( _ "%2i -> %-23s => %5i [ 0x%.3x ]" & _ " - %s#%s\n" , _ $SM_Value, $SM_Name, $ret, $ret, _ $HelpUrl, $SM_Name ) ConsoleWrite ($OutputLine) local $ArrLine[][]= [[ _ $SM_Value, $SM_Name, $ret, StringFormat( "0x%.3x", $ret) ]] $Header = "Value|SM_Name|RetVal|RetVal" _ArrayAdd( $OutputLines, $ArrLine ) Next Const $ArrayDisplay_ColumnNoRow = 0x40 Const $ArrayDisplay_ColumnTextAlignRight = 0x2 _ArrayDisplay($OutputLines,"GetSystemMetrics Return Values","", _ $ArrayDisplay_ColumnNoRow + $ArrayDisplay_ColumnTextAlignRight,"", _ $Header, -1 , 0 , _UserFunc ) EndFunc Func _UserFunc($aArray_2D, $aSelected) $itemIndex = $aSelected[1] $SM_Name = $aArray_2D [$itemIndex] [1] $url = StringFormat("%s#%s", $HelpUrl, $SM_Name) ShellExecute($url) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $url = ' & $url & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console EndFunc ;==>_UserFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _AutoIT_IncludeFile_Load ; Description ...: Loads a file frim the AutoIT Include ; Syntax ........: _AutoIT_IncludeFile_Load($IncludeName) ; Parameters ....: $IncludeName - *.au3 Include Filename ; Return values .: Success: FileContent (@extended Bytes Read) ; Failure: sets @error = 1 ; Author ........: YourRobinson1Name ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _AutoIT_IncludeFile_Load($IncludeName) $Path_Au3File = @AutoItExe & "\..\Include\" & $IncludeName $Ret = _myFileRead( $Path_Au3File ) Return SetError(@error, @extended, $Ret ) EndFunc ; #FUNCTION# ==================================================================================================================== ; Name ..........: _myFileRead ; Description ...: a wapper for FileRead(...) ; incase of an error an inputbox apperars, allowing the user to correct the path ; Syntax ........: _myFileRead($TheFile) ; Parameters ....: $TheFile - The file to read. ; Return values .: Success: FileContent ; Failure: sets @error = 1 ; Author ........: Robinson1 ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _myFileRead( $TheFile, $Count = -1) while True $Ret = FileRead( $TheFile, $Count) if @extended > 0 Then Return SetError( @error, @extended, $Ret) Else $TheFile = InputBox( "Error: FileRead returned " & @error, _ "Please edit the path:", $TheFile) if $TheFile = "" Then _ Return SetError (1) EndIf WEnd EndFunc The Output will look like this: 0 -> SM_CXSCREEN => 1680 [ 0x690 ] 1 -> SM_CYSCREEN => 1050 [ 0x41a ] 2 -> SM_CXVSCROLL => 20 [ 0x014 ] 3 -> SM_CYHSCROLL => 20 [ 0x014 ] 4 -> SM_CYCAPTION => 25 [ 0x019 ] 5 -> SM_CXBORDER => 1 [ 0x001 ] 6 -> SM_CYBORDER => 1 [ 0x001 ] 7 -> SM_CXDLGFRAME => 3 [ 0x003 ] 8 -> SM_CYDLGFRAME => 3 [ 0x003 ] 9 -> SM_CYVTHUMB => 20 [ 0x014 ] 10 -> SM_CXHTHUMB => 20 [ 0x014 ] 11 -> SM_CXICON => 40 [ 0x028 ] 12 -> SM_CYICON => 40 [ 0x028 ] 13 -> SM_CXCURSOR => 32 [ 0x020 ] 14 -> SM_CYCURSOR => 32 [ 0x020 ] 15 -> SM_CYMENU => 25 [ 0x019 ] 16 -> SM_CXFULLSCREEN => 1449 [ 0x5a9 ] 17 -> SM_CYFULLSCREEN => 1025 [ 0x401 ] 18 -> SM_CYKANJIWINDOW => 0 [ 0x000 ] 19 -> SM_MOUSEPRESENT => 1 [ 0x001 ] 20 -> SM_CYVSCROLL => 20 [ 0x014 ] 21 -> SM_CXHSCROLL => 20 [ 0x014 ] 22 -> SM_DEBUG => 0 [ 0x000 ] 23 -> SM_SWAPBUTTON => 0 [ 0x000 ] 24 -> SM_RESERVED1 => 0 [ 0x000 ] 25 -> SM_RESERVED2 => 0 [ 0x000 ] 26 -> SM_RESERVED3 => 0 [ 0x000 ] 27 -> SM_RESERVED4 => 0 [ 0x000 ] 28 -> SM_CXMIN => 145 [ 0x091 ] 29 -> SM_CYMIN => 37 [ 0x025 ] 30 -> SM_CXSIZE => 23 [ 0x017 ] 31 -> SM_CYSIZE => 24 [ 0x018 ] 32 -> SM_CXFRAME => 6 [ 0x006 ] 33 -> SM_CYFRAME => 6 [ 0x006 ] 34 -> SM_CXMINTRACK => 145 [ 0x091 ] 35 -> SM_CYMINTRACK => 37 [ 0x025 ] 36 -> SM_CXDOUBLECLK => 4 [ 0x004 ] 37 -> SM_CYDOUBLECLK => 4 [ 0x004 ] 38 -> SM_CXICONSPACING => 143 [ 0x08f ] 39 -> SM_CYICONSPACING => 94 [ 0x05e ] 40 -> SM_MENUDROPALIGNMENT => 0 [ 0x000 ] 41 -> SM_PENWINDOWS => 0 [ 0x000 ] 42 -> SM_DBCSENABLED => 0 [ 0x000 ] 43 -> SM_CMOUSEBUTTONS => 5 [ 0x005 ] 44 -> SM_SECURE => 0 [ 0x000 ] 45 -> SM_CXEDGE => 2 [ 0x002 ] 46 -> SM_CYEDGE => 2 [ 0x002 ] 47 -> SM_CXMINSPACING => 160 [ 0x0a0 ] 48 -> SM_CYMINSPACING => 30 [ 0x01e ] 49 -> SM_CXSMICON => 20 [ 0x014 ] 50 -> SM_CYSMICON => 20 [ 0x014 ] 51 -> SM_CYSMCAPTION => 25 [ 0x019 ] 52 -> SM_CXSMSIZE => 15 [ 0x00f ] 53 -> SM_CYSMSIZE => 24 [ 0x018 ] 54 -> SM_CXMENUSIZE => 23 [ 0x017 ] 55 -> SM_CYMENUSIZE => 24 [ 0x018 ] 56 -> SM_ARRANGE => 8 [ 0x008 ] 57 -> SM_CXMINIMIZED => 160 [ 0x0a0 ] 58 -> SM_CYMINIMIZED => 30 [ 0x01e ] 59 -> SM_CXMAXTRACK => 1696 [ 0x6a0 ] 60 -> SM_CYMAXTRACK => 1066 [ 0x42a ] 61 -> SM_CXMAXIMIZED => 1461 [ 0x5b5 ] 62 -> SM_CYMAXIMIZED => 1062 [ 0x426 ] 63 -> SM_NETWORK => 3 [ 0x003 ] 67 -> SM_CLEANBOOT => 0 [ 0x000 ] 68 -> SM_CXDRAG => 4 [ 0x004 ] 69 -> SM_CYDRAG => 4 [ 0x004 ] 70 -> SM_SHOWSOUNDS => 0 [ 0x000 ] 71 -> SM_CXMENUCHECK => 17 [ 0x011 ] 72 -> SM_CYMENUCHECK => 17 [ 0x011 ] 73 -> SM_SLOWMACHINE => 0 [ 0x000 ] 74 -> SM_MIDEASTENABLED => 0 [ 0x000 ] 75 -> SM_MOUSEWHEELPRESENT => 1 [ 0x001 ] 76 -> SM_XVIRTUALSCREEN => 0 [ 0x000 ] 77 -> SM_YVIRTUALSCREEN => 0 [ 0x000 ] 78 -> SM_CXVIRTUALSCREEN => 1680 [ 0x690 ] 79 -> SM_CYVIRTUALSCREEN => 1050 [ 0x41a ] 80 -> SM_CMONITORS => 1 [ 0x001 ] 81 -> SM_SAMEDISPLAYFORMAT => 1 [ 0x001 ] 82 -> SM_IMMENABLED => 1 [ 0x001 ] 83 -> SM_CXFOCUSBORDER => 1 [ 0x001 ] 84 -> SM_CYFOCUSBORDER => 1 [ 0x001 ] 86 -> SM_TABLETPC => 0 [ 0x000 ] 87 -> SM_MEDIACENTER => 1 [ 0x001 ] 88 -> SM_STARTER => 0 [ 0x000 ] 89 -> SM_SERVERR2 => 0 [ 0x000 ] 90 -> SM_CMETRICS => 0 [ 0x000 ] 4096 -> SM_REMOTESESSION => 0 [ 0x000 ] 8192 -> SM_SHUTTINGDOWN => 0 [ 0x000 ] 8193 -> SM_REMOTECONTROL => 0 [ 0x000 ] 8194 -> SM_CARETBLINKINGENABLED => 1 [ 0x001 ] The 'Run User Func' button in ArrayDisplay will also launch MSDN GetSystemMetrics documentation with the selected entry in the browser. Esc (or a click on Close ) does a refresh. To exit click the small 'Exit Script' button in ArrayDisplay. It's a nice example for: Getting the Autoit include Dir + the use of StringRegExp to parse an *.au3 file. SetError() to completely wrap an Autoit function (here FileRead) and also return the @error and @extended value How to use _ArrayDisplay and _ArrayAdd GetSystemMetrics_Demo.au3
  8. Cool thanks for ya reply. Okay what I wanna do now is to patch away this nag-screen "Gesponserte Sitzung" "Dies war eine kostenlose Sitzung mit Unterstützung von www.teamviewer.com" that pops ups after each remote Session. Well yes BinaryToString seems to be the critical point. And more in particular its flags that specify how the binary data is converted/encode. And there only $SB_ANSI (1) = binary data is ANSI (default) makes some sense here. However what is not in the AutoIT documentation that this encode/decoding is depending on the country settings. I uses Phython3 before and there string encoding decoding issue is well done. It's nice to learn and to get practical experience on that topic.. Well so far I end up creation some function called BinRegExp() that wraps in StringRegExp. Does some preSearch by replacing all /x7F-/xFF in the pattern with . (anychar) Checks each match via the slower but better working Version regex that uses HexNumberStrings Loops if needed (to filter out match artefacts ) I may posted it here sooner or later but it's not really a solution more like workaround around the problem. But let's get focus back on this: StringRegExp( $TestData ,'\x80'... Why it is not working?. A.) all 0x80 inside $TestData got somehow messed up during by BinaryToString B.) \x80 is somehow not transformed by StringRegExp as intented C.) Something else
  9. Plz edit/improve ya post. Format autoit code as 'code' with syntax highlighting it'll be more 'inviting' for ppl to study it choose a more specific topic give some feedback in case you already solved it
  10. Well the plan is to use the power of regular expressions engine of AutoIT for patching binary data. Something like this: StringRegExp( $BinaryData, "(?s)\x55\x8B.." <cut> ... Okay straight to question/problem ... certain bytes that are in the range from 0x80 to 0xA0 won't match. Hmm seem to be a char encoding problem. In detail these are 27 chars: 0x80, 0x82~8C, 0x8E, 0x91~9C, 0x9E,0x9F Here's a small code snippet to explore / explain this problem: #include "StringConstants.au3" $TestData = BinaryToString("0x7E7F808182") ;Okay $match = StringRegExp( $TestData ,'\x7E' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;Okay $match = StringRegExp( $TestData ,'\x7F' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;Error no match $match = StringRegExp( $TestData ,'\x80' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;Okay $match = StringRegExp( $TestData ,'\x81' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;Error no match $match = StringRegExp( $TestData ,'\x82' ,$STR_REGEXPARRAYFULLMATCH) ConsoleWrite('@extended = ' & @extended & ' $match = ' & $match & @CRLF) ;~ output: ;~ @extended = 2 $match = ;~ @extended = 3 $match = ;~ @extended = 0 $match = 1 ;~ @extended = 5 $match = ;~ @extended = 0 $match = 1 Hmm what to do? Go back and use the 'numberstring monster' implementation or just omit that range of 'unsafe bytes'. What is the root of this problem? Any idea how to fix this? Update: Okay I know a byte is not a character. But StringRegExp operates on String and so character level. Okay as long as you stay at Ansi encoding and only use /x00 - /X7F in the search pattern using StringRegExp works well to search for binary data. What bytes can be matched that are in the range from /X7F - /xFF is also depending on the code page. So this avoid to search for bytes in the range from 0x80-0xa0 only applies to Germany. I just change this country setting: to Thai and now near all bytes from /X7F - /xFF fails to match.
  11. Interesting question - but no there is definitely no such a thing like an API for hibernate a Process. (suprisingly Windows don't officially offers an API to suspend/resume a process) I once tried something when unpacking / dumping some process. With Read/WriteProcessMemory you can access the Memory of some other process. CreateRemoteThread may be used to start/create some other thread in another process. But beside the memory there are objects like for ex windows, files-handles, reg-handles, signaling stuff mutex's/semaphor's... you may also take care for and not to forget driver handles(of graphic or sound). Well unpacking is dealing just with dumping memory stuff and the more or less initialed API-imports - you don't deal with the rest. To create something to hibernate a Process can be a big undertake. But well maybe it's good to see how suspend / resume to RAM is done in detail to get some inspiration. Or that crashdump file *.dmp that contains the cpu state+stack of all threads
  12. #1 First of all please note that all the example above doesn't close the opened handle to the process. That'll be correctly: DllCall('kernel32.dll', 'ptr','CloseHandle', 'ptr',$ai_Handle[0]) #2 Second thing NtSuspendProcess and NtResumeProcess are undocumented functions - means that microsoft doesn't have them in their Win32-API documentation - >More[https://social.msdn.microsoft.com/forums/windowsdesktop/en-us/b5c5121c-bf48-47bd-b612-e2f61c5e5d82/ntsuspendprocess] A more 'official' way would be to use DebugActiveProcess(PID) + DebugSetProcessKillOnExit(0) and DebugActiveProcessStop(PID) to suspend or resume a process. See ->_ProcessSuspendResume2 in the following example (you'll maybe need to scroll down a little ) on how it's being used. #3 The direct use of literals like this ... 'OpenProcess', 'int', 0x1f0fff, ... is really ugly sloppy coding style - use constants or even better include them. Like this: #include <ProcessConstants.au3> ... 'OpenProcess', 'int', $PROCESS_ALL_ACCESS , ... it'll be much better readable. Okay now here it is a small usefull app to'll bring back the 'pause' key from the dos era into Windows. Pressing PAUSE will suspend the current active process(<= the currently active windows is running in ) Pressing PAUSE again will resume it. #include <WinAPI.au3> #include <ProcessConstants.au3> Func _ProcessSuspendResume($iPIDorName, $iSuspend = True) If IsString($iPIDorName) Then $iPIDorName = ProcessExists($iPIDorName) If Not $iPIDorName Then Return SetError(2, 0, 0) ; Consider using $PROCESS_SUSPEND_RESUME = 0x00000800 instead of $PROCESS_ALL_ACCESS Local $ai_Handle = _WinAPI_OpenProcess( $PROCESS_ALL_ACCESS, False, $iPIDorName ) ;Local $ai_Handle = DllCall("kernel32.dll", 'int','OpenProcess', 'int', 0x1f0fff, 'int',False, 'int',$iPIDorName)[0] ; Note: "NtSuspendProcess" is an undocumented API Local $i_sucess = DllCall("ntdll.dll","int","Nt" & ($iSuspend ? "Suspend" : "Resume") & "Process" _ ,"int",$ai_Handle) _WinAPI_CloseHandle($ai_Handle) ;DllCall('kernel32.dll', 'ptr','CloseHandle', 'ptr',$ai_Handle) If IsArray($i_sucess) Then Return 1 Return SetError(1, 0, 0) EndFunc ;==>_ProcessSuspendResume <-based on: http://autoitscript.com/forum/topic/32975-process-suspendprocess-resume-udf/ Func TogglePause() $g_bPaused = Not $g_bPaused ;~ $PIDorName = $TARGET_PROCESSNAME $PIDorName = WinGetProcess("[ACTIVE]") _ProcessSuspendResume($PIDorName, $g_bPaused) EndFunc ;==>TogglePause ; The more 'offical' & easy way (http://stackoverflow.com/a/11010508/3135511) Func _ProcessSuspendResume2($iPIDorName, $iSuspend = True) If IsString($iPIDorName) Then $iPIDorName = ProcessExists($iPIDorName) If Not $iPIDorName Then Return SetError(2, 0, 0) if $iSuspend then ;Note Opens Process with PROCESS_ALL_ACCESS DllCall('kernel32.dll','ptr','DebugActiveProcess','int',$iPIDorName) ; you may leave out DebugSetProcessKillOnExit; however then your supended App will also Exit when you quit this AutoIt App DllCall('kernel32.dll','ptr','DebugSetProcessKillOnExit','int',False) Else DllCall('kernel32.dll','ptr','DebugActiveProcessStop','int',$iPIDorName) EndIf EndFunc ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Global Const $APP_NAME = "Pause for Windows" Global Const $TARGET_PROCESSNAME = "Kingdom Rush.exe" ; Base on the 'HotKeySet' sample from the AutoIt help ; Press Esc to terminate script, Pause/Break to "pause" Global $g_bPaused = False HotKeySet("{PAUSE}", "TogglePause") HotKeySet("{ESC}", "Terminate") HotKeySet("+!h", "ShowMessage") ; Shift-Alt-h While 1 Sleep(100) WEnd Func Terminate() Exit EndFunc ;==>Terminate Func ShowMessage() MsgBox($MB_SYSTEMMODAL, APP_NAME & " - Help", "Press the >Pause< Key to your keyboard to suspend the current Process" & @CRLF & _ "(= the one whose windows is active)." & @CRLF & _ "Press >Pause< again to resume it.") EndFunc ;==>ShowMessage ^-Really neat for games like Kingdom rush that doesn't have a pause function (or like this one the pause hides too much of the gaming screen) or image you've a cpu intensive app like a packer that doesn't have a 'Pause' Key. Limitiations of code above: * Does take care for the case that you might change to another process * Alt+shift+h gives an error to fix move the 'Global Const $APP_NAME' just to the beginning Man what a stupid limitation why global's can be a the end or between functions? Anyway In the attached file I already fixed this (But for the post this gets somehow much overhead - since the focus should be here on supend/resume a process) _________________________________________________________________________________ Offtopic And one other thing I noticed it's about the Ternary-operator like this: "Nt" & ($iSuspend ? "Suspend" : "Resume") in the current AutoIT Help file it is not missing in the section that 'talks' about operator precedence.(autoit.chm::/html/intro/lang_operators.htm) PauseForWindows.au3
  13. I see it's blowing up da string exponentially now. Nice idea. I'll keep that idea for other languages. Its a little hard to see on the first glance - Maybe that will be a little better readable Func _StringRepeat($sString, $iRepeatCount) ; Casting Int() takes care of String/Int, Numbers. $iRepeatCount = Int($iRepeatCount) ; Zero is a valid repeat integer. If (StringLen($sString) < 1) Or _ ($iRepeatCount < 0) Then _ Return SetError(1, 0, "") ; Blow up string exponentially Local $sResult = "" While $iRepeatCount > 1 ; when RepeatCount is uneven; store rest in $sResult If mod($iRepeatCount, 2) Then $sResult &= $sString EndIf ; Concat string exponentially $sString &= $sString ; Next $iRepeatCount = int($iRepeatCount / 2) WEnd Return $sString & $sResult EndFunc ;==>_StringRepeat ^-I also took out that bit crafting stuff even if that might tiny slow down the function.
  14. Wow cool _StringRepeat that's it. Thanks. I actually looked how it's implementated: Func _StringRepeat($sString, $iRepeatCount) ;... For $iCount = 1 To $iRepeatCount $sResult &= $sString Next Return $sResult EndFunc So the core part is this: $sResult &= $sString Hmm I guess the operator '&=' on a string is already linked like to some kinda StringConcat. Anyway $sResult &= $sString is more nice than $sResult = $sResult & $sString. ...so I'll use that construct or _StringRepeat in future.
  15. Is there an other way like this: dim $myStringBuff=StringBuff(3) MsgBox(0, "StringBuff(5)=", $myStringBuff) ;------------------------------------------------- Func StringBuff( $size, $FillChar="0") Local $StringBuffer For $i = 1 To $size $StringBuffer = $StringBuffer & $FillChar Next Return $StringBuffer EndFunc to easily create a String in Autoit? Especially $StringBuffer = $StringBuffer & $FillChar is a really bad way to do so regarding the performance. (each time in the Loop a new string is created and the old one is discarded) Maybe something like this Local $StringBuffer[$size] For $i = 1 To $size $StringBuffer[$i] = $FillChar Next Return $StringBuffer ^-Sample Doesn't work ...or Local $StringBuffer For $i = 1 To $size _StringAppend($StringBuffer, $FillChar) Next Return $StringBuffer were '_StringAppend()' is some Interpreter optimised version that does some kind of redim to $StringBuffer and then append $FillChar
×
×
  • Create New...