Matt @ MPCS 0 Posted October 8, 2004 Share Posted October 8, 2004 I have been hiding this one from the public for a while due to its possible uses in virus writing. I know it isn't a complex function but I use it all the time in my scripts. It isn't perfect, but it does the job for me. Check it out! Func GetNextInSeq( $Path, $Prefix, $Suffix, $ShowZeros ) Local $i, $tmpMask, $strName If( $ShowZeros = 0 ) Then $ShowZeros = 3 EndIf If( StringRight( $Path, 1 ) <> "\" ) Then $Path = $Path & "\" EndIf $i = 0 While 1 $i = $i + 1 $strName = $Path & $Prefix & StringFormat( "%0" & $ShowZeros & "d", $i ) & $Suffix If Not FileExists( $strName ) Then Return $strName EndIf Wend EndFunc USAGE: DirCreate( GetNextInSeq( @TempDir, "Temp", "", 4 ) ) It returns the next available filename or directory in sequence in the directory specified. If you look through the code you will see the defualt $ShowZeros value is three. This means the number following the prefix will always be formatted "###", where # is an integer. Happy Posting! *** Matt @ MPCS Link to post Share on other sites
ezzetabi 4 Posted October 8, 2004 Share Posted October 8, 2004 Why do you fear virus writing from this? (BTW I think that if someone want to write virii indeed I should also be capable of make something like this already ) Link to post Share on other sites
Matt @ MPCS 0 Posted October 8, 2004 Author Share Posted October 8, 2004 Why do you fear virus writing from this?(BTW I think that if someone want to write virii indeed I should also be capable of make something like this already )<{POST_SNAPBACK}>After seeing the maturity level (and development skills) of some of the people out here, I don't really think they would be able to write such a UDF. I am not talking about everyone, mostly just the younger crowd. The reason I feared posting this is because I personally used a function similar to this when I was younger to write a replicating virus. I also have a UDF that generates random filenames... this I will never post as it has a more obvious malicious use. Thanks for the input though! *** Matt @ MPCS Link to post Share on other sites
upnorth 0 Posted October 9, 2004 Share Posted October 9, 2004 I also have a UDF that generates random filenames... this I will never post as it has a more obvious malicious use. Thanks for the input though! <{POST_SNAPBACK}>$my_random_filename = @HomeDrive & "\" & TimerInit ( ) & ".ass" Link to post Share on other sites
Matt @ MPCS 0 Posted October 9, 2004 Author Share Posted October 9, 2004 $my_random_filename = @HomeDrive & "\" & TimerInit ( ) & ".ass"<{POST_SNAPBACK}>It generates random character filenames... e.g. sdf3l5kj.file. TimerInit only returns an integer and it isn't random... therefore this is not a good way to enerate random filenames. It did however give me an idea as an addition to my current function. Thanks!*** Matt @ MPCS Link to post Share on other sites
ezzetabi 4 Posted October 9, 2004 Share Posted October 9, 2004 (edited) Too late:Long time ago ezzetabi made... Edited October 9, 2004 by ezzetabi Link to post Share on other sites
Matt @ MPCS 0 Posted October 9, 2004 Author Share Posted October 9, 2004 (edited) Too late:Long time ago ezzetabi made...<{POST_SNAPBACK}>I actually like that function better than mine, thanks. I still think it was a bad idea to post it. That's all we need is to give some of these moron's working code that helps them make more shit to attack my computer and give AutoIt a bad name... good goin'!*** Matt @ MPCSEDIT: Your function is good but I will be sticking with mine since it supports Upper/Lowercase letters, numbers (optional), and special characters (optional). it is still a good UDF.*** Matt @ MPCS Edited October 9, 2004 by Matt @ MPCS Link to post Share on other sites
ezzetabi 4 Posted October 9, 2004 Share Posted October 9, 2004 Just for you: Not fully tested, but it seems working. expandcollapse popupFunc _MattRandomText($iN, $iT) ;$iN is the lenght, it must be >0 ;$iT is a number to select what char do you want to see in it. (it can sum up) ; 1 Lowercase letters ; 2 Uppercase letters ; 4 Numbers ; 8 Special Ascii chars. ASCII numbers (in decimal) 32->47, 58->64, 91->96 and 123->126 ;so $iT must be >= 1 and <= 15 ;In case you ask for non valid arguments, a 0 is returned and @error is set to 1 Local $iN, $iT, $bType = '', $c, $sOutput = '', $c2 = 0, $iR, $sChar If $iN < 1 Or $iT < 1 Or $iT > 15 Then SetError(1) Return 0 EndIf While $iT > 0 If String(Mod($iT, 2)) = '1' Then $c2 = $c2 + 1 $bType = String(Mod($iT, 2)) & $bType $iT = Int($iT / 2) Wend While StringLen($bType) < 4 $bType = '0' & $bType Wend ;32 special chars ;16 7 6 3 -> 16 23 29 32 For $c = 1 To $iN $iR = Random(1, $c2 + 1) Select Case StringInStr($bType, '1', 0, -$iR) = 1 $iR = Int(Random(1, 34)) Select Case $iR >= 31 $sChar = Chr(Random(123, 127)) Case $iR >= 25 $sChar = Chr(Random(91, 97)) Case $iR >= 18 $sChar = Chr(Random(58, 65)) Case Else; >= 1 $sChar = Chr(Random(32, 48)) EndSelect Case StringInStr($bType, '1', 0, -$iR) = 2 $sChar = Chr(Random(48, 58)) Case StringInStr($bType, '1', 0, -$iR) = 3 $sChar = Chr(Random(65, 91)) Case StringInStr($bType, '1', 0, -$iR) = 4 $sChar = Chr(Random(97, 123)) EndSelect $sOutput = $sOutput & $sChar Next Return $sOutput EndFunc ;==>_MattRandomText Link to post Share on other sites
Matt @ MPCS 0 Posted October 10, 2004 Author Share Posted October 10, 2004 Just for you:Not fully tested, but it seems working.expandcollapse popupFunc _MattRandomText($iN, $iT) ;$iN is the lenght, it must be >0 ;$iT is a number to select what char do you want to see in it. (it can sum up) ; 1 Lowercase letters ; 2 Uppercase letters ; 4 Numbers ; 8 Special Ascii chars. ASCII numbers (in decimal) 32->47, 58->64, 91->96 and 123->126 ;so $iT must be >= 1 and <= 15 ;In case you ask for non valid arguments, a 0 is returned and @error is set to 1 Local $iN, $iT, $bType = '', $c, $sOutput = '', $c2 = 0, $iR, $sChar If $iN < 1 Or $iT < 1 Or $iT > 15 Then SetError(1) Return 0 EndIf While $iT > 0 If String(Mod($iT, 2)) = '1' Then $c2 = $c2 + 1 $bType = String(Mod($iT, 2)) & $bType $iT = Int($iT / 2) Wend While StringLen($bType) < 4 $bType = '0' & $bType Wend ;32 special chars ;16 7 6 3 -> 16 23 29 32 For $c = 1 To $iN $iR = Random(1, $c2 + 1) Select Case StringInStr($bType, '1', 0, -$iR) = 1 $iR = Int(Random(1, 34)) Select Case $iR >= 31 $sChar = Chr(Random(123, 127)) Case $iR >= 25 $sChar = Chr(Random(91, 97)) Case $iR >= 18 $sChar = Chr(Random(58, 65)) Case Else; >= 1 $sChar = Chr(Random(32, 48)) EndSelect Case StringInStr($bType, '1', 0, -$iR) = 2 $sChar = Chr(Random(48, 58)) Case StringInStr($bType, '1', 0, -$iR) = 3 $sChar = Chr(Random(65, 91)) Case StringInStr($bType, '1', 0, -$iR) = 4 $sChar = Chr(Random(97, 123)) EndSelect $sOutput = $sOutput & $sChar Next Return $sOutput EndFunc ;==>_MattRandomText<{POST_SNAPBACK}>No, no, no... don't do it that way far too much code. I won't post the code for maral reasons but in short it builds a string of possible characters and generates a random number to pick one from the sequence. The string starts out as "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" and then based on parameters passed I add the associated characters to the string. It does everything you do in those 50+ lines of code in under 20. If this doesn't make sense I may have to post it dispite my better judgement.*** Matt @ MPCS Link to post Share on other sites
ezzetabi 4 Posted October 10, 2004 Share Posted October 10, 2004 (edited) Nice idea indeed! But the point was not making a optimized code (I started the first thing it comes to my mind), but show you that I think you are 'thinking too much', if you have interesting code, post it. If anyone want to use it for non lawful purpuses it is not your fault, nor you have to worry about it. But many others will apreciate and use it 'well' for useful things. Edited October 10, 2004 by ezzetabi Link to post Share on other sites
ezzetabi 4 Posted October 10, 2004 Share Posted October 10, 2004 (edited) For example, just for your quick answer I saw the problem from an other point of view. And I could make a MattRandomText udf in an other way. Thanks to you I improved a little. So... Thanks 20 lines of code. I guess it is more or less like yours. Func _MattRandomText($iN, $iT) ; $iN is the lenght, it must be >0 ; $iT is a number to select what char do you want to see in it. (it can sum up) ; 1 Lowercase letters ; 2 Uppercase letters ; 4 Numbers ; 8 Special Ascii chars. ASCII numbers (in decimal) 32->47, 58->64, 91->96 and 123->126 ; so $iT must be >= 1 and <= 15 ; In the case you ask for non valid arguments, a 0 is returned. Local $iN, $iT, $bType, $sCharList = '', $c, $sOutput = '' If $iN < 1 Or $iT < 1 Or $iT > 15 Then Return 0 $iT = Int($iT) While $iT > 0 $bType = String(Mod($iT, 2)) & $bType $iT = Int($iT / 2) Wend While StringLen($bType) < 4 $bType = '0' & $bType Wend If StringMid($bType, 4, 1) = 1 Then $sCharList = $sCharList & 'abcdefghijklmnopqrstuvwxyz' If StringMid($bType, 3, 1) = 1 Then $sCharList = $sCharList & 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' If StringMid($bType, 2, 1) = 1 Then $sCharList = $sCharList & '0123456789' If StringMid($bType, 1, 1) = 1 Then $sCharList = $sCharList & ' !"#$%&''()*+,-./:;<=>?@[\]^_`{|}~' For $c = 1 To $iN $sOutput = $sOutput & StringMid($sCharList, Int(Random(1, StringLen($sCharList) + 1)), 1) Next Return $sOutput EndFunc ;==>_MattRandomText Edited October 10, 2004 by ezzetabi Link to post Share on other sites
ezzetabi 4 Posted October 10, 2004 Share Posted October 10, 2004 (edited) Your idea is indeed great. It can also modded with easy if needed: In few seconds you can alter _MattRandomText for having new conditions, or set of chars! E.g. expandcollapse popupFunc _MattRandomText($iN, $iT) ; $iN is the lenght, it must be >0 ; $iT is a number to select what chars appear in it. (it can sum up) ; ; 1 Lowercase letters ; 2 Uppercase letters ; 4 Numbers ; 8 Special Ascii chars. ; 16 Special extended Ascii chars - symbols ; 32 Special extended Ascii chars - non english letters lowcase ; 64 Special extended Ascii chars - non english letters uppercase ;128 Spaces ; ; so $iT must be >= 1 and <= 255 ; In the case you ask for non valid arguments, a 0 is returned. Local $iN, $iT, $bType = '', $sCharList = '', $c, $sOutput = '', $iL If $iN < 1 Or $iT < 1 Or $iT > 255 Then Return 0 $iT = Int($iT) While $iT > 0;It creates a binary number 'reversed' (the most significative digit is the last) $bType = $bType & String(Mod($iT, 2)) $iT = Int($iT / 2) Wend While StringLen($bType) < 8 $bType = $bType & '0' Wend ;So it can be used with easy with StringMid... If StringMid($bType, 1, 1) = 1 Then $sCharList = $sCharList & 'abcdefghijklmnopqrstuvwxyz' If StringMid($bType, 2, 1) = 1 Then $sCharList = $sCharList & 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' If StringMid($bType, 3, 1) = 1 Then $sCharList = $sCharList & '0123456789' If StringMid($bType, 4, 1) = 1 Then $sCharList = $sCharList & '!"#$%&''()*+,-./:;<=>?@[\]^_`{|}~' If StringMid($bType, 5, 1) = 1 Then $sCharList = $sCharList & '??????????????????????????? ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿÷×Þßþ' If StringMid($bType, 6, 1) = 1 Then $sCharList = $sCharList & 'àáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ' If StringMid($bType, 7, 1) = 1 Then $sCharList = $sCharList & 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝ' If StringMid($bType, 8, 1) = 1 Then $sCharList = $sCharList & ' ' $iL = StringLen($sCharList) + 1 For $c = 1 To $iN $sOutput = $sOutput & StringMid($sCharList, Int(Random(1, $iL)), 1) Next Return $sOutput EndFunc ;==>_MattRandomText Edit: the html is messing up the code, if you see many ???????? it is just a effect of extended ascii not shown correctly. Edited October 10, 2004 by ezzetabi Link to post Share on other sites
Matt @ MPCS 0 Posted October 10, 2004 Author Share Posted October 10, 2004 Your idea is indeed great. It can also modded with easy if needed:In few seconds you can alter _MattRandomText for having new conditions, or set of chars!E.g.expandcollapse popupFunc _MattRandomText($iN, $iT) ; $iN is the lenght, it must be >0 ; $iT is a number to select what chars appear in it. (it can sum up) ; ; 1 Lowercase letters ; 2 Uppercase letters ; 4 Numbers ; 8 Special Ascii chars. ; 16 Special extended Ascii chars - symbols ; 32 Special extended Ascii chars - non english letters lowcase ; 64 Special extended Ascii chars - non english letters uppercase ;128 Spaces ; ; so $iT must be >= 1 and <= 255 ; In the case you ask for non valid arguments, a 0 is returned. Local $iN, $iT, $bType = '', $sCharList = '', $c, $sOutput = '', $iL If $iN < 1 Or $iT < 1 Or $iT > 255 Then Return 0 $iT = Int($iT) While $iT > 0;It creates a binary number 'reversed' (the most significative digit is the last) $bType = $bType & String(Mod($iT, 2)) $iT = Int($iT / 2) Wend While StringLen($bType) < 8 $bType = $bType & '0' Wend ;So it can be used with easy with StringMid... If StringMid($bType, 1, 1) = 1 Then $sCharList = $sCharList & 'abcdefghijklmnopqrstuvwxyz' If StringMid($bType, 2, 1) = 1 Then $sCharList = $sCharList & 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' If StringMid($bType, 3, 1) = 1 Then $sCharList = $sCharList & '0123456789' If StringMid($bType, 4, 1) = 1 Then $sCharList = $sCharList & '!"#$%&''()*+,-./:;<=>?@[\]^_`{|}~' If StringMid($bType, 5, 1) = 1 Then $sCharList = $sCharList & '??????????????????????????? ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿÷×Þßþ' If StringMid($bType, 6, 1) = 1 Then $sCharList = $sCharList & 'àáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ' If StringMid($bType, 7, 1) = 1 Then $sCharList = $sCharList & 'ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝ' If StringMid($bType, 8, 1) = 1 Then $sCharList = $sCharList & ' ' $iL = StringLen($sCharList) + 1 For $c = 1 To $iN $sOutput = $sOutput & StringMid($sCharList, Int(Random(1, $iL)), 1) Next Return $sOutput EndFunc ;==>_MattRandomTextEdit: the html is messing up the code, if you see many ???????? it is just a effect of extended ascii not shown correctly.<{POST_SNAPBACK}>That looks a lot more similar to my function. I see your point in the we should post just to help those and assume everything is going to be fine... I will keep that in mind. Thanks! *** Matt @ MPCS Link to post Share on other sites
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now