Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 04/07/2015 in all areas

  1. The little assembly code posted >here by Tekk to count how many @LF there are in a string is very fast. It can be easly modified to count any other char instead of only a @LF in this way: #include <Memory.au3> Local $sString, $char For $i = 1 To 100000 $sString &= "This line is line " & $i & @CRLF Next $char = "i" MsgBox(0, 'Count of "' & $char & '"', 'There are ' & StringCountChar($sString, $char) & ' occurrences of the char "' & $char & '"') Func StringCountChar(ByRef $g_sString, $sCHR) Local $pCountLF = _MemVirtualAlloc(Null, 25, $MEM_COMMIT, $PAGE_EXECUTE_READWRITE) $sCHR = StringLeft($sCHR, 1) DllStructSetData(DllStructCreate("BYTE[25]", $pCountLF), 1, "0x" _ & "8B4C2404" _ ;~ mov ecx, dword[esp+04h] & "31C0" _ ;~ xor eax, eax & "8A11" _ ;~ @@:mov dl, byte[ecx] & "80FA00" _ ;~ cmp dl, 00h & "7409" _ ;~ je @f & "41" _ ;~ inc ecx & "80FA" & Hex(Asc($sCHR), 2) _ ;~ cmp dl, NNh <-- modified here & "75F3" _ ;~ jne @b & "40" _ ;~ inc eax & "EBF0" _ ;~ jmp @b & "C20400" _ ;~ @@:ret 4 ) Local $nResult = DllCallAddress("INT", $pCountLF, "STR", $g_sString)[0] _MemVirtualFree($pCountLF, 0, $MEM_RELEASE) Return $nResult EndFunc ;==>StringCountChar That's all. edit: added ByRef to $g_sString in function
    1 point
  2. Remove the "And" Global $sNum = Random(1, 4, 1) & "E" Switch $sNum Case "1E","2E" MsgBox(64, "TEST", "1E or 2E") Case "3E", "4E" MsgBox(64, "TEST", "3E or 4E") EndSwitch MsgBox(64, "TEST", "The number was: " & $sNum)
    1 point
  3. @Sorry: You mean in the function declaration, like func _myFunc($param1, $param2 = "") ? No, it does not mean only accept strings, it means that the parameter is optional, and that if you do not supply it, the default value is an empty string. Try this example: _myFunc("test") _myFunc("test", "something") func _myFunc($param1, $param2 = "default value") msgbox(0, 0, "Param 1: " & $param1 & @CRLF & "Param 2: " & $param2) EndFunc
    1 point
  4. jchd

    REGEX help

    This useful site explains it all thusly: /(?mx) ^ ; \s+ (\w+) \s+ = \s+ (.+) $/ (?mx) Match the remainder of the pattern with the following options: m modifier: multi-line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string) x modifier: extended. Spaces and text after a # in the pattern are ignored ^ assert position at start of a line ; matches the character ; literally \s+ match any white space character [\r\n\t\f ] Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy] 1st Capturing group (\w+) \w+ match any word character [a-zA-Z0-9_] Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy] \s+ match any white space character [\r\n\t\f ] Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy] = matches the character = literally \s+ match any white space character [\r\n\t\f ] Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy] 2nd Capturing group (.+) .+ matches any character (except newline) Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy] $ assert position at end of a line
    1 point
  5. susserj

    Encrypt_It

    Hi I've created this script and thought it might be useful to others. Basically, it encrypts selected text with the hot key <ctr><alt>e and then one can un-encrypts the text using the hot key <ctrl><alt>v. This script might be useful when sending an email to someone while needing a minimum level of privacy.The other person would need the executable, of course, and the compiled passwords would need to be the same. I've tested it with Windows7 64 bit. It works most of the time. It was a little flaky but I think it's OK now. Just be sure that you are on a windows screen that allows editing before envoking the hot keys or you might get a nasty surprise. Cheers #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.12.0 Script Name: Encrypt_IT Version: 1.3 Author: Joel Susser Last Modifed: 06/04/2015 Description: This script Encrypts selected text. This program is ideal for sending encrypted text through normal emails. - To activate program run the Executable Encrypt_it.exe - To Encrypt Text, Select the Text and type <ctr><alt><e> - To Un-Encrypt Text, Select Text wrapped with <<encrypt_on>><encrypt_off> Tags and then type <ctr><Alt><u> - To Exit application, close it in the system tray. Update functionalty: -Fixed a logic bug -Added error checking for empty selection or missing tags -Added a function to just view encrypted text (It doeesn't replace the text) -Added scrowlable msgbox using Form and Edit Field Example Encrypted Message: <encrypt_on>0xAC974253127B228E1E5C87259AE31C22FF44723C24CB817D89E2206D7AE75BAC0A5B<encrypt_off> #ce ---------------------------------------------------------------------------- $hWnd = WinGetHandle("[ACTIVE]", "") ;get handle of current window WinActivate ( $hWnd ) ;active current window by handle #include <MsgBoxConstants.au3> #include <Crypt.au3> #include <String.au3> #include <Clipboard.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> const $sPassword = "password" ;should be changed. Global $g_bPaused = False ;probably not needed. Global $sData = "" ;initalize data storage variable to "" Global $Encrypted = "" ;initalize encrypted variable to "" ;setup hotkeys HotKeySet("^!e", "Encrypt"); <ctrl><alt>e HotKeySet("^!u", "UnEncrypt_replace"); <ctrl><alt>u HotKeySet("^!v", "UnEncrypt_view"); <ctrl><alt>v ;HotKeySet("{ESC}", "Terminate") ; Press Esc to terminate script ;create main loop to check for hotkeys While 1 Sleep(100) WEnd Func Terminate() Exit EndFunc ;==>Terminate Func Encrypt() $hWnd = WinGetHandle("[ACTIVE]", "") ;active handle of windows that selection was made on when hot key pressed WinActivate ( $hWnd ) WinActive ($hWnd) send("^c") ;copy selected text to clipboard ;send("{CTRLDOWN}c{CTRLUP}") sleep(1000);wait for selection to complete ;consolewrite($sData & @CRLF) ;wait for selection to complete ;$sData = ClipGet() $sData =_ClipBoard_GetData ( $CF_TEXT ) ;convert clipboard data to pure text and move it to $sData variable If Check_Unencrypted_Data_Good($sData) Then ;MsgBox($MB_SYSTEMMODAL, "", $sData) $Encrypted = _Crypt_EncryptData($sData, $sPassword, $CALG_RC4) ; encrypt $sData data and move it to $Encrypted ;MsgBox($MB_SYSTEMMODAL, '', $Encrypted) $sData = "<encrypt_on>" & $Encrypted & "<encrypt_off>" ClipPut($sData) ;put $encrypted data back into cliboaard WinActivate ( $hWnd ) ;active windows by handle WinActive ($hWnd) ;wait for window to be active send("^v") ;send clipboard data to screen via <ctr>v command sleep(1000) ;wait for clipboard push to completd ClipPut("");clear clipboard ;clear the clipboard EndIf EndFunc Func UnEncrypt_replace() $hWnd = WinGetHandle("[ACTIVE]", "") ;active handle of windows that selection was made on when hot key pressed WinActivate ( $hWnd ) ;active window by handle WinActive ($hWnd) send("^c") ;send clipboard data to screen ;send("{CTRLDOWN}c{CTRLUP}") sleep(1000) $sData = ClipGet() ;consolewrite($sData & @CRLF) if Check_if_Properly_Tagged($sData) then ;$sData =_ClipBoard_GetData ( $CF_TEXT ) ;convert clipboard data to pure text and put it in $sData variable $aArray=_StringBetween($sData,'<encrypt_on>','<encrypt_off>');remove tags $Encrypted = $aArray[0] ;MsgBox($MB_SYSTEMMODAL, "", $Encrypted) sleep(500) $sData = BinaryToString( _Crypt_DecryptData($Encrypted, $sPassword, $CALG_RC4)) ; de-crypt data ; MsgBox($MB_SYSTEMMODAL, "", $sData) ClipPut($sData) ;put data collected in clipboard send("^v") ;send clipboard to screen ; send("{CTRLDOWN}v{CTRLUP}") sleep(1000) ;wait for completion ClipPut("") ;clear clipboard ;MsgBox($MB_SYSTEMMODAL, "", "UnEncrypting") EndIf EndFunc Func UnEncrypt_view() $hWnd = WinGetHandle("[ACTIVE]", "") ;active handle of windows that selection was made on when hot key pressed WinActivate ( $hWnd ) ;active window by handle WinActive ($hWnd) send("^c") ;send clipboard data to screen ; send("{CTRLDOWN}c{CTRLUP}") sleep(1000) $sData = ClipGet() ;consolewrite($sData & @CRLF) ;$sData =_ClipBoard_GetData ( $CF_TEXT ) ;convert clipboard data to pure text and put it in $sData variable if Check_if_Properly_Tagged($sData) then $aArray=_StringBetween($sData,'<encrypt_on>','<encrypt_off>');remove tags $Encrypted = $aArray[0] ;MsgBox($MB_SYSTEMMODAL, "", $Encrypted) sleep(500) $sData = BinaryToString( _Crypt_DecryptData($Encrypted, $sPassword, $CALG_RC4)) ; de-crypt data ; MsgBox($MB_SYSTEMMODAL, "", $sData) MsgBox_Scroll("Un-Encrypt Text", $sData) endif ClipPut("") ;clear clipboard ;MsgBox($MB_SYSTEMMODAL, "", "UnEncrypting") EndFunc ;custom scrollable message box func MsgBox_scroll($title, $text) $Form1 = GUICreate($title, 623, 436, 192, 132) $Edit1 = GUICtrlCreateEdit("", 8, 0, 593, 433) GUICtrlSetData(-1, $text) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ;Exit GUIDelete ( $Form1 ) ExitLoop EndSwitch WEnd EndFunc ;check if cliboard is blank. If yes, there is a problem. func Check_Unencrypted_Data_Good($sData) if $sData = "" Then MsgBox($MB_SYSTEMMODAL,"Error", "No Text Selected for Encryption") return False Else Return True EndIf EndFunc ;check if clipboard data has the closing and starting tags. If not, there is a problem. func Check_if_Properly_Tagged($sData) if ( StringInStr($sData, "<encrypt_on>") And StringInStr($sData, "<encrypt_off>") ) Then return True Else MsgBox($MB_SYSTEMMODAL,"Error", "Missing Encyption Tag") return false EndIf EndFunc
    1 point
  6. Yes. But without the false BOM information.
    1 point
  7. ha yes, you are right, now it works, thanks mikell here a new race with the new competitor p.s. (chimp has retired from competition. Disqualified! ) #include <array.au3> #include <Memory.au3> Local $sString, $hTimer, $aCompetitors[7][2] = [ _ ["Melba23 ", 0], _ ["Mikell ", 0], _ ["Mikell 2 ", 0], _ ["SadBunny ", 0], _ ["Malkey ", 0], _ ["jchd ", 0], _ ["Tekk ", 0]] For $i = 1 To 100000 $sString &= "This line is line " & $i & @CRLF Next $hTimer = TimerInit() StringReplace($sString, @LF, "") $a = @extended Stopwatch(0, $hTimer, $aCompetitors) ConsoleWrite(StringFormat("%-20s", $aCompetitors[0][0]) & @TAB & $aCompetitors[0][1] & " secs" & @TAB & $a & @CRLF) $a = StringSplit($sString, @LF)[0] - 1 Stopwatch(1, $hTimer, $aCompetitors) ConsoleWrite(StringFormat("%-20s", $aCompetitors[1][0]) & @TAB & $aCompetitors[1][1] & " secs" & @TAB & $a & @CRLF) $a = UBound(StringRegExp($sString, @LF, 3)) Stopwatch(2, $hTimer, $aCompetitors) ConsoleWrite(StringFormat("%-20s", $aCompetitors[2][0]) & @TAB & $aCompetitors[2][1] & " secs" & @TAB & $a & @CRLF) $a = StringLen(StringRegExpReplace($sString, "[^\n]", "")) Stopwatch(3, $hTimer, $aCompetitors) ConsoleWrite(StringFormat("%-20s", $aCompetitors[3][0]) & @TAB & $aCompetitors[3][1] & " secs" & @TAB & $a & @CRLF) $a = StringLen(StringAddCR($sString)) - StringLen($sString) Stopwatch(4, $hTimer, $aCompetitors) ConsoleWrite(StringFormat("%-20s", $aCompetitors[4][0]) & @TAB & $aCompetitors[4][1] & " secs" & @TAB & $a & @CRLF) StringRegExpReplace($sString, "\n", "\n") $a = @extended Stopwatch(5, $hTimer, $aCompetitors) ConsoleWrite(StringFormat("%-20s", $aCompetitors[5][0]) & @TAB & $aCompetitors[5][1] & " secs" & @TAB & $a & @CRLF) $a = StringCountLF($sString) Stopwatch(6, $hTimer, $aCompetitors) ConsoleWrite(StringFormat("%-20s", $aCompetitors[6][0]) & @TAB & $aCompetitors[6][1] & " secs" & @TAB & $a & @CRLF) _ArraySort($aCompetitors, 0, 0, 0, 1) _ArrayDisplay($aCompetitors, "Results") Func Stopwatch($iCompetitor, ByRef $hTimer, ByRef $aCompetitors) $aCompetitors[$iCompetitor][1] = Round(TimerDiff($hTimer) / 1000, 5) $hTimer = TimerInit() EndFunc ;==>Stopwatch Func StringCountLF($g_sString) Local $pCountLF = _MemVirtualAlloc(Null, 25, $MEM_COMMIT, $PAGE_EXECUTE_READWRITE) DllStructSetData(DllStructCreate("BYTE[25]", $pCountLF), 1, "0x" _ & "8B4C2404" _ ;~ mov ecx, dword[esp+04h] & "31C0" _ ;~ xor eax, eax & "8A11" _ ;~ @@:mov dl, byte[ecx] & "80FA00" _ ;~ cmp dl, 00h & "7409" _ ;~ je @f & "41" _ ;~ inc ecx & "80FA0A" _ ;~ cmp dl, 0Ah & "75F3" _ ;~ jne @b & "40" _ ;~ inc eax & "EBF0" _ ;~ jmp @b & "C20400" _ ;~ @@:ret 4 ) Local $nResult = DllCallAddress("INT", $pCountLF, "STR", $g_sString)[0] _MemVirtualFree($pCountLF, 0, $MEM_RELEASE) Return $nResult EndFunc
    1 point
  8. Or... $sString = "Line 1" & @LF & "Line 2" & @LF & "Line 3" MsgBox(0, 0, StringLen(StringRegExpReplace($sString, "[^\n]", ""))) ; replace everything that is not a linefeed by an empty string, then shows the length of the resulting string
    1 point
  9. MsgBox($MB_SYSTEMMODAL, "Count", StringSplit($sString, @LF)[0]-1) Edit of course if you absolutely want a regex... MsgBox($MB_SYSTEMMODAL, "Count", UBound(StringRegExp($sString, @LF, 3)))
    1 point
  10. kcvinu, No. Just use StringReplace and see what is returned in @extended: #include <MsgBoxConstants.au3> $sString = "Line 1" & @LF & "Line 2" & @LF & "Line 3" StringReplace($sString, @LF, "") MsgBox($MB_SYSTEMMODAL, "Count", @extended) M23
    1 point
  11. working example: ; Initialize COM error handler $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") $objHTTP = ObjCreate("Microsoft.XMLHTTP") $objReturn = ObjCreate("Msxml2.DOMdocument.3.0") ; Create the SOAP Envelope $strEnvelope = "" & _ '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:even="http://events.dpdinfoservices.dpd.com.pl/">' & _ ' <soapenv:Header/>' & _ ' <soapenv:Body>' & _ ' <even:getEventsForCustomerV1>' & _ ' <limit>10</limit>' & _ ' <authDataV1>' & _ ' <channel>clientChannel</channel>' & _ ' <login>user</login>' & _ ' <password>userPassword</password>' & _ ' </authDataV1>' & _ ' </even:getEventsForCustomerV1>' & _ ' </soapenv:Body>' & _ '</soapenv:Envelope>' $objHTTP.Open('POST', 'http://dpd.com.pl/common/service/LoginService/2.0/getAuth', False) ; Make the SOAP call $objHTTP.send () ; Get the return envelope $strReturn = $objHTTP.responseText ConsoleWrite("Return : " & @CR & $strReturn & @CR & @CR) Func MyErrFunc() $HexNumber=hex($oMyError.number,8) ConsoleWrite("We intercepted a COM Error !" & @CRLF & @CRLF & _ "err.description is: " & @TAB & $oMyError.description & @CRLF & _ "err.windescription:" & @TAB & $oMyError.windescription & @CRLF & _ "err.number is: " & @TAB & $HexNumber & @CRLF & _ "err.lastdllerror is: " & @TAB & $oMyError.lastdllerror & @CRLF & _ "err.scriptline is: " & @TAB & $oMyError.scriptline & @CRLF & _ "err.source is: " & @TAB & $oMyError.source & @CRLF & _ "err.helpfile is: " & @TAB & $oMyError.helpfile & @CRLF & _ "err.helpcontext is: " & @TAB & $oMyError.helpcontext & @CRLF & _ "" _ ) SetError(1) ; to check for after this function returns Endfunc
    1 point
×
×
  • Create New...