Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 10/09/2014 in all areas

  1. Melba23

    New MVPs

    In case you had not noticed we have a new MVP, czardas. I am sure you will all join me in congratulating him on his new status. M23
    7 points
  2. No you are right, but you have to read past that FAQ (it was written when the UDF was originally posted). >Post #202 Many more examples in the >Access AutoIt thread
    2 points
  3. trancexx

    Access AutoIt

    Majority of users of AutoIt language likes it because it's easy to learn and very powerful when it comes to automating some basically very complicated stuff on windows. AutoIt often does it in just one line of code while doing it in other languages would be writing a full book of code. How to use AutoIt with other languages? One way would be to use AutoItX. Dll version of AutoIt. In this case you can access it through COM or exported functions. Downside surely is limited number of available functions and user rights for COM option. Other way is... no wait, there is no other way. But, what If I add some magic salt to the soup? Let's say I use some of the code from (thanks Manadar) and, yes you guessed AutoItObject, and make a simple (the most basic) COM server that exports almost the whole AutoIt functionality to anyone wanting to use it. AutoItObject 1.2.8.0 makes objects published to ROT (running object table) more accessible than ever. Accessing the object is as easy as GetObject(...) in any scripting language and CoGetObject() through Windows API. An example of VBS would be: Javascript could be: C# PowerShell (based on ptrex's example) Python (AdmiralAlkex) ...and so on. Server script is really minimalistic: All packed in ZIP: AccessAutoIt.zip What you'll find there is folder named AccessAutoIt. Unzip it somewhere and inside there will be five files: AutoItObject.au3 (1.2.8.0), AutoItServer.au3, Csharp.cs, JS.js and VBS.vbs. Run AutoItServer.au3 and then either vbs or js script or compile Csharp.cs and run resulting executable. I have chosen AutoIt.Application object moniker for no particular reason. Can be anything. Latest AutoItObject, if you want the whole thing, is here. AutoIt on your palm. edit: Added c# example. Don't mind about my usage of other languages. I'm not quite familiar with them.
    1 point
  4. Ward

    LZMA Compression UDF

    How to compress data in memory? The simplest way is to use the Native API Compression by trancexx. Here provides another way, using LZMA algorithm. LZMA is the default method of 7z format, provides a high compression ratio and very fast decompression. In this UDF, embedded and external DLL are both supported. If "LZMA.DLL.AU3" (embedded binary) is not included in scripts, a external LZMA.DLL must exists. You can use external DLL if MemoryDll is not work for you. Some tips: Both LzmaEnc and LzmaDec only accept binary arguments. To compress string, StringToBinary and BinaryToString can help.LzmaEnc can accept an extra argument, the comression level, from 1 to 9. For example: LzmaEnc($Binary, 9)More settings are support by LzmaEncSetting, please see LZMA SDK.This UDF is not for file compression. To compress files, 7-ZIP UDF is the better choiceExample: #include "LZMA.AU3" #include "LZMA.DLL.AU3" Local $Source = Binary("LZMALZMALZMALZMALZMALZMALZMALZMALZMALZMA") Local $Compressed = LzmaEnc($Source) Local $Decompressed = LzmaDec($Compressed) LZMA.zip
    1 point
  5. czardas

    ORfuscator

    ORfuscate your script. I'm not sure if this exists, but it is intended as a pre-obfuscation tool. It might be a new invention! While it does not guarantee any protection by itself, ORfuscation does offer some benefit in certain situations. It's more useful in cases where knowing the original numbers is essential to fully understand a script. In other cases it's just adds a slight inconvenience to the reverse engineer due to superflous internal routines. You may wish to convert globals to magic numbers before ORfuscation. I believe PreExpand by guinness will do this. Additional features such as creating fake constants may be included in a future release. Please do not post ORfuscated scripts on the forum. You may post them in this thread if it is relevant to the topic or provides an interesting example. Please double check to make sure that your scripts are still functional after ORfuscation. The example at the end of the script (lines 236 onwards) should be removed before testing with your own script. ; ; #FUNCTION# ==================================================================================================================== ; Name...........: ORfuscate ; Description ...: Refactorization of magic numbers, 32-bit integers and hard coded BitOR() arguments. ; Syntax.........: ORfuscate($sScript) ; Parameters ....: $sScript - String input of an AutoIt script. ; Return values .: Success - Returns the orfuscated script. ; Failure - Returns the original script and sets @error to the following values: ; |@error = 1 : Script contains no data. ; |@error = 2 : No suitable separators found (this should not happen). ; Author ........: czardas ; Modified.......: ; Remarks .......: This is an experimental project with very little testing - so use at your own risk. ; Link ..........: ; Example .......: ; =============================================================================================================================== Func ORfuscate($sScript) If $sScript = "" Then Return SetError(1, 0, "") ; Get suitable padding to separate strings, comments and directives from the AutoIt. Local $iCount = 63743 ; BMP Private Range Upper Limit $sScript &= @LF Local $sIgnoreOn = " " & __GetSubstitute($sScript, $iCount) & " " ; Spaces are used for extra padding. If @error Then Return SetError(2, 0, $sScript) Local $sIgnoreOff = " " & __GetSubstitute($sScript, $iCount) & " " If @error Then Return SetError(2, 0, $sScript) Local $bIsAutoIt = True, _ ; The current position is outside strings, comments and directives. $sNotAutoIt = "", _ ; Strings, comments or directives to avoid. $sExpected = "", _ ; Regexp pattern to match the termination of a string, comment or directive. $sNextChar, $sNewAutoIt = "" ; Identify strings, comments and directives. For $i = 1 To StringLen($sScript) $sNextChar = StringMid($sScript, $i, 1) If $bIsAutoIt Then If StringRegExp($sNextChar, '[#''";]') Then $sNewAutoIt &= $sIgnoreOn & $sNextChar $bIsAutoIt = False Switch $sNextChar Case "#" $sExpected = StringRegExp(StringMid($sScript, $i, 4), "(?:)(#cs\b)") ? "(?:)([\r\n]\h*#ce\b.*\v)" : "\v" Case "'" $sExpected = "'" Case """" $sExpected = """" Case ";" $sExpected = "\v" EndSwitch Else $sNewAutoIt &= $sNextChar EndIf Else $sNotAutoIt &= $sNextChar If StringRegExp($sNotAutoIt, $sExpected) Then $sNewAutoIt &= $sNotAutoIt & $sIgnoreOff $bIsAutoIt = True $sExpected = "" $sNotAutoIt = "" EndIf EndIf Next ; Split the script to reveal 32-bit integers, Bitwise-OR'ed integers and also capture the rest of the code. Local $aAutoIt = StringRegExp($sNewAutoIt, "(?i)(?s)(?U)(" & $sIgnoreOn & ".+" & $sIgnoreOff & ")|\b\d*\.\d+\b|\b\d*\.?\d+e[\+\-]?\d+\b|(?<=[\s=,/\Q[(+-*^?:\E])(\d+|0x[A-F0-9]+|BitOR\h*\([x\h0-9,A-F]+\))(?=[\s=,/\Q)]+-*^?:\E])|\$*\b\w+\b|.", 3) ; Search for integers Local $iBound = UBound($aAutoIt), $iInt32, $sIdx = "" For $i = 0 To $iBound -1 $iInt32 = "" If StringIsInt($aAutoIt[$i]) Or StringRegExp($aAutoIt[$i], "(?i)(\A0x[A-F\d]{1,8}\z)") Or StringRegExp($aAutoIt[$i], "(?i)(BitOR\h*\([x\h\d,A-F]+\))") Then $iInt32 = Execute($aAutoIt[$i]) If VarGetType ($iInt32) <> "Int32" Then ContinueLoop $aAutoIt[$i] = $iInt32 $sIdx &= $i & "," Next If Not $sIdx Then Return SetExtended(1, $sScript) ; No changes can be made Local $aIdx = StringSplit(StringTrimRight($sIdx, 1), ",", 2) Local $iBoundIdx = Ubound($aIdx) Local $aSplit, $aMagic[$iBoundIdx][2][3] For $i = 0 to $iBoundIdx -1 $aSplit = MagicSplit($aAutoIt[$aIdx[$i]]) $aMagic[$i][0][0] = $aSplit[0] ; 1st int $aMagic[$i][1][0] = $aSplit[1] ; 2nd int $aSplit = MagicSplit($aMagic[$i][0][0]) $aMagic[$i][0][1] = $aSplit[0] ; 1st int - 1st element $aMagic[$i][0][2] = $aSplit[1] ; 1st int - 2nd element $aSplit = MagicSplit($aMagic[$i][1][0]) $aMagic[$i][1][1] = $aSplit[0] ; 2nd int - 1st element $aMagic[$i][1][2] = $aSplit[1] ; 2nd int - 2nd element Next ;_WalkThrough3D($aMagic, "zx") Local $sCheckDupes For $i = 0 to $iBoundIdx -1 If $aMagic[$i][0][0] = 0 Then If $aMagic[$i][1][1] = 0 Or $aMagic[$i][1][2] = 0 Then $aAutoIt[$aIdx[$i]] = MagicFormat($aAutoIt[$aIdx[$i]]) Else $aAutoIt[$aIdx[$i]] = "BitOR(" & MagicFormat($aMagic[$i][1][1]) & ", " & MagicFormat($aMagic[$i][1][2]) & ")" EndIf ElseIf $aMagic[$i][1][0] = 0 Then If $aMagic[$i][0][1] = 0 Or $aMagic[$i][0][2] = 0 Then $aAutoIt[$aIdx[$i]] = MagicFormat($aAutoIt[$aIdx[$i]]) Else $aAutoIt[$aIdx[$i]] = "BitOR(" & MagicFormat($aMagic[$i][0][1]) & ", " & MagicFormat($aMagic[$i][0][2]) & ")" EndIf ElseIf Random(0, 1, 1) Then $aAutoIt[$aIdx[$i]] = "BitOR(" $sCheckDupes = "|" For $j = 0 To 1 For $k = 1 To 2 If $aMagic[$i][$j][$k] <> 0 And Not StringInStr($sCheckDupes, "|" & $aMagic[$i][$j][$k] & "|") Then $aAutoIt[$aIdx[$i]] &= MagicFormat($aMagic[$i][$j][$k]) & ", " $sCheckDupes &= $aMagic[$i][$j][$k] & "|" EndIf Next Next $aAutoIt[$aIdx[$i]] = StringTrimRight($aAutoIt[$aIdx[$i]], 2) & ")" ElseIf $aMagic[$i][0][0] <> $aMagic[$i][1][0] Then $aAutoIt[$aIdx[$i]] = "BitOR(" & MagicFormat($aMagic[$i][0][0]) & ", " & MagicFormat($aMagic[$i][1][0]) & ")" Else $aAutoIt[$aIdx[$i]] = MagicFormat($aAutoIt[$aIdx[$i]]) EndIf Next $sScript = "" For $i = 0 To $iBound -1 $sScript &= $aAutoIt[$i] Next $sScript = StringReplace($sScript, $sIgnoreOn, "") $sScript = StringReplace($sScript, $sIgnoreOff, "") $sScript = StringTrimRight($sScript, 1) ; Remove LF added at the start Return $sScript EndFunc Func XORSplit($i32Bit) ; Splits an integer into two randomly selected bitwise exclusive integers. If Not IsInt($i32Bit) Or $i32Bit >= 2^32 Or $i32Bit < 0x80000000 Then Return SetError(1, 0, 0) Local $aXOR[2] $aXOR[0] = 0 ; Randomly select which bits to reproduce in the first return value. => $aXOR[0] Local $iBitPos For $i = 0 To 31 $iBitPos = 2^$i If BitAND($i32Bit, $iBitPos) = $iBitPos And Random(0, 1, 1) Then $aXOR[0] = BitOR($aXOR[0], $iBitPos) Next ; Check the sign bit. If BitAND($i32Bit, 0x80000000) = 0x80000000 And Random(0, 1, 1) Then $aXOR[0] = BitOR($aXOR[0], 0x80000000) ; Exclude the bits set to one (in the first return value) from the original input. $aXOR[1] = BitXOR($i32Bit, $aXOR[0]) Return $aXOR ; Array values can be Bitwise-OR'ed together to reproduce the original input. EndFunc ;==> XORSplit Func ORSplit($i32Bit) ; Splits an integer into two randomly selected bitwise non-exclusive integers. If Not IsInt($i32Bit) Or $i32Bit >= 2^32 Or $i32Bit < 0x80000000 Then Return SetError(1, 0, 0) Local $aOR[2] $aOR[0] = 0 $aOR[1] = 0 ; Randomly select which bits to reproduce in either one or both return values. Local $iBitPos, $iSwitch = Random(1,3,1) For $i = 0 To 31 $iBitPos = 2^$i If BitAND($i32Bit, $iBitPos) = $iBitPos Then For $n = 1 To 2 If BitAND($iSwitch, $n) = $n Then $aOR[$n -1] = BitOR($aOR[$n -1], $iBitPos) Next $iSwitch = Random(1,3,1) ; Set the switch for the next run. EndIf Next ; Check the sign bit. If BitAND($i32Bit, 0x80000000) = 0x80000000 Then For $n = 1 To 2 If BitAND($iSwitch, $n) = $n Then $aOR[$n -1] = BitOR($aOR[$n -1], 0x80000000) Next EndIf Return $aOR ; Array values can be Bitwise-OR'ed together to reproduce the original input. EndFunc ;==> ORSplit Func MagicFormat($iInt) Return '0x' & StringRegExpReplace(Hex($iInt), '\A0{0,'& 2*Random(2,3,1) &'}', '') EndFunc Func MagicSplit($iInt) Local $aSplit = ORSplit($iInt) If $aSplit[0] = $iInt Or $aSplit[1] = $iInt Or $aSplit[0] = 1 Or $aSplit[1] = 1 Then $aSplit = XORSplit($iInt) Return $aSplit EndFunc ; #INTERNAL_USE_ONLY# =========================================================================================================== ; Name...........: __GetSubstitute ; Description ...: Searches for a character to be used for substitution, ie one not contained within the input string ; Syntax.........: __GetSubstitute($string, ByRef $iCountdown) ; Parameters ....: $string - The string of characters to avoid ; $iCountdown - The first code point to begin checking ; Return values .: Success - Returns a suitable substitution character not found within the first parameter ; Failure - Sets @error to 1 => No substitution character available ; Author ........: czardas ; Comments ......; This function is connected to the function _CSVSplit and was not intended for general use ; $iCountdown is returned ByRef to avoid selecting the same character on subsequent calls to this function ; Initially $iCountown should be passed with a value = 63743 ; =============================================================================================================================== Func __GetSubstitute($string, ByRef $iCountdown) If $iCountdown < 57344 Then Return SetError(1, 0, "") ; Out of options Local $sTestChar For $i = $iCountdown To 57344 Step -1 $sTestChar = ChrW($i) $iCountdown -= 1 If Not StringInStr($string, $sTestChar) Then Return $sTestChar EndIf Next Return SetError(1, 0, "") ; Out of options EndFunc ;==> __GetSubstitute ; ==> Example - ORfuscate this script. ; See what it does to an array of numbers: Local $aArrayOfNumbers[8] = [387, 0xFFFFFFFF, BitOR(1,2,4,8,16,32,64,128), 0.178, 13/167, 0.1e-78, -876, 20] Global $hFile = FileOpen(@ScriptFullPath) Global $sScript = FileRead($hFile) FileClose($hFile) ConsoleWrite(ORfuscate($sScript) & @CRLF) #cs Ignores multiline comments 100, 0xFFFFFFFF, BitOR(23, 57) #ce ; Have fun!
    1 point
  6. From what I can gather, the OP is asking what's the point of a crash? or Why is a crash better than an exit? or How can I make my crashing application a good thing?. So errrm I haven't gathered much.
    1 point
  7. Mobius

    ORfuscator

    An interesting idea czardas , oh btw congrats are in order I think
    1 point
  8. Melba23

    Click on menubar item

    MikahS, I aim to please! M23
    1 point
  9. Hobbyist, You could shorten it just a little: #include <GUIConstantsEx.au3> Global $sIni = @ScriptDir & "\Settings.ini" Global $aRadio[13] Global $aMon[13] = ["", "January", "February", "March", "April", "May", "June", _ "July", "August", "September", "October", "November", "December"] $main = GUICreate("Dash Board", 680, 515, 150, 100) $Group1 = GUICtrlCreateGroup("Default Month", 28, 230, 121, 121) For $i = 1 To 12 $iX = (($i > 6) ? (103) : (38)) $iY = 247 + (17 * Mod($i - 1, 6)) $aRadio[$i] = GUICtrlCreateRadio(StringLeft($aMon[$i], 3), $iX, $iY, 45, 17) Next GUICtrlSetState($aRadio[_MyCheck()], $GUI_CHECKED) GUISetState() While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $aRadio[1] To $aRadio[12] For $i = 1 To 12 If $iMsg = $aRadio[$i] Then $Monthmgr = $aMon[$i] _MyChoice($Monthmgr) _MyValue($i) ExitLoop EndIf Next EndSwitch WEnd Func _MyChoice($sMon) IniWrite($sIni, "Month", "Month", $sMon) EndFunc ;==>_MyChoice Func _MyValue($i) IniWrite($sIni, "Checked", "Checked", $i) EndFunc ;==>_MyValue Func _MyCheck() Return IniRead($sIni, "Checked", "Checked", 1) ; Default is 1 EndFunc ;==>_MyCheck The main changes: - Use of an ini file to store the saved data - that is what they are designed to do. - Use of arrays to hold the radio ControlIDs and month names - makes it easier to loop through them. - Use of algorithms to locate each of the radios as they are created. - Looping through array of radio ControlIDs to see whch was pressed. Please ask if you have any questions or of any of the code is unclear. M23
    1 point
  10. altex, Actually you can do this by using a little trick: #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> $hGUI = GUICreate("Test", 500, 500) $mFilemenu = GUICtrlCreateMenu("File") $mExititem = GUICtrlCreateMenuItem("Exit", $mFilemenu) $mSpecialitem = GUICtrlCreateMenuItem("?", -1) ; I belong to the main menu GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $mExititem Exit Case $mSpecialitem MsgBox($MB_SYSTEMMODAL, "Hi", "I can be actioned!") EndSwitch WEnd M23
    1 point
  11. Thanks FlutterShy! It is easy to do that these functions to work with SSL. All we need is install stunnel. Configure it in that way: [POP3 configuration] <- This is comment about what below lines apply to client = yes ;This means that stunnel works in client mode accept = 127.0.0.1:110 ;Port number on our machine on which stunnel will be listen to incoming non-ciphered connection. By default if POP3 is non secured 110 is the port on which it works. That could be any other free port. connect = you.email.ssl.service.provider:995 As I describe here To connect with POP3 ssl server we call _POP3Connect("username","pass","127.0.0.1","110"). Easy to do! :-) Remember to comment-out Example section in the beginning of the script. FlutterShy Thanks for the code, You saved me a lot of work.
    1 point
  12. Someone seems to have updated it but only posted on the German autoit forums, not really sure how much they updated or anything, I just stumbled into it. Spoiler: doesn't work with SSL or Gmail... ; :collapseFolds=0:maxLineLen=80:mode=autoitscript:tabSize=8:indentSize=8:folding=indent: ;=============================================================================== ; Original UDF: ; http://www.autoitscript.com/forum/index.php?showtopic=22838 ;~ Basic functions for AU3 Scripts, based on the 1939 RFC. ;~ See http://www.ietf.org/rfc/rfc1939.txt ;~ Include version : 0.99 (March 2006, 9th). ;~ Requires AU3 beta version 3.1.1.110 or newer. ;~ Author : Luc HENNINOT <lhenninot@nordnet.fr> ;=============================================================================== ; Name ..........: _POP3.au3 ; Author: .......: Thorsten Willert (thorsten [dot] willert [at] gmx [dot] de) ; Date ..........: Thu Feb 24 22:59:56 CET 2010 @778 /Internet Time/ ; Version .......: 1.03 ; AutoIt ........: v3.3.2.0 ;=============================================================================== #include-once #Region Global constants ; -- _POP3 error codes, sent by SetError. Use @error to display it. -- Global Enum $POP3_ERROR_OK = 0, _ $POP3_ERROR, _ $POP3_ERROR_TCPCONNECT_FAILED, _ $POP3_ERROR_SERVER_RESPONSE_TIMEOUT, _ $POP3_ERROR_ALREADY_CONNECTED, _ $POP3_ERROR_NOT_CONNECTED, _ $POP3_ERROR_NO_AUTH, _ $POP3_ERROR_TCPRECV_TIMEOUT, _ $POP3_ERROR_USER_REFUSED, _ $POP3_ERROR_PASSWD_REFUSED, _ $POP3_ERROR_ERR_RESPONSE, _ $POP3_ERROR_NO_OK_RESPONSE, _ $POP3_ERROR_STAT_BADRESPONSE, _ $POP3_ERROR_NO_TCP_RESPONSE, _ $POP3_ERROR_STAT_REFUSED, _ $POP3_ERROR_LIST_REFUSED, _ $POP3_ERROR_RSET_REFUSED, _ $POP3_ERROR_RETR_REFUSED, _ $POP3_ERROR_QUIT_REFUSED, _ $POP3_ERROR_DELE_REFUSED, _ $POP3_ERROR_TOP_REFUSED, _ $POP3_ERROR_UIDL_REFUSED, _ $POP3_ERROR_NOOP_REFUSED ; I love this one ;) ;-- _POP3 vars -- Global Const $POP3_OK = '^\+OK'; Regexp syntax #EndRegion Global constants #Region Global variables Global $POP3_TRACE = True Global $POP3_ISCONNECTED = 0 Global $POP3_ISAUTH = 0 Global $POP3_SOCKET Global $POP3_SERVER_RESPONSE_TIMEOUT = 60000 ; 1 mn, modify it if needed #EndRegion Global variables #Region Example #include <array.au3> If _POP3Connect("somenonsslemail@domain.com", "apassword") Then $a = _POP3Info() _ArrayDisplay($a) _POP3Quit() _POP3Disconnect() EndIf Exit #EndRegion Example ; #FUNCTION# =================================================================== ; Name ..........: _POP3Info ; Description ...: Returns an array with the specified informations about all mails ; AutoIt Version : V3.3.2.0 ; Syntax ........: _POP3Info([$vInfo = ""]) ; Parameter(s): .: $vInfo - Optional: (Default = "") : string or array ; Return Value ..: Success - array (Default: array[date,from,to,subject]) ; Failure - 0 ; @ERROR - ; Author(s) .....: Thorsten Willert ; Date ..........: Fri Jan 15 18:17:54 CET 2010 ; Link ..........: ; Related .......: ; Example .......: No ; ============================================================================== Func _POP3Info($vInfo = "") If $POP3_ISAUTH Then Local $vInf If $vInfo = "" Then Local $vInf[4] = ["Date", "From", "To", "Subject"] ElseIf IsArray($vInfo) Then $vInf = $vInfo Else Local $vInf[1] = [$vInfo] EndIf Local $iCnt = _POP3MsgCnt() If @error Then Return SetError(@error, 0, 0) Local $sTMP, $aTMP Local $iInf = UBound($vInf) If $iCnt > 0 Then Local $aRet[$iCnt + 1][$iInf] $aRet[0][0] = $iCnt For $i = 1 To $iCnt $sTMP = _POP3Top($i) If @error Then Return SetError(@error, 0, 0) For $j = 0 To $iInf - 1 $aTMP = StringRegExp($sTMP, '(?i)\n' & $vInf[$j] & ':\s*(.*?)\r', 3) If Not @error Then $aRet[$i][$j] = $aTMP[0] Next Next Return $aRet EndIf Return SetError($POP3_ERROR, 0, 0) Else Return SetError($POP3_ERROR_NO_AUTH, 0, 0) EndIf EndFunc ;==>_POP3Info ; #FUNCTION# =================================================================== ; Name ..........: _POP3Connect ; Description ...: Conects to the according pop3 server. ; AutoIt Version : V3.3.2.0 ; Syntax ........: _POP3Connect($sLogin, $sPasswd[, $sServer = ""[, $iPort = 110]]) ; Parameter(s): .: $sLogin - ; $sPasswd - ; $sServer - Optional: (Default = "") : pop3 server ; $iPort - Optional: (Default = 110) : ; Return Value ..: Success - 1 ; Failure - 0 ; @ERROR - ; Author(s) .....: Luc HENNINOT, Thorsten Willert ; Date ..........: Fri Jan 15 18:37:29 CET 2010 ; Link ..........: ; Related .......: ; Example .......: No ; ============================================================================== Func _POP3Connect($sLogin, $sPasswd, $sServer = "", $iPort = 110) If $POP3_ISCONNECTED = 0 Then If $iPort = 995 Then ConsoleWriteError("_POP3Connect: Error: SSL not supported ..." & @CRLF) Return SetError(1, 0, 0) EndIf If Not StringInStr($sServer, ".") Then Local $aTMP = StringRegExp($sLogin, '.*?@(.*?)\.(.*)', 3) If UBound($aTMP) Then $sServer = $aTMP[0] Local $sD = "." & $aTMP[1] Else ConsoleWriteError("_POP3Connect: Error: Can't find domain in login-name." & @CRLF) Return SetError(1, 0, 0) EndIf Select Case Ping("pop3." & $sServer & $sD, 2000) $sServer = "pop3." & $sServer & $sD Case Ping("pop." & $sServer & $sD, 2000) $sServer = "pop." & $sServer & $sD Case Ping("pop3." & $sServer & ".com", 2000) $sServer = "pop3." & $sServer & ".com" Case Ping("pop." & $sServer & ".com", 2000) $sServer = "pop." & $sServer & ".com" Case Else ConsoleWriteError("_POP3Connect: Error: Can't find POP3-server." & @CRLF) Return SetError(1, 0, 0) EndSelect EndIf TCPStartup() ; Basic name to IP conversion ConsoleWrite("_POP3Connect: connecting to: (" & $sServer & ") ") If StringRegExp($sServer, "[a-zA-Z]") Then $sServer = TCPNameToIP($sServer) ConsoleWrite($sServer & ":" & $iPort & @CRLF) $POP3_SOCKET = TCPConnect($sServer, $iPort) If @error Then $POP3_ISCONNECTED = 0 ConsoleWriteError("_POP3Connect: Error: " & @error & @CRLF) Return SetError($POP3_ERROR_TCPCONNECT_FAILED, 0, 0) Else $POP3_ISCONNECTED = 1 EndIf ; We need a first OK from pop3 server __POP3WaitForOK() If @error Then Return SetError($POP3_ERROR_NO_OK_RESPONSE, 0, 0) ; Send user __POP3Cmd("USER " & $sLogin) If @error Then Return SetError(@error, 0, 0) ; Send passwd __POP3Cmd("PASS " & $sPasswd) If @error Then Return SetError(@error, 0, 0) $POP3_ISAUTH = 1 Return 1 Else Return SetError($POP3_ERROR_ALREADY_CONNECTED, 0, 0) EndIf EndFunc ;==>_POP3Connect ; #FUNCTION# =================================================================== ; Name ..........: _POP3Dele ; Description ...: Delete msg n-msg_number. ; AutoIt Version : V3.3.2.0 ; Syntax ........: _POP3Dele($iMsg) ; Parameter(s): .: $iMsg - msg-number ; Return Value ..: Success - server response ; Failure - 0 ; @ERROR - ; Author(s) .....: Luc HENNINOT, Thorsten Willert ; Date ..........: Thu Jan 14 15:24:41 CET 2010 ; Link ..........: ; Related .......: ; Example .......: No ; ============================================================================== Func _POP3Dele($iMsg) If $POP3_ISAUTH Then __POP3Cmd("DELE " & $iMsg) If @error Then Return SetError(@error, 0, 0) Local $sRet = __POP3WaitTcpResponse() If @error Then Return SetError($POP3_ERROR_NO_TCP_RESPONSE, 0, 0) Return $sRet Else Return SetError($POP3_ERROR_NO_AUTH, 0, 0) EndIf EndFunc ;==>_POP3Dele ; #FUNCTION# =================================================================== ; Name ..........: _POP3Disconnect ; Description ...: Shuts down connection. ; AutoIt Version : V3.3.2.0 ; Syntax ........: _POP3Disconnect() ; Parameter(s): .: - ; Return Value ..: Success - 1 ; Failure - 0 ; @ERROR - ; Author(s) .....: Luc HENNINOT, Thorsten Willert ; Date ..........: Thu Jan 14 11:15:16 CET 2010 ; Remark(s) .....: Use _POP3Quit to exit !! ; Link ..........: ; Related .......: ; Example .......: No ; ============================================================================== Func _POP3Disconnect() If $POP3_ISCONNECTED <> 0 Then TCPCloseSocket($POP3_SOCKET) TCPShutdown() $POP3_ISCONNECTED = 0 Return 1 Else Return SetError($POP3_ERROR_NOT_CONNECTED, 0, 0) EndIf EndFunc ;==>_POP3Disconnect ; #FUNCTION# =================================================================== ; Name ..........: _POP3List ; Description ...: Returns an array with the msg number and its size (octets) ; AutoIt Version : V3.3.2.0 ; Syntax ........: _POP3List([$iMsg = -1]) ; Parameter(s): .: $iMsg - Optional: (Default = -1) : ; | -1 = all ; Return Value ..: Success - array[n][2] ; Failure - 0 ; @ERROR - ; Author(s) .....: Luc HENNINOT, Thorsten Willert, Oscar ; Date ..........: Thu Feb 24 23:00:26 CET 2010 ; Link ..........: ; Related .......: _POP3Uidl ; Example .......: No ; ============================================================================== Func _POP3List($iMsg = -1) If $POP3_ISAUTH Then Local $aRet[1][2], $aTMP2 Local $sAddMsg = "" If $iMsg <> -1 Then $sAddMsg = " " & $iMsg EndIf ; Send List Local $sRet = __POP3Cmd("LIST" & $sAddMsg) If @error Then Return SetError(@error, 0, 0) While $iMsg = -1 And Not StringRegExp($sRet, "\r\n\.\r\n") $sRet = $sRet & __POP3WaitTcpResponse() If @error Then Return SetError($POP3_ERROR_NO_TCP_RESPONSE, 0, 0) WEnd $sRet = StringRegExpReplace($sRet, '.+?message.+\(.+\)\r\n', @LF) ; Yahoo-Support, by Oscar ; Stripping useless infos for complete listing If $iMsg = -1 Then $sRet = StringMid($sRet, 2, StringLen($sRet) - 6) Else $sRet = StringMid($sRet, 1, StringLen($sRet) - 2) EndIf Local $aTMP = StringSplit(StringStripCR($sRet), @LF) Local $iE = UBound($aTMP) ReDim $aRet[$iE][2] $aRet[0][0] = $iE - 1 For $i = 1 To $iE - 1 $aTMP2 = StringSplit($aTMP[$i], " ", 2) $aRet[$i][0] = $aTMP2[0] $aRet[$i][1] = $aTMP2[1] Next Return $aRet EndIf EndFunc ;==>_POP3List ; #FUNCTION# =================================================================== ; Name ..........: _POP3Noop ; Description ...: Actually, does nothing. ; AutoIt Version : V3.3.2.0 ; Syntax ........: _POP3Noop() ; Parameter(s): .: - ; Return Value ..: Success - 1 ; Failure - 0 ; @ERROR - ; Author(s) .....: Luc HENNINOT, Thorsten Willert ; Date ..........: Thu Jan 14 11:22:36 CET 2010 ; Remark(s) .....: The most interesting command from RFC 1939 ;) ; Link ..........: ; Related .......: ; Example .......: No ; ============================================================================== Func _POP3Noop() If $POP3_ISAUTH Then ; Send NOOP __POP3Cmd("NOOP") If @error Then Return SetError($POP3_ERROR_USER_REFUSED, 0, 0) Return 1 EndIf EndFunc ;==>_POP3Noop ; #FUNCTION# =================================================================== ; Name ..........: _POP3Quit ; Description ...: Validates your actions (dele for example) and stops the connection as it should. ; AutoIt Version : V3.3.2.0 ; Syntax ........: _POP3Quit() ; Parameter(s): .: - ; Return Value ..: Success - 1 ; Failure - 0 ; @ERROR - ; Author(s) .....: Luc HENNINOT, Thorsten Willert ; Date ..........: Thu Jan 14 11:25:00 CET 2010 ; Link ..........: ; Related .......: ; Example .......: No ; ============================================================================== Func _POP3Quit() If $POP3_ISAUTH Then __POP3Cmd("QUIT") If @error Then Return SetError(@error, 0, 0) Return 1 Else Return SetError($POP3_ERROR_NO_AUTH, 0, 0) EndIf EndFunc ;==>_POP3Quit ; #FUNCTION# =================================================================== ; Name ..........: _POP3Retr ; Description ...: Downloads the according message ; AutoIt Version : V3.3.2.0 ; Syntax ........: _POP3Retr([$iMsg = -1]) ; Parameter(s): .: $iMsg - Optional: (Default = -1) : ; | -1 = newest ; Return Value ..: Success - string ; Failure - 0 ; @ERROR - ; Author(s) .....: Luc HENNINOT, Thorsten Willert ; Date ..........: Thu Jan 14 17:23:03 CET 2010 ; Link ..........: ; Related .......: ; Example .......: No ; ============================================================================== Func _POP3Retr($iMsg = -1) If $POP3_ISAUTH Then If $iMsg = -1 Then Local $aStat = _POP3Stat() If Not @error Then $iMsg = $aStat[0] EndIf ; Send Retr Local $sRet = __POP3Cmd("RETR " & $iMsg) If @error Then Return SetError(@error, 0, 0) ; Downloading until final dot and cariage return. While Not StringRegExp($sRet, "\r\n\.\r\n") $sRet = $sRet & __POP3WaitTcpResponse() If @error Then Return SetError($POP3_ERROR_NO_TCP_RESPONSE, 0, 0) WEnd Return $sRet Else Return SetError($POP3_ERROR_NO_AUTH, 0, 0) EndIf EndFunc ;==>_POP3Retr ; #FUNCTION# =================================================================== ; Name ..........: _POP3Rset ; Description ...: Withdraw changes, such as dele orders ; AutoIt Version : V3.3.2.0 ; Syntax ........: _POP3Rset() ; Parameter(s): .: - ; Return Value ..: Success - 1 ; Failure - 0 ; @ERROR - ; Author(s) .....: Luc HENNINOT, Thorsten Willert ; Date ..........: Thu Jan 14 11:34:52 CET 2010 ; Link ..........: ; Related .......: ; Example .......: No ; ============================================================================== Func _POP3Rset() If $POP3_ISAUTH Then ; Send RSET __POP3Cmd("RSET") If @error Then Return SetError(@error, 0, 0) Return 1 Else Return SetError($POP3_ERROR_NO_AUTH, 0, 0) EndIf EndFunc ;==>_POP3Rset ; #FUNCTION# =================================================================== ; Name ..........: _POP3Stat ; Description ...: Gets the number of messages in the pop3 account (array[1]) and the size(array[2]) in octets ; AutoIt Version : V3.3.2.0 ; Syntax ........: _POP3Stat() ; Parameter(s): .: - ; Return Value ..: Success - array ; Failure - array[-1,-1] ; @ERROR - ; Author(s) .....: Luc HENNINOT, Thorsten Willert ; Date ..........: Fri Jan 15 09:54:17 CET 2010 ; Link ..........: ; Related .......: _POP3MsgCnt ; Example .......: No ; ============================================================================== Func _POP3Stat() Local $aRet[2] = [-1, -1] If $POP3_ISAUTH Then ; Send STAT Local $sRet = __POP3Cmd("STAT") If @error Then Return SetError(@error, 0, 0) $sRet = StringStripWS($sRet, 3) $aRet = StringSplit($sRet, " ", 2) If IsArray($aRet) Then Return $aRet Else Return SetError($POP3_ERROR_STAT_BADRESPONSE, 0, $aRet) EndIf Else Return SetError($POP3_ERROR_NO_AUTH, 0, $aRet) EndIf EndFunc ;==>_POP3Stat ; #FUNCTION# =================================================================== ; Name ..........: _POP3MsgCnt ; Description ...: Returns the number of messages ; AutoIt Version : V3.3.2.0 ; Syntax ........: _POP3MsgCnt() ; Parameter(s): .: - ; Return Value ..: Success - number of messages ; Failure - -1 ; @ERROR - ; Author(s) .....: Thorsten Willert ; Date ..........: Fri Jan 15 09:56:20 CET 2010 ; Link ..........: ; Related .......: _POP3Stat ; Example .......: NO ; ============================================================================== Func _POP3MsgCnt() Local $a = _POP3Stat() Return SetError(@error, 0, $a[0]) EndFunc ;==>_POP3MsgCnt ; #FUNCTION# =================================================================== ; Name ..........: _POP3Top ; Description ...: Retreives the mail headers, and the X first lines of the message ; AutoIt Version : V3.3.2.0 ; Syntax ........: _POP3Top([$iMsg = -1[, $iLines = 0]]) ; Parameter(s): .: $iMsg - Optional: (Default = -1) : ; | -1 : newest ; $iLines - Optional: (Default = 0) : ; Return Value ..: Success - string ; Failure - 0 ; @ERROR - ; Author(s) .....: Luc HENNINOT, Thorsten Willert ; Date ..........: Thu Jan 14 17:26:42 CET 2010 ; Link ..........: ; Related .......: ; Example .......: No ; ============================================================================== Func _POP3Top($iMsg = -1, $iLines = 0) If $POP3_ISAUTH Then If $iMsg = -1 Then Local $aStat = _POP3Stat() If Not @error Then $iMsg = $aStat[0] EndIf ; Send Top Local $sRet = __POP3Cmd("TOP " & $iMsg & " " & $iLines) If @error Then Return SetError(@error, 0, 0) ; Downloading until final dot and cariage return. While Not StringRegExp($sRet, "\r\n\.\r\n") $sRet = $sRet & __POP3WaitTcpResponse() If @error Then Return SetError($POP3_ERROR_NO_TCP_RESPONSE, 0, 0) WEnd Return $sRet Else Return SetError($POP3_ERROR_NO_AUTH, 0, 0) EndIf EndFunc ;==>_POP3Top ; #FUNCTION# =================================================================== ; Name ..........: _POP3Uidl ; Description ...: Same as _POP3List(), but with UIDL identifiers instead of message size. ; AutoIt Version : V3.3.2.0 ; Syntax ........: _POP3Uidl([$iMsg = -1]) ; Parameter(s): .: $iMsg - Optional: (Default = -1) : ; Return Value ..: Success - array[n][2] ; Failure - 0 ; @ERROR - ; Author(s) .....: Luc HENNINOT, Thorsten Willert ; Date ..........: Thu Jan 14 16:51:30 CET 2010 ; Link ..........: ; Related .......: _POP3List ; Example .......: No ; ============================================================================== Func _POP3Uidl($iMsg = -1) If $POP3_ISAUTH Then Local $aRet[1][2], $aTMP2 Local $sAddMsg = "" If $iMsg <> -1 Then $sAddMsg = " " & $iMsg ; Send List Local $sRet = __POP3Cmd("UIDL " & $sAddMsg) If @error Then Return SetError(@error, 0, 0) While $iMsg = -1 And Not StringRegExp($sRet, "\r\n\.\r\n") $sRet = $sRet & __POP3WaitTcpResponse() If @error Then Return SetError($POP3_ERROR_NO_TCP_RESPONSE, 0, 0) WEnd ; Stripping useless infos for complete listing If $iMsg = -1 Then $sRet = StringMid($sRet, 2, StringLen($sRet) - 6) Else $sRet = StringMid($sRet, 1, StringLen($sRet) - 2) EndIf Local $aTMP = StringSplit(StringStripCR($sRet), @LF) Local $iE = UBound($aTMP) ReDim $aRet[$iE][2] $aRet[0][0] = $iE - 1 For $i = 1 To $iE - 1 $aTMP2 = StringSplit($aTMP[$i], " ", 2) $aRet[$i][0] = $aTMP2[0] $aRet[$i][1] = $aTMP2[1] Next Return $aRet Else Return SetError($POP3_ERROR_NO_AUTH, 0, 0) EndIf EndFunc ;==>_POP3Uidl ; #INTERNAL_USE_ONLY# ========================================================== ; Name ..........: __POP3Cmd ; Description ...: ; AutoIt Version : V3.3.2.0 ; Syntax ........: __POP3Cmd($sMSg) ; Parameter(s): .: $sMSg - ; Return Value ..: Success - string ; Failure - 0 ; @ERROR - ; Author(s) .....: Thorsten Willert ; Date ..........: Thu Jan 14 17:07:08 CET 2010 ; ============================================================================== Func __POP3Cmd($sMSg) If $POP3_TRACE Then ConsoleWrite(">: " & $sMSg & @CRLF) TCPSend($POP3_SOCKET, $sMSg & @CRLF) If @error Then Return SetError($POP3_ERROR_USER_REFUSED, 0, 0) Local $sRet = __POP3WaitForOK() If @error Then Return SetError($POP3_ERROR_NO_OK_RESPONSE, 0, 0) Return $sRet EndFunc ;==>__POP3Cmd ; #INTERNAL_USE_ONLY# ========================================================== ; Name ..........: __POP3WaitForOK ; Description ...: Returns the server response if it starts with "+OK" ; AutoIt Version : V3.3.2.0 ; Syntax ........: __POP3WaitForOK() ; Parameter(s): .: - ; Return Value ..: Success - string ; Failure - "" ; @ERROR - ; Author(s) .....: Luc HENNINOT, Thorsten Willert ; Date ..........: Thu Jan 14 11:50:34 CET 2010 ; ============================================================================== Func __POP3WaitForOK() ; Wait for server response. Local $sRet Local $T = TimerInit() While TimerDiff($T) < $POP3_SERVER_RESPONSE_TIMEOUT $sRet = __POP3WaitTcpResponse() If Not @error And StringRegExp($sRet, '\+OK') Then Return StringRegExpReplace($sRet, '\+OK\s?', "") If StringRegExp($sRet, '\-ERR\s?') Then Return SetError($POP3_ERROR_ERR_RESPONSE, 0, "") Sleep(100) WEnd Return SetError($POP3_ERROR_SERVER_RESPONSE_TIMEOUT, 0, "") EndFunc ;==>__POP3WaitForOK ; #INTERNAL_USE_ONLY# ========================================================== ; Name ..........: __POP3WaitTcpResponse ; Description ...: Returns the server response ; AutoIt Version : V3.3.2.0 ; Syntax ........: __POP3WaitTcpResponse([$iTimeOut = 30000]) ; Parameter(s): .: $iTimeOut - Optional: (Default = 30000) : ; Return Value ..: Success - string ; Failure - 0 ; @ERROR - ; Author(s) .....: Luc HENNINOT, Thorsten Willert ; Date ..........: Thu Jan 14 11:51:07 CET 2010 ; ============================================================================== Func __POP3WaitTcpResponse($iTimeOut = 30000) ;Timeout to 30 s, should be enough in most cases. Overwright it if needed. Local $sRet = "" Local $T = TimerInit() While TimerDiff($T) < $iTimeOut $sRet = TCPRecv($POP3_SOCKET, 512) If $POP3_TRACE And $sRet Then ConsoleWrite("<: " & $sRet) If $sRet <> "" Then Return $sRet Sleep(100) WEnd Return SetError($POP3_ERROR_TCPRECV_TIMEOUT, 0, 0) EndFunc ;==>__POP3WaitTcpResponse POP3.au3 Edit: stupid buggy autoit tags Edit2: wow, why are things formatted in the code tags >
    1 point
  13. This call function can call any script/user function and also any native function. This is invented because mostly invented this clumsy work-around. For call with ByRef capability (but only with CallArgArray), see this post: Hopefully at some point AutoIt will treat AutoIt functions as-if they were user defined functions (or vice versa). Reposted this in a seperate thread for SEO mostly (<title> and <h1> matter most, after all). _CallAny("MsgBox", 0x20, "Hello, World", "LOL") ; This demonstrates how to use the special array argument. Local $aArgs[4] $aArgs[0] = "CallArgArray" ; This is required, otherwise, _CallAny will not recognize the array as containing arguments $aArgs[1] = 0x20 $aArgs[2] = "Hello, World" $aArgs[3] = "Example 2" _CallAny("MsgBox", $aArgs) Func _CallAny($function, $param1 = 0, $param2 = 0, $param3 = 0, $param4 = 0, $param5 = 0) Local $exec = $function & "(" If @NumParams = 2 And IsArray($param1) And UBound($param1, 0) = 1 And $param1[0] = "CallArgArray" Then For $n = 1 To UBound($param1) - 1 $exec &= "$param1[" & $n & "]," Next Else For $n = 1 To @NumParams $exec &= "$param" & $n & "," Next EndIf Local $iRet = Execute(StringTrimRight($exec, 1) & ")") Return SetError(@error, @extended, $iRet) EndFunc ;==>_CallAny To add the ability for more parameters, just add $param6 = 0, $param7 = 0. The guts of the function don't need any changes.
    1 point
  14. ptrex

    Printing Controls in AU3

    Printing Controls in AU3 Native printing in AU3 has always been an issue, untill GRS came up with PrintWinAPI.au3 Thanks to Martin, ProgAndy and Zedna for their enlightning examples. I was able to mix all of those together in this example. Print_Control.au3 Needs : PrintWinAPI.au3 It still needs cleaning up, but it will give you all a start. I finished what Zedna started using the WM_PRINT message instead of _WinAPI_BitBlt. The result is the same but the approach is different. When to use which approach ? #include <ClipBoard.au3> #include <SendMessage.au3> #include <GDIPlus.au3> #Include <WinAPI.au3> #include <GUIStatusBar.au3> #include <GUIConstantsEx.au3> Const $WM_PAINT = 0x000F Const $WM_PRINT = 0x317 Const $WM_PRINTCLIENT = 0x318 Const $PRF_CHECKVISIBLE = 0x1; Draws the window only if it is visible Const $PRF_ERASEBKGND = 0x8 ; Erases the background before drawing the window Const $PRF_CLIENT = 0x4 ; Draw the window's client area. Const $PRF_NONCLIENT = 0x2 ; Draw the window's Title area. Const $PRF_CHILDREN = 0x10; Draw all visible child windows. Const $PRF_OWNED = 0x20 ; Draw all owned windows. $Form1 = GUICreate("Form1", 593, 453, 193, 115) $StatusBar1 = _GUICtrlStatusBar_Create($Form1) _GUICtrlStatusBar_SetSimple($StatusBar1) _GUICtrlStatusBar_SetText($StatusBar1, "This is the status bar text ...") $MyButton1 = GUICtrlCreateButton("Get Status as image", 224, 176, 140, 30, 0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $MyButton1 GetStatusImage() EndSwitch WEnd Func GetStatusImage() $hWnd = ControlGetHandle("Form1","","msctls_statusbar321") ; WinGetHandle("Form1") $pos = ControlGetPos("Form1","","msctls_statusbar321") ; WinGetPos("Form1") If Not IsArray($pos) Then MsgBox(0,"Error","No Control found") Return EndIf _GDIPlus_StartUp() $Width = $pos[2] $Height = $pos[3] $hDC = _WinAPI_GetDC($hWnd) $memDC = _WinAPI_CreateCompatibleDC($hDC) $memBmp = _WinAPI_CreateCompatibleBitmap($hDC, $Width, $Height) _WinAPI_SelectObject ($memDC, $memBmp) ; Use the WM_PRINT message instead of _WinAPI_BitBlt ;_WinAPI_BitBlt($memDC, 0, 0, $Width, $Height, $hDC, 0, 0, $SRCCOPY) $Ret = _SendMessage($hWnd, $WM_PAINT, $memDC, 0) $Ret = _SendMessage($hWnd, $WM_PRINT, $memDC, BitOR($PRF_CHILDREN , $PRF_CLIENT, $PRF_OWNED, $PRF_NONCLIENT, $PRF_ERASEBKGND)) $hImage = _GDIPlus_BitmapCreateFromHBITMAP ($memBmp) _ClipBoard_SetData($memBmp,$CF_BITMAP) _GDIPlus_ImageSaveToFile($hImage, 'status.jpg') ;.BMP _GDIPlus_ImageDispose ($hImage) _WinAPI_ReleaseDC($hWnd, $hDC) _WinAPI_DeleteDC($memDC) _WinAPI_DeleteObject ($memBmp) _GDIPlus_ShutDown() _WinAPI_GetLastError() EndFunc Enjoy !! Regards, ptrex
    1 point
×
×
  • Create New...