Leaderboard
Popular Content
Showing content with the highest reputation on 03/04/2014 in all areas
-
GetOpt.au3 v1.3 If you've ever dabbled in C (or Python, Perl etc) then you might have heard of getopt() (Wiki entry). Well, I wrote this UDF to get that functionality into AutoIt. Some searching around here on the forum did turn up some other UDFs in this direction, but I decided to write my own port anyway and parallel the implementation in the C library. It's still missing a few things but on a whole it does the job really well. It's now pretty much complete. And I want to share it with you all. So here it is. If you want to handle the command line options passed to your script or program like a master, then this is the UDF for you! Main features: Parses DOS style options as well as GNU style options alike.Handles both short and long options.Define options that must have arguments when used.Define and handle suboptions (-s=foo,bar=quux,baz).Supports + and /- option modifiers.Casts string arguments to AutoIt variants, e.g. -a=yes becomes True.Easy access to any passed operand that's not an option.Some examples of invoking scripts: Script.au3 -a -b=10 --long-option file.txt Script.au3 /A /B:10 /Long-Option file.txtAs you see you can use both styles on the command line (as a matter of fact, at this moment you could even mix them but that wouldn't be good practice). In your script you just set the options you want to detect with _GetOpt_Set() and then iterate through each option with _GetOpt(). The 'file.txt' is available through _GetOpt_Oper(). See GetOpt-Example.au3 below for a step-by-step walkthrough of using GetOpt.au3. The UDF: GetOpt.au3 (+43) GetOpt-Example.au3: A demo of GetOpt.au3 #include <GetOpt.au3> #include <Array.au3> ; For demo purposes only. If 0 = $CmdLine[0] Then ; Create our own example command line. Run(FileGetShortName(@AutoItExe) & ' ' & FileGetShortName(@ScriptFullPath) & ' -a=no -b=42 -c=0.5 /Windows:' & @OSVersion & ' -z --required -s=foo,bar=quux,baz +p /-M -- -w=ignored Hello World!') Exit EndIf _GetOpt_Demo() Func _GetOpt_Demo() Local $sMsg = @ScriptName & ' for GetOpt v' & $GETOPT_VERSION & '.' & @CRLF & 'Parsing: ' & _ArrayToString($CmdLine, ' ', 1) & @CRLF & @CRLF; Message. Local $sOpt, $sSubOpt, $sOper ; Options array, entries have the format [short, long, default value] Local $aOpts[9][3] = [ _ ['-a', '--a-option', True], _ ['-b', '--b-option', False], _ ['-c', '--c-option', 'c option argument'], _ ['/W', '/Windows', 'windows style argument'], _ ; For demo purposes styles are mixed. ['-r', '--required', $GETOPT_REQUIRED_ARGUMENT], _ ; This option requires an argument. ['-s', '--suboption', $GETOPT_REQUIRED_ARGUMENT], _ ; option with suboptions. ['-p', '--plus', Default], _ ['/M', '/Minus', Default], _ ['-h', '--help', True] _ ] ; Suboptions array, entries have the format [suboption, default value] Local $aSubOpts[2][2] = [ _ ['foo', 47], _ ['bar', True] _ ] _GetOpt_Set($aOpts) ; Set options. If 0 < $GetOpt_Opts[0] Then ; If there are any options... While 1 ; ...loop through them one by one. ; Get the next option passing a string with valid options. $sOpt = _GetOpt('abcwr:s:pmh') ; r: means -r option requires an argument. If Not $sOpt Then ExitLoop ; No options or end of loop. ; Check @extended above if you want better error handling. ; The current option is stored in $GetOpt_Opt, it's index (in $GetOpt_Opts) ; in $GetOpt_Ind and it's value in $GetOpt_Arg. Switch $sOpt ; What is the current option? Case '?' ; Unknown options come here. @extended is set to $E_GETOPT_UNKNOWN_OPTION $sMsg &= 'Unknown option: ' & $GetOpt_Ind & ': ' & $GetOpt_Opt $sMsg &= ' with value "' & $GetOpt_Arg & '" (' & VarGetType($GetOpt_Arg) & ').' & @CRLF Case ':' ; Options with missing required arguments come here. @extended is set to $E_GETOPT_MISSING_ARGUMENT $sMsg &= 'Missing required argument for option: ' & $GetOpt_Ind & ': ' & $GetOpt_Opt & @CRLF Case 'a', 'b', 'c', 'w', 'p', 'm' $sMsg &= 'Option ' & $GetOpt_Ind & ': ' & $GetOpt_Opt $sMsg &= ' with value "' & $GetOpt_Arg & '" (' & VarGetType($GetOpt_Arg) & ')' If $GETOPT_MOD_PLUS = $GetOpt_Mod Then $sMsg &= ' and invoked with plus modifier (+' & $GetOpt_Opt & ')' ElseIf $GETOPT_MOD_MINUS = $GetOpt_Mod Then $sMsg &= ' and invoked with minus modifier (/-' & $GetOpt_Opt & ')' EndIf $sMsg &= '.' & @CRLF Case 'r' $sMsg &= 'Option ' & $GetOpt_Ind & ': ' & $GetOpt_Opt $sMsg &= ' with required value "' & $GetOpt_Arg & '" (' & VarGetType($GetOpt_Arg) & ')' If $GETOPT_MOD_PLUS = $GetOpt_Mod Then $sMsg &= ' and invoked with plus modifier (+' & $GetOpt_Opt & ')' ElseIf $GETOPT_MOD_MINUS = $GetOpt_Mod Then $sMsg &= ' and invoked with minus modifier (/-' & $GetOpt_Opt & ')' EndIf $sMsg &= '.' & @CRLF Case 's' $sMsg &= 'Option ' & $GetOpt_Ind & ': ' & $GetOpt_Opt $sMsg &= ' with required suboptions:' & @CRLF While 1 ; Loop through suboptions. $sSubOpt = _GetOpt_Sub($GetOpt_Arg, $aSubOpts) If Not $sSubOpt Then ExitLoop ; No suboptions or end of loop. ; Check @extended above if you want better error handling. ; The current suboption is stored in $GetOpt_SubOpt, it's index (in $GetOpt_SubOpts) ; in $GetOpt_SubInd and it's value in $GetOpt_SubArg. Switch $sSubOpt ; What is the current suboption? Case '?' $sMsg &= ' Unknown suboption ' & $GetOpt_SubInd & ': ' & $GetOpt_SubOpt $sMsg &= ' with value "' & $GetOpt_SubArg & '" (' & VarGetType($GetOpt_SubArg) & ').' & @CRLF Case 'foo', 'bar' $sMsg &= ' Suboption ' & $GetOpt_SubInd & ': ' & $GetOpt_SubOpt $sMsg &= ' with value "' & $GetOpt_SubArg & '" (' & VarGetType($GetOpt_SubArg) & ').' & @CRLF EndSwitch WEnd If $GETOPT_MOD_PLUS = $GetOpt_Mod Then $sMsg &= 'And invoked with plus modifier (+' & $GetOpt_Opt & ').' ElseIf $GETOPT_MOD_MINUS = $GetOpt_Mod Then $sMsg &= ' and invoked with minus modifier (/-' & $GetOpt_Opt & ')' EndIf Case 'h' MsgBox(0, 'GetOpt.au3', 'GetOpt.au3 example.' & @CRLF & _ 'Just try out some options and find out what happens!') Exit EndSwitch WEnd Else $sMsg &= 'No options passed.' & @CRLF EndIf $sMsg &= @CRLF If 0 < $GetOpt_Opers[0] Then ; If there are any operands... While 1 ; ...loop through them one by one. $sOper = _GetOpt_Oper() ; Get the next operand. If Not $sOper Then ExitLoop ; no operands or end of loop. ; Check @extended above if you want better error handling. $sMsg &= 'Operand ' & $GetOpt_OperInd & ': ' & $sOper & @CRLF WEnd Else $sMsg &= 'No operands passed.' & @CRLF EndIf MsgBox(0, @ScriptName, $sMsg) ; Let's see what we've got. _ArrayDisplay($GetOpt_Opts, '$GetOpt_Opts') _ArrayDisplay($GetOpt_Opers, '$GetOpt_Opers') _ArrayDisplay($GetOpt_ArgV, '$GetOpt_ArgV') Exit EndFunc Version 1.3: + Added support for -- (marks end of options). + Added support for + option modifiers e.g. +x. + Added support for /- option modifiers e.g. /-X. + Added _GetOpt_Sub to iterate through comma-separated suboptions like -s=a=foo,b=bar. * Changed $GETOPT_REQUIRED_ARGUMENT from keyword Default to Chr(127), keyword can now be used as an option argument. * Standardized comments and function headers. * Tidy-ed up source code. Version 1.2: + Support for required arguments with options, e.g. _GetOpt('ab:c') where -b=foo is valid and -b will return an error. + Added support for /C:foo (colon) when using DOS style. + Added optional auto-casting of arguments from Strings to AutoIt variants, e.g. -a=yes on the CLI would set the $GetOpt_Arg to True and not 'yes'. See __GetOpt_Cast. * Private __GetOpt_DOSToGNU to simplify code. Version 1.1: * Initial public release. If you encounter any bugs or have any suggestions, requests or improvements, then please let me know. Happy coding!1 point
-
Stopping a Label from going below 0 (Goes with my latest post)
gottygolly reacted to JLogan3o13 for a topic
Why not just add an If statement to keep it above 0? #include <GUIConstantsEx.au3> $hGUI = GUICreate("Test", 500, 500) $cLabel = GUICtrlCreateLabel("100", 10, 10, 400, 40) GUICtrlSetFont($cLabel, 24) $cButton_Add5 = GUICtrlCreateButton("Add 5", 10, 100, 80, 30) $cButton_Min10 = GUICtrlCreateButton("Minus 10", 110, 100, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton_Add5 GUICtrlSetData($cLabel, Number(GUICtrlRead($cLabel)) + 5) Case $cButton_Min10 If GUICtrlRead($cLabel) > 10 Then GUICtrlSetData($cLabel, Number(GUICtrlRead($cLabel)) - 10) Else GUICtrlSetData($cLabel, Number(0)) EndIf EndSwitch WEnd1 point -
Working around with Array for the 1st time
Palestinian reacted to BrewManNH for a topic
Don't use IniWrite if all you want to do is write the contents of the $sData variable to a file, use FileWrite instead. You say you know IniWrite works, and then demonstrate that you don't even need it. Actually, you don't even need to write the data to a file at all, you could use StringInStr on the $sData variable to see if the text you're looking for is there.1 point -
Working around with Array for the 1st time
Palestinian reacted to FireFox for a topic
Then post your code and reupload the file so I can see what's wrong1 point -
I wrote that over two years ago!1 point
-
Problem with a simple script, one change kills the script.
TheLandYacht reacted to JLogan3o13 for a topic
This works just fine for me on WIN7 x64, MyPhoneExplorer 1.8.5: Local $hWnd = WinWait("MyPhoneExplorer","") Sleep(1000) ControlSend($hWnd, "", "[CLASS:ToolbarWindow32]", "{F1}") ;Or ControlSend($hWnd, "", "[CLASS:ToolbarWindow32]", "{F2}") ;Or ControlSend($hWnd, "", "[CLASS:ToolbarWindow32]", "{F5}") ;Or ControlSend($hWnd, "", "[CLASS:ToolbarWindow32]", "+{F5}")1 point -
you stated though the instructions on the code you copied clearly stated you need to use the password as instructed when you log in. Why? $username = mysql_real_escape_string( $_POST['username'] ); $password = sha1( md5( PASSWORD_SALT ) . $_POST['password'] . PASSWORD_SALT); $query = "SELECT * FROM `{$db_table}` WHERE `username`='{$username}' AND `password`='{$password}'"; $username is not changed in any way (taken directly from the POST data and checked against the database) $password IS changed from the POST data, encrypted prior to being saved in the database (which stops people from getting into your database and stealing all the passwords - including YOU....) In other words, the 'fix' is for you to follow the instructions given and use 'test' as a password and NOT what you see in the database (and your 'abc' user will never be able to log in as the password of '123' is not properly encrypted, so you might as well delete it). If you want to add an account, add it using the AutoIt function and NOT directly in the database.1 point
-
Here is another approach. Local $arr1[2] ConsoleWrite("$arr1[2]" & @LF & _ArrayContains($arr1) & @LF) ConsoleWrite("==================" & @LF) Local $arr2[2][4] ConsoleWrite("$arr2[2][4]" & @LF & _ArrayContains($arr2) & @LF) ConsoleWrite("==================" & @LF) Local $arr3[2][4][3] ConsoleWrite("$arr3[2][4][3]" & @LF & _ArrayContains($arr3) & @LF) ConsoleWrite("==================" & @LF) Func _ArrayContains($arr) Local $sAns, $iVal, $iNumElem = 1, $aNumElem[UBound($arr, 0)] For $i = 1 To UBound($arr, 0) $iNumElem *= UBound($arr, $i) $aNumElem[$i - 1] = $iNumElem Next For $i = 0 To $iNumElem - 1 ;#1 $arr[0][0][0] --> 0 0 0 $sAns &= "#" & $i + 1 & @TAB & "arr" For $j = 1 To UBound($arr, 0) $iVal = Mod(Int($i / ($iNumElem / ($aNumElem[$j - 1]))), UBound($arr, $j)) $sAns &= "[" & $iVal & "]" Next $sAns = $sAns & " --> " For $j = 1 To UBound($arr, 0) $iVal = Mod(Int($i / ($iNumElem / ($aNumElem[$j - 1]))), UBound($arr, $j)) $sAns &= $iVal & " " Next $sAns &= @CRLF Next Return $sAns EndFunc ;==>_ArrayContains #cs ; Returns:- $arr1[2] #1 arr[0] --> 0 #2 arr[1] --> 1 ================== $arr2[2][4] #1 arr[0][0] --> 0 0 #2 arr[0][1] --> 0 1 #3 arr[0][2] --> 0 2 #4 arr[0][3] --> 0 3 #5 arr[1][0] --> 1 0 #6 arr[1][1] --> 1 1 #7 arr[1][2] --> 1 2 #8 arr[1][3] --> 1 3 ================== $arr3[2][4][3] #1 arr[0][0][0] --> 0 0 0 #2 arr[0][0][1] --> 0 0 1 #3 arr[0][0][2] --> 0 0 2 #4 arr[0][1][0] --> 0 1 0 #5 arr[0][1][1] --> 0 1 1 #6 arr[0][1][2] --> 0 1 2 #7 arr[0][2][0] --> 0 2 0 #8 arr[0][2][1] --> 0 2 1 #9 arr[0][2][2] --> 0 2 2 #10 arr[0][3][0] --> 0 3 0 #11 arr[0][3][1] --> 0 3 1 #12 arr[0][3][2] --> 0 3 2 #13 arr[1][0][0] --> 1 0 0 #14 arr[1][0][1] --> 1 0 1 #15 arr[1][0][2] --> 1 0 2 #16 arr[1][1][0] --> 1 1 0 #17 arr[1][1][1] --> 1 1 1 #18 arr[1][1][2] --> 1 1 2 #19 arr[1][2][0] --> 1 2 0 #20 arr[1][2][1] --> 1 2 1 #21 arr[1][2][2] --> 1 2 2 #22 arr[1][3][0] --> 1 3 0 #23 arr[1][3][1] --> 1 3 1 #24 arr[1][3][2] --> 1 3 2 ================== #ce1 point
-
Detefon, You appear to look for a magical in-depth iterator over elements of a multi-dimensionnal array giving you indices sequence for every entry. AutoIt doesn't offer that feature, so you must use nested For loops, which you said "and so on... but it is not smart..." The problem isn't being smart or not, it's about using the language features for what they can offer. BTW, _ArrayPermute and _ArrayCombinations are different unicorns entirely.1 point
-
Well, I'm not sure to really have understood... I still give you a code to generate all combinations from a muliti-dimensional array : #Include <Array.au3> Local $arr[2][3][4] $aCombinations = _Combinations($arr) _ArrayDisplay($aCombinations) Func _Combinations($aMyArray) Local $i = 0 Local $iCount = 1 While 1 $i += 1 $iLen = UBound($aMyArray, $i) If $iLen = 0 Then ExitLoop $iCount *= $iLen WEnd Local $aResult[$iCount] Local $iDims = $i - 1 Local $iSwap = $iCount Local $iIndex, $iVal For $i = 0 To $iDims - 1 $iSwap /= UBound($aMyArray, $i + 1) $iIndex = 0 $iVal = 0 For $j = 0 To $iCount - 1 If $iIndex = $iSwap Then $iIndex = 0 If $iVal = UBound($aMyArray, $i + 1) - 1 Then $iVal = 0 Else $iVal += 1 EndIf EndIf $aResult[$j] &= $iVal $iIndex += 1 Next Next Return $aResult EndFunc1 point
-
First read. Secondly, try to understand. Thirdly, apply to your own needs. Here you have next tip/hint: http://support.attachmate.com/techdocs/2164.html#API_Reference_Manuals http://download.attachmate.com/fileinfo.asp?filename=eb-samples.zip There is a excel.ebm file. It looks like Visual Basic witch use COM object (EXTRA! Personal Client 6.x (and derivatives)) Try to study it, and come back in a few days if you have further questions. EDIT: It looks easy to rewrite version of VisualBasic, on a version for AutoIt. EDIT2:4 http://docs.attachmate.com/reflection/2014/r1/help/en/vba-reference/1 point
-
I believe that shows the base very well, so I believe 'create a .php and .sql for check' has been addressed. I also believe the 'teach me' has been addressed in my addition of ideas/suggestions/etc that can make the base code more secure. Perhaps your 'teach me' means 'show me where I could do better in the code'. If so, you will find help here - by showing your code and asking for help in areas you get stuck. It seems, though, that your 'teach me' means more 'do it for me' - that is not going to happen, for multiple reasons including the fact that creating security for your product is best done yourself (through taking the ideas/hints/suggestions given in this thread). Certainly any code I create for security on my products will not be posted publicly and anyone that would post such would be wasting their time in creating it! So, this is an area where 'ask for help when you get stuck' is the best (and IMHO, only) approach to going further.1 point
-
kid1519, When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - we know what we wrote and it just pads the thread unneccessarily. M231 point
-
Sending a message to GUIGetMsg to simulate ComboBox selection change
SlowCoder74 reacted to BrewManNH for a topic
As I am sure you found out, or will find out after trying to run that, you shouldn't put an include in the middle of your script, and especially not inside a loop like that. Don't be penny wise and pound foolish, create your code inside functions, add the functions into your include files, put the #include lines at the top of your script. Use the function calls where needed. Right now, you're making it MUCH more difficult for yourself or anyone else to follow that spaghetti code 2 weeks down the road, let alone 2 years down the road.1 point -
MrKris1224, So you can play a trick on other people's machines? We are not going to help you do that - thread locked. M231 point
-
Not to bump the topic, but I was told privately that I wasn't being clear enough (not by anyone in this thread). Basically, when I say to subtract 256, this is mathematically the same as adding negative 256. And -256 is represented as this in hexadecimal: FFFF FFFF FFFF FF00 You can see clearly the last 8 bits are zeroes. Effectively, adding the above to any 8-bit value will leave the lower 8 bits changed; however, the interpretation of the number now becomes different. If the sign bit in the lower 8 bits was set, then what we just performed is sign-extension. Since AutoIt works with integers (32 or 64-bit), when we extract a non-floating point value from a structure, regardless of size, it is always either 32-bit or 64-bit integer. This is why you need to sign-extend. To show what happens, and that the lower 8 bits are left unchanged when -256 is added, run the following code: $stByte = DllStructCreate("byte;") DllStructSetData($stByte, 1, -50) $nVal = DllStructGetData($stByte, 1) ConsoleWrite("Value as read from DLLStruct = " & $nVal & @CRLF) ConsoleWrite(" Value -256 = " & $nVal - 256 & @CRLF) ConsoleWrite(" Value BitOR'd with -256 = " & BitOR(0xFFFFFF00, $nVal) & @CRLF) DllStructSetData($stByte, 1, $nVal) $nVal = DllStructGetData($stByte, 1) ConsoleWrite("Value read from DLLStruct again = " & $nVal & @CRLF)1 point
-
Identicon.au3 v0.8 A simple UDF to create identicons or visual representations of any hash value. Based on Don Park's original Identicon program. Main features: 3x3 and 4x4 grid patterns.Aside from rotational symmetry there are also checkerboard and Space Invader (mirror symmetry) patterns.Adapted to handle hashes up to SHA512.Save as PNG, JPG, GIF or BMP identicons.Alpha-transparency support for PNG.The UDF and a demo:Identicon.au3 Identicon-Demo.au3 Version 0.8: * Initial public release. To do: * In the checkerboard pattern there is a bias for diamond shapes. * Improve image saving, BMP, GIF and JPG suck, much artifacts and dithering. * Transparency doesn't work with GIF (and BMP?) due to the wrong Bitmap format. * Add some more unique sprite shapes and preferably cap the shape arrays at powers of two as BitAND is faster than a modulus operation.1 point
-
Run(...) and use @SW_MAXIMIZE as the show flag.1 point
-
$tBuffer = DllStructCreate('byte[8388608]') ; 8 MB $pBuffer = DllStructGetPtr($tBuffer) $iOffset = 0 ... If IsBinary($vRecv) Then DllStructSetData(DllStructCreate('byte[' & BinaryLen($vRecv) & ']', $pBuffer + $iOffset), 1, $vRecv) $iOffset += BinaryLen($vRecv) ContinueLoop EndIf ... $bBmp = DllStructGetData(DllStructCreate('byte[' & $iOffset & ']', $pBuffer), 1)1 point