├── .github └── FUNDING.yml ├── .gitignore ├── icon.ico ├── README.adoc ├── IsMgcNumPresent.au3 ├── LICENSE ├── IniReadWrite.au3 ├── config.adoc ├── help.adoc ├── CHANGELOG.adoc ├── ProcessEx.au3 ├── Tor.au3 └── ProxAllium.au3 /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: TheDcoder 2 | liberapay: DcodingTheWeb 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Tor/ 2 | Tor Data/ 3 | config.torrc 4 | config.ini 5 | Builds/ 6 | -------------------------------------------------------------------------------- /icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DcodingTheWeb/ProxAllium/HEAD/icon.ico -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = ProxAllium 2 | 3 | image:https://img.shields.io/badge/license-MIT-blue.svg[link="https://raw.githubusercontent.com/DcodingTheWeb/ProxAllium/master/LICENSE"] image:https://img.shields.io/github/issues/DcodingTheWeb/ProxAllium.svg[link="https://github.com/DcodingTheWeb/ProxAllium/issues"] image:https://img.shields.io/github/release/DcodingTheWeb/ProxAllium/all.svg[link="https://github.com/DcodingTheWeb/ProxAllium/releases"] image:https://img.shields.io/badge/Chat-on%20Gitter-%2346BC99[alt=Chat on Gitter,link=https://gitter.im/ProxAllium/chat] 4 | 5 | Tor Proxy Bundle for Windows. ProxAllium is an open-source wrapper for Tor. Visit the https://proxallium.tuxfamily.org/[website] for more details, don't forget to check the https://proxallium.tuxfamily.org/screenshots[screenshots]! 6 | -------------------------------------------------------------------------------- /IsMgcNumPresent.au3: -------------------------------------------------------------------------------- 1 | ; #FUNCTION# ==================================================================================================================== 2 | ; Name ..........: IsMgcNumPresent 3 | ; Description ...: Checks if a number is a present in a number (Magic numbers aka Powers of 2) 4 | ; Syntax ........: IsMgcNumPresent($iNumber, $iMagicNumber) 5 | ; Parameters ....: $iNumber - Number to check if it exists in $iMagicNumber. 6 | ; $iMagicNumber - The number which might contain $iNumber. 7 | ; Return values .: Success: True 8 | ; Failure: False 9 | ; Author ........: Damon Harris (TheDcoder) 10 | ; Modified ......: 11 | ; Remarks .......: 12 | ; Related .......: 13 | ; Link ..........: https://git.io/vPFjk 14 | ; Example .......: Yes, see IsMgcNumPresent_Example.au3 15 | ; =============================================================================================================================== 16 | Func IsMgcNumPresent($iNumber, $iMagicNumber) 17 | Return BitAND($iMagicNumber, $iNumber) = $iNumber 18 | EndFunc -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016 Dcoding The Web 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /IniReadWrite.au3: -------------------------------------------------------------------------------- 1 | ; #FUNCTION# ==================================================================================================================== 2 | ; Name ..........: IniReadWrite 3 | ; Description ...: Write the default value to Ini if it does not exist 4 | ; Syntax ........: IniReadWrite($sFile, $sSection, $sKey, $sDefault) 5 | ; Parameters ....: $sFile - The path for the .ini file. 6 | ; $sSection - The section name in the .ini file. 7 | ; $sKey - The key name in the .ini file. 8 | ; $sDefault - The default value. 9 | ; Return values .: The value of the $sKey in the Ini file or $sDefault if the $sKey does not exists 10 | ; Author ........: Damon Harris (TheDcoder) 11 | ; Remarks .......: PRO TIP: IniReadWrite is fully compatible with IniRead (i.e Same parameters) 12 | ; Related .......: IniRead and IniWrite 13 | ; Link ..........: https://gist.github.com/TheDcoder/b5035d600b7a130ea45311541a15a555 14 | ; Example .......: No 15 | ; =============================================================================================================================== 16 | Func IniReadWrite($sFile, $sSection, $sKey, $sDefault) 17 | Local $sIniRead = IniRead($sFile, $sSection, $sKey, "") 18 | If Not $sIniRead = "" Then Return $sIniRead 19 | IniWrite($sFile, $sSection, $sKey, $sDefault) 20 | Return $sDefault 21 | EndFunc 22 | -------------------------------------------------------------------------------- /config.adoc: -------------------------------------------------------------------------------- 1 | = ProxAllium Configuration 2 | 3 | == Introduction 4 | 5 | This document will outline all of the available configuration options in ProxAllium. The defaults are pretty good so an average user can do without reading this, but advanced users may want to access one of the more advanced features and change the defaults to suit their needs. 6 | 7 | It goes without saying that you should know what you are doing, otherwise you may have unexpected consequences! 8 | 9 | == Config File 10 | 11 | ProxAllium uses a single `config.ini` file which is stored alongside the binary, it uses the reasonably simple https://en.wikipedia.org/wiki/INI_file#Format[INI] format to store your preferences. 12 | 13 | Don't worry about getting the format to follow the rules outlined in the wiki, AutoIt's INI parser is quite flexible and will be able to process your output as long it is readable by a human. Try taking the automatically generated key/value pairs as an example. 14 | 15 | NOTE: Don't forget to regenerate Tor configuration if you change anything which effects Tor! 16 | 17 | == Options 18 | 19 | This part will describe all of the options/keys/properties a section might contain. 20 | 21 | === `proxallium` 22 | 23 | |=== 24 | |Key |Value |Default 25 | 26 | | `output_poll_interval` 27 | | The delay between checking for output from Tor in milliseconds 28 | | `100` 29 | 30 | |=== 31 | 32 | === `tor` 33 | 34 | |=== 35 | |Key |Value |Default 36 | 37 | | `path` 38 | | Path to `tor.exe` 39 | | `Tor\tor.exe` 40 | 41 | | `obfs4_path` 42 | | Path to `obfs4.exe` (pluggable transport for bridges) 43 | | `Tor\PluggableTransports\obfs4\obfs4proxy.exe` 44 | 45 | | `snowflake_path` 46 | | Path to Snowflake pluggable transport (bridge) 47 | | `Tor\PluggableTransports\obfs4\snowflake-client.exe` 48 | 49 | | `snowflake_args` 50 | | Arguments to the Snowflake client 51 | | Refer to the https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/tree/main/client[official docs] for up-to-date information 52 | 53 | | `config_file` 54 | | Path for the generated `torrc` file 55 | | `config.torrc` 56 | 57 | | `data_dir` 58 | | Path to the directory used by Tor to store data 59 | | `Tor Data` 60 | 61 | | `geoip4_file` and/or `geoip6_file` 62 | | Paths to the GeoIP files 63 | | `Tor\geoip` and/or `Tor\geoip6` 64 | 65 | |=== 66 | 67 | === `tor_config` 68 | 69 | |=== 70 | |Key |Value |Default 71 | 72 | | `port` 73 | | Port for Tor's SOCKS5 proxy 74 | | `9050` 75 | 76 | | `tunnel_port` 77 | | Port for the HTTP tunnel proxy, use `auto` if you want Tor to pick the port 78 | | _None_ 79 | 80 | | `control_port` 81 | | Port for Tor's controller, used to control Tor 82 | | `9051` 83 | 84 | | `control_pass` 85 | | Password for controller authentication 86 | | String of random 6 digit number 87 | 88 | | `localhost_only` 89 | | Only allow proxy connection from your computer 90 | | `true` 91 | 92 | | `exit_node_country_code` 93 | | https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Current_codes[2-letter country code] of the exit node 94 | | _None_ 95 | 96 | |=== 97 | 98 | === `proxy` 99 | 100 | IMPORTANT: These settings are for Tor to connect to the nodes, not for Tor's proxy! 101 | 102 | |=== 103 | |Key |Value 104 | 105 | | `type` 106 | | Type of the proxy (`http` or `https` or `socks4` or `socks5`) 107 | 108 | | `host` 109 | | Address of the proxy's host (I.P or Name) 110 | 111 | | `port` 112 | | Port to connect at the host 113 | 114 | | `user` 115 | | (*Only for SOCKS5*) Username 116 | 117 | | `pass` 118 | | (*Only for SOCKS5*) Password 119 | 120 | |=== 121 | 122 | === `bridges` 123 | 124 | TIP: You can change these settings via GUI! Use `Options` -> `Bridges` option in the menu 125 | 126 | |=== 127 | |Key |Value 128 | 129 | | `enabled` 130 | | `true` if enabled or `false` if not 131 | 132 | | `path` 133 | | Path to a text file with the bridge lines 134 | 135 | |=== 136 | 137 | === `startup` 138 | 139 | TIP: These settings can be interactively modified via GUI in the `Options` -> `Startup` menu! 140 | 141 | |=== 142 | |Key |Value 143 | 144 | | `auto_start` 145 | | `true` if auto-start is enabled or `false` if not 146 | 147 | | `auto_start_shortcut` 148 | | (*DON'T MODIFY, INTERNAL USE ONLY*) Path of the startup shortcut 149 | 150 | | `start_minimized` 151 | | `true` if you want to start minimized or `false` if not 152 | 153 | |=== 154 | -------------------------------------------------------------------------------- /help.adoc: -------------------------------------------------------------------------------- 1 | = Documentation for ProxAllium 2 | :doctype: book 3 | :nofooter: 4 | :toc: left 5 | 6 | == Introduction 7 | ProxAllium is a Free and Open Source front-end for Tor which makes it *easier* for normal everyday people to make more out of Tor! 8 | With ProxAllium, you can circumvent censorship and be secure while using public internet hotspots (you can also be anonymous but only upto some extent). 9 | 10 | Just run ProxAllium and now you have a working Tor circuit for you to use! 11 | 12 | You can consult to the <> for more information. 13 | 14 | == Installation 15 | ProxAllium is fully portable, it does not require any _setup_ to be done and it does not mess with anything outside its own folder! 16 | 17 | Just use any file archiver (http://7-zip.org/[7-zip] is recommended) to extract the `.7z` file onto your computer, you can extract it to anywhere, it is your choice. 18 | The `7z` archive/package contains a folder called `ProxAllium` and within it, you can find ProxAllium itself and other necessary files. 19 | 20 | Now you can start using ProxAllium by executing `ProxAllium.exe`! Easy, isn't it? 21 | 22 | == Mailing List (Email Updates) 23 | 24 | CAUTION: *I am no longer actively posting to the mailing list, so I do not recommend anyone to register, sorry.* 25 | 26 | Now you can get e-mail notifications for new releases and updates from https://listengine.tuxfamily.org/proxallium.tuxfamily.org/news/[ProxAllium's Mailing List]! 27 | 28 | === Subscribing 29 | To subscribe, send a mail with `subscribe` as the subject to `news-request@proxallium.tuxfamily.org`, then reply to the confirmation mail sent by `listmaster@tuxfamily.org`. If for some reason you are not able to subscribe, you can https://github.com/DcodingTheWeb/ProxAllium/wiki/FAQ#i-have-a-question-where-can-i-ask[contact me] asking to add your e-mail to the mailing list... I won't bite by the way! 30 | 31 | === Precautions and Information 32 | . Your Email is **private** and is **not distributed** to anyone! 33 | . You will receive emails updates from `mailman@proxallium.tuxfamily.org`, so make sure that it is in your whitelist/address book/contacts. You don't want to find those important notifications in your spam folder! 34 | . **Do no reply to email notifications**! They will not reach anyone, the mailing list only accepts emails from administrators 35 | . To unsubscribe, just follow the same procedure as <> except use `unsubscribe` as the subject of the email 36 | 37 | 38 | == FAQ 39 | === What does it do? 40 | ProxAllium's goal is to make using https://www.torproject.org/about/overview.html.en[Tor] (Not to be confused with https://www.torproject.org/projects/torbrowser.html.en[Tor Browser]) easier for normal everyday users. It's basically a front-end for Tor, except that it tries to be more than that. 41 | 42 | === How is it different from Tor Browser (Bundle)? 43 | It is not a replacement for the `TBB`, ProxAllium does not come with any browser! You should configure your own browser to work with `Tor`. Don't worry because it's really easy! You just have to use the proxy created by `Tor`. The method for using the proxy created by Tor is the same as using a traditional https://en.wikipedia.org/wiki/SOCKS[SOCKS proxy]. 44 | 45 | === Where do I download ProxAllium? 46 | You can find the 7-zip packages at the https://github.com/DcodingTheWeb/ProxAllium/releases[Releases] page. 47 | 48 | === How do I make it start on startup? 49 | Use the `Automatically start with Windows` option (in `Menu -> Options -> Startup`). 50 | 51 | === I have a question, where can I ask? 52 | You can consult to the "link:https://proxallium.tuxfamily.org/chat/[Chat]" page on ProxAllium's website. 53 | 54 | == Credits & Acknowledgments 55 | === Programming Language 56 | Thanks to https://github.com/jonathanbennett73[Jonathan Bennett] & AutoIt Team for creating a wonderful scripting language called AutoIt! All of ProxAllium's code is 100% pure http://www.autoitscript.com/autoit3/[AutoIt]. 57 | 58 | === Tor 59 | Thanks to https://en.wikipedia.org/wiki/The_Tor_Project,_Inc[The Tor Project] for creating a wonderful thing called https://www.torproject.org/[Tor]. Tor enables millions of people to be anonymous and circumvent censorship! 60 | 61 | === ProxAllium's Icon 62 | The icon for ProxAllium is a combined effort from many talented graphic artists... that excludes me. 63 | 64 | * Onion Icon made by http://www.flaticon.com/authors/roundicons[Roundicons] from www.flaticon.com 65 | * Computer Icon made by http://www.flaticon.com/authors/madebyoliver[Madebyoliver] from www.flaticon.com 66 | * World Server Icon made by http://www.flaticon.com/authors/prosymbols[Prosymbols] from www.flaticon.com 67 | * Double Headed Arrow Icon made by http://www.flaticon.com/authors/freepik[Freepik] from www.flaticon.com 68 | 69 | All of these icons were compiled into one by me. 70 | 71 | https://www.icoconverter.com/ was used to create the final `ico` file! 72 | 73 | 74 | === Infrastructure 75 | Thanks to https://github.com[GitHub] (Code and Issue Tracker Hosting), https://www.tuxfamily.org/[Tux Family] (https://www.tuxfamily.org/en/about[Whole array of services to FOSS projects]) and https://www.oftc.net/[OFTC] (IRC Network) for providing such generous services! 76 | 77 | === You! 78 | For using ProxAllium! 79 | -------------------------------------------------------------------------------- /CHANGELOG.adoc: -------------------------------------------------------------------------------- 1 | = Changelog 2 | 3 | == v0.4.3 (Luscious Last) 4 | 5 | A minor release to add support for Snowflake bridges and to fix a fatal bug which could crash ProxAllium, as well as a few other quality of life improvements. 6 | 7 | You can now obtain ProxAllium via https://community.chocolatey.org/packages/proxallium[Chocolately], a package manager for Windows. It's maintained by https://github.com/Cossey[Stewart Cossey] (big thanks!). 8 | 9 | .Additions 10 | * Added support for the Snowflake pluggable transport 11 | * Added an option to run Tor setup manually 12 | 13 | .Changes 14 | * Main window no longer hides when minimized, instead it hides when closed 15 | 16 | .Fixes 17 | * An out-of-bounds bug in Tor output handling code 18 | 19 | == v0.4.2 (Luscious Last) 20 | 21 | This is a maintainence release with some updates to how ProxAllium is packaged, I no longer wish to package Tor along with ProxAllium for various reasons, mainly that I was no longer using ProxAllium in Windows myself and it was getting harder to keep track of new Tor releases and push an updated package everytime. 22 | 23 | I understand that it has been a while since the last release, but many things have happened since. I now have a full-timeish job that keeps me busy and I have also switched to Linux as my main operating system a while ago. The good news is that I have been working on a cross-platform version of ProxAllium, the progress is slow due to myself not being very experienced at writing a program in C and interacting with the system on a lower level... and also my job takes most of my time. 24 | 25 | .Additions 26 | * A new interactive guide for setting up Tor 27 | * A new setting to define the path for obfs4 pluggable transport in the configuration file 28 | 29 | .Changes 30 | * Tor is no longer packaged along with ProxAllium 31 | 32 | == v0.4 (Luscious Last) 33 | (_Thanks to my dear friend TheSaint for suggesting the name for this release_) 34 | 35 | This will probably be the first and final stable release of ProxAllium written in AutoIt. I am planning to rewrite it in C so that it can take advantage of various thing which cannot be done in AutoIt. This was challenging to accomplish and I learned many new things about AutoIt and programming, it maybe a while before I start working on the cross-platform C version as I am busy with work and life these days. Thank you to everyone who has used ProxAllium! 36 | 37 | .Additions 38 | * *ProxAllium now directly communicates with Tor*. This means Tor is handled properly and opens up more possibilities! 39 | * Support for bridges with pluggable transports `obfs` (all versions) and `scramblesuit`, GUI included for configuration 40 | * Support for HTTP tunnel 41 | * Added documentation for all INI options 42 | * Added an option to start with Windows 43 | * Added an option to start minimized 44 | * Added an option to regenerate Tor configuration 45 | * Added an option to switch to clean Tor circuits 46 | 47 | .Fixed and changes 48 | * Tor Output now resets after starting Tor instead of resetting everytime Tor stops or crashes 49 | * Paths from configuration (`config.ini`) are no longer converted to absolute paths internally, this prevents use of absolute paths in the generated `torrc` file which may cause portability issues 50 | 51 | == v0.3-beta (GUI Goodness) 52 | Finally out of alpha! :) 53 | 54 | .Additions 55 | * **New GUI** with buttons, text fields, menubar, status indicator etc. 56 | * Added "Hostname" 57 | * Added Tray Tips (ProxAllium will notify you about Tor) 58 | * Added multi-instance detection (ProxAllium will detect if it is already running) 59 | 60 | .Fixes and changes 61 | * Closing the Tor Output window will no longer prompt to stop Tor 62 | * AsciiDoc is used instead of Markdown 63 | * Fixed crashing if Tor was not initialized properly 64 | * Tor is handled better internally (ProxAllium can detect crashes now) 65 | * `config.ini` uses relative paths instead of absolute paths which can cause problems in a portable environment (Fixes https://github.com/DcodingTheWeb/ProxAllium/issues/1[#1]) 66 | * UPX is no longer used to compile ProxAllium, this should reduce anti-virus false positives. 67 | * More minor internal changes 68 | 69 | .Changes independent of ProxAllium's code 70 | * New website with documentation, screenshots, webchat etc! 71 | 72 | == v0.2-alpha (Featury Feast) 73 | .Additions 74 | * `ProxAllium.exe` now has its Product Version property filled 75 | * Added ability to show Error/Warning messages made by Tor 76 | * Added ability to Stop/Start Tor without restarting ProxAllium! 77 | * Added ability to auto-generate `config.ini` (Therefore there is no need to pack `config.ini` in the release packages) 78 | * Added support for HTTP(S) and SOCKS4/5 proxies (No GUI yet to configure these though) 79 | 80 | .Fixes and changes 81 | * **Fixed a lot of bugs** (including the bug where ProxAllium was not stopping Tor when exiting) 82 | * **Optimisation and cleanup** 83 | * Updated `README.md` and `CREDITS.md` 84 | * Changed the internal structure/workings/design of ProxAllium 85 | * Changed some text to be more meaningful 86 | * Changed Tor's data directories location (You can now delete the `data` directory in `Tor/data` if you are upgrading) 87 | * Tor Output Window no longer asks for confirmation if Tor has already exited 88 | * ProxAllium no longer prompts to exit after closing Tor 89 | 90 | (You can also https://github.com/DcodingTheWeb/ProxAllium/compare/v0.1-alpha...v0.2-alpha[view] the complete code changes across the previous release if you want) 91 | 92 | **EDIT (23-02-2017)**: Added PGP signature to the list of downloads, you can find Dcoding The Web's public key https://dcodingtheweb.com/key.asc[here]. 93 | -------------------------------------------------------------------------------- /ProcessEx.au3: -------------------------------------------------------------------------------- 1 | #include-once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "IsMgcNumPresent.au3" 11 | 12 | #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 13 | 14 | ; #INDEX# ======================================================================================================================= 15 | ; Title ............: Process UDF. 16 | ; AutoIt Version ...: 3.3.14.1 17 | ; Description ......: UDF for AutoIt which contains useful functions which can be used to interact with processes in windows! 18 | ; Author(s) ........: Damon Harris (TheDcoder). 19 | ; This UDF Uses ....: PslatyDS's Code - https://www.autoitscript.com/forum/topic/98602-run-not-runwait-with-dos-exit-code/?do=findComment&comment=720326 20 | ; Is Magic Number Present? - https://git.io/vPFjk 21 | ; Links ............: GitHub - https://github.com/TheDcoder/Process-UDF-for-AutoIt/ 22 | ; AutoIt Forum - https://www.autoitscript.com/forum/topic/174697-process-udf-get-both-the-output-the-exit-code 23 | ; =============================================================================================================================== 24 | 25 | ; #CURRENT# ===================================================================================================================== 26 | ; _Process_RunCommand 27 | ; _Process_WaitUntil 28 | ; _Process_GetPID 29 | ; _Process_GetPath 30 | ; _Process_GetHandle 31 | ; _Process_CloseHandle 32 | ; _Process_GetExitCode 33 | ; _Process_DebugRunCommand 34 | ; =============================================================================================================================== 35 | 36 | ; #INTERNAL_USE_ONLY# =========================================================================================================== 37 | ; __Process_WM_SIZE 38 | ; =============================================================================================================================== 39 | 40 | ; #CONSTANTS# =================================================================================================================== 41 | Global Const $PROCESS_RUN = 2, $PROCESS_RUNWAIT = 4, $PROCESS_EXIST = 8, $PROCESS_NOTEXIST = 16, $PROCESS_DEBUG = 32 42 | 43 | Global Const $PROCESS_COMMAND = @ComSpec & " /c " ; Use this in RunCommand function to run commands 44 | ; =============================================================================================================================== 45 | 46 | ; #FUNCTION# ==================================================================================================================== 47 | ; Name ..........: _Process_RunCommand 48 | ; Description ...: Runs a command or a executable 49 | ; Syntax ........: _Process_RunCommand($iMode, $sExecutable [, $sWorkingDir = "" [, $iRunOptFlag = $STDERR_MERGED]]) 50 | ; Parameters ....: $iMode - Mode in which this function should operate, See Remarks. 51 | ; $sExecutable - The command to run/execute (along with any arguments). 52 | ; $sWorkingDir - [optional] The working directroy for the command. Default is "". 53 | ; $iRunOptFlag - [optional] The Opt flag for the Run function. Default is $STDERR_MERGED. 54 | ; Return values .: Success: Mode $PROCESS_RUN : Will return the process handle & @extended will contain the PID of the command 55 | ; Mode $PROCESS_RUNWAIT : Will return the output & @extended will contain the exit code for the function 56 | ; Failure: Will return False & @error will contain: 57 | ; 1 - If the $iMode flag is invalid 58 | ; 2 - If the command is invalid 59 | ; Author ........: TheDcoder 60 | ; Remarks .......: 1. The ONLY valid modes are: $PROCESS_RUN & $PROCESS_RUNWAIT 61 | ; $PROCESS_RUN : Will act similarly to Run function, See Return values 62 | ; $PROCESS_RUNWAIT : Will act similarly to RunWait function, See Return values 63 | ; If you use $PROCESS_RUN then use _Process_GetExitCode to get the exit code & use StdoutRead to get the output of the command 64 | ; 2. Use $PROCESS_COMMAND to run commands like this: $PROCESS_COMMAND & "ping 127.0.0.1" 65 | ; 3. Add $PROCESS_DEBUG to $iMode to automagically debug the command, $PROCESS_RUN is equivalent to $PROCESS_RUNWAIT in this case 66 | ; Related .......: Run, RunWait 67 | ; Example .......: Yes, see example.au3 68 | ; ===============================================================================================================================; Functions 69 | Func _Process_RunCommand($iMode, $sExecutable, $sWorkingDir = "", $iRunOptFlag = $STDERR_MERGED) 70 | Local $iExitCode = 0 ; Declare the exit code variable before hand 71 | Local $sOutput = "" ; Declare the output variable before hand 72 | Local $bDebug = IsMgcNumPresent($PROCESS_DEBUG, $iMode) ; Check if $PROCESS_DEBUG is present. 73 | Select ; Select... 74 | Case IsMgcNumPresent($PROCESS_RUN, $iMode) ; If the mode is $PROCESS_RUN 75 | $iMode = $PROCESS_RUN 76 | 77 | Case IsMgcNumPresent($PROCESS_RUNWAIT, $iMode) ; If the mode is $PROCESS_RUNWAIT 78 | $iMode = $PROCESS_RUNWAIT 79 | 80 | Case Else 81 | Return SetError(1, 0, False) ; If the mode is invalid... 82 | EndSelect 83 | Local $iPID = Run($sExecutable, $sWorkingDir, @SW_HIDE, $iRunOptFlag) ; Run!!! :P 84 | If @error Then Return SetError(2, 0, False) ; If the command is invalid... 85 | Local $hProcessHandle = _Process_GetHandle($iPID) ; Get the handle of the process 86 | If $iMode = $PROCESS_RUN Then 87 | If Not $bDebug Then Return SetExtended($iPID, $hProcessHandle) ; If the function is in Run mode then return the PID & Process Handle 88 | $sOutput = _Process_DebugRunCommand($hProcessHandle, $iPID) ; Debug the process 89 | $iExitCode = _Process_GetExitCode($hProcessHandle) ; Note the exit code 90 | Return SetExtended($iExitCode, $sOutput) ; Return the output & exit code 91 | EndIf 92 | If Not $bDebug Then 93 | While ProcessExists($iPID) 94 | $sOutput &= StdoutRead($iPID) ; Capture the output 95 | Sleep(10) ; Don't kill the CPU 96 | WEnd 97 | $sOutput &= StdoutRead($iPID) ; Capture any remaining output 98 | $iExitCode = _Process_GetExitCode($hProcessHandle) ; Note the exit code 99 | Return SetExtended($iExitCode, $sOutput) ; Return the exit code & the output :D 100 | EndIf 101 | $sOutput = _Process_DebugRunCommand($hProcessHandle, $iPID) ; Debug the process 102 | $iExitCode = _Process_GetExitCode($hProcessHandle) ; Note the exit code 103 | Return SetExtended($iExitCode, $sOutput) ; Return the output & exit code 104 | EndFunc 105 | 106 | ; #FUNCTION# ==================================================================================================================== 107 | ; Name ..........: _Process_WaitUntil 108 | ; Description ...: Waits until a process starts or quits. Also returns the exit code... 109 | ; Syntax ........: _Process_WaitUntil($iMode, $vProcess [, $iUpdateInterval = 10]) 110 | ; Parameters ....: $iMode - Mode in which this function should operate, See Remarks. 111 | ; $vProcess - The PID or Name of the process, Same as ProcessExist's "process" parameter. 112 | ; $iUpdateInterval - [optional] The time (in milliseconds) to wait before performing another check. Default is 10. 113 | ; Return values .: Success: True and sets @extended to the exit code if the mode is $PROCESS_NOTEXIST 114 | ; Failure: False 115 | ; Special: 0(See Remarks) 116 | ; Author ........: TheDcoder 117 | ; Remarks .......: 1. There are only 2 valid modes: 118 | ; $PROCESS_EXIST : Waits until a process starts. 119 | ; $PROCESS_NOTEXIST : Waits until a process quits. 120 | ; 2. 0 is returned when unable to retrive the PID of the process when in $PROCESS_NOTEXIST as the mode, 121 | ; There is an good chance that the process has already quit before the function starts checking. 122 | ; Example .......: No 123 | ; =============================================================================================================================== 124 | Func _Process_WaitUntil($iMode, $vProcess, $iUpdateInterval = 10) 125 | If $iMode = $PROCESS_NOTEXIST And Not IsInt($vProcess) Then ; If it is in $PROCESS_NOTEXIST mode & not an PID 126 | $vProcess = _Process_GetPID($vProcess) ; Get the PID 127 | If @error Then Return 0 ; Return Immediatly 128 | EndIf 129 | Switch $iMode ; Switch to the required mode to opreate in. 130 | Case $PROCESS_EXIST 131 | While Not ProcessExists($vProcess) ; Wait for the process to start 132 | Sleep($iUpdateInterval) ; Some mercy on the CPU 133 | WEnd 134 | Return True ; Return True 135 | 136 | Case $PROCESS_NOTEXIST 137 | Local $hProcessHandle = _Process_GetHandle($vProcess) ; Get the process handle :) 138 | While ProcessExists($vProcess) ; Wait for the process to quit 139 | Sleep($iUpdateInterval) ; Some mercy on the CPU 140 | WEnd 141 | Return SetExtended(_Process_GetExitCode($hProcessHandle), True) ; Return True & set @extended to the exit code 142 | 143 | Case Else 144 | Return False 145 | EndSwitch 146 | EndFunc 147 | 148 | ; #FUNCTION# ==================================================================================================================== 149 | ; Name ..........: _Process_GetPID 150 | ; Description ...: Gets the PID of the process using the name of the process 151 | ; Syntax ........: _Process_GetPID($sProcess) 152 | ; Parameters ....: $sProcess - The name of the process. 153 | ; Return values .: Success: The PID of the process 154 | ; Failure: False & sets @error to non-zero 155 | ; Author ........: TheDcoder 156 | ; Remarks .......: If multiple processes exist then the most recent process's PID is returned. 157 | ; Example .......: No 158 | ; =============================================================================================================================== 159 | Func _Process_GetPID($sProcess) 160 | Local $aProcess = ProcessList($sProcess) ; List processes with that name 161 | If @error Or $aProcess[0][0] = 0 Then Return SetError(@error, False) ; Return False & set @error to non-zero if an error 162 | Return $aProcess[1][1] ; Return the PID 163 | EndFunc 164 | 165 | ; #FUNCTION# ==================================================================================================================== 166 | ; Name ..........: _Process_GetPath 167 | ; Description ...: Get the path of a process along with its arguments (if any) 168 | ; Syntax ........: _Process_GetPath($vProcess) 169 | ; Parameters ....: $vProcess - The PID or name of the process. 170 | ; Return values .: Success: The path of process with its arguments 171 | ; Failure: False & sets @error to 1 172 | ; Author ........: TheDcoder 173 | ; Remarks .......: The return value is in this format: X:\Process.exe -Argument1 -ArgumentN... 174 | ; Example .......: No 175 | ; =============================================================================================================================== 176 | Func _Process_GetPath($vProcess) 177 | Local Const $eiCharsToTrim = 12 178 | If Not IsInt($vProcess) Then $vProcess = _Process_GetPID($vProcess) ; Convert process name to PID 179 | Local $sCommandline = "wmic" ; Declare the commandline string 180 | $sCommandline &= ' process' 181 | $sCommandline &= ' where "' & "processid='" & $vProcess & "'" & '"' 182 | $sCommandline &= ' get commandline /format:list' 183 | Local $sOutput = _Process_RunCommand($PROCESS_RUNWAIT, $sCommandline) ; Run the command... 184 | ; Thanks to rojo for this command at stackowerflow: http://stackoverflow.com/a/32609300/3815591 185 | $sOutput = StringStripWS($sOutput, $STR_STRIPLEADING + $STR_STRIPTRAILING) ; Remove whitespaces attached to the string 186 | If $sOutput = "No Instance(s) Available." Then Return SetError(1, 0, False) ; If process was not found... 187 | Local $sCommand = StringTrimLeft($sOutput, $eiCharsToTrim) ; Trim the Commandline= 188 | Return $sCommand ; Return 189 | EndFunc 190 | 191 | ; #FUNCTION# ==================================================================================================================== 192 | ; Name ..........: _Process_GetHandle 193 | ; Description ...: Gets the handle of a process, will be used later to retrive the exit code 194 | ; Syntax ........: _Process_GetHandle($vProcess) 195 | ; Parameters ....: $vProcess - The PID or name of the process. 196 | ; Return values .: Success: Process handle 197 | ; Failure: 0 & Sets @error to non-zero 198 | ; Author ........: PsaltyDS 199 | ; Modified ......: TheDcoder: Comments, "If...Else...EndIf" to "If...Then", Return value for failure & Name of the function 200 | ; Example .......: No 201 | ; =============================================================================================================================== 202 | Func _Process_GetHandle($vProcess) 203 | If Not IsInt($vProcess) Then $vProcess = _Process_GetPID($vProcess) ; Get the PID of the process if its not a PID ;) 204 | Local $avRET = DllCall("kernel32.dll", "ptr", "OpenProcess", "int", $PROCESS_QUERY_INFORMATION, "int", 0, "int", $vProcess) ; Get the process handle 205 | If @error Then Return SetError(1, 0, 0) ; If the process does not exists... 206 | Return $avRET[0] ; Return handle 207 | EndFunc 208 | 209 | ; #FUNCTION# ==================================================================================================================== 210 | ; Name ..........: _Process_CloseHandle 211 | ; Description ...: Closes the Process Handle of a process 212 | ; Syntax ........: _Process_CloseHandle($hProcessHandle) 213 | ; Parameters ....: $hProcessHandle - A Process Handle. 214 | ; Return values .: Success: True 215 | ; Failure: False & sets @error to non-zero 216 | ; Author ........: PsaltyDS 217 | ; Modified ......: TheDcoder: Comments, "If...Else...EndIf" to "If...Then", Return values & Name of the function 218 | ; Example .......: No 219 | ; =============================================================================================================================== 220 | Func _Process_CloseHandle($hProcessHandle) 221 | DllCall("kernel32.dll", "int", "CloseHandle", "ptr", $hProcessHandle) ; Close the handle 222 | If @error Then Return SetError(@error, 0, False) ; If invalid handle... 223 | Return True ; Return True if success 224 | EndFunc 225 | 226 | ; #FUNCTION# ==================================================================================================================== 227 | ; Name ..........: _Process_GetExitCode 228 | ; Description ...: Gets the exit code of a process 229 | ; Syntax ........: _Process_GetExitCode($hProcessHandle[, $bCloseHandle = True]) 230 | ; Parameters ....: $hProcessHandle - A Process Handle. 231 | ; $bCloseHandle - [optional] Do you want to close the $hProcessHandle?. Default is True. 232 | ; Return values .: Success: Exit Code 233 | ; Failure: Returns 0 & sets @error to non-zero 234 | ; Author ........: PsaltyDS 235 | ; Modified ......: TheDcoder: Comments & Name of the function 236 | ; Example .......: No 237 | ; =============================================================================================================================== 238 | Func _Process_GetExitCode($hProcessHandle, $bCloseHandle = True) 239 | Local $t_ExitCode = DllStructCreate("int") ; Its the container for the exit code 240 | DllCall("kernel32.dll", "int", "GetExitCodeProcess", "ptr", $hProcessHandle, "ptr", DllStructGetPtr($t_ExitCode)) ; Store the exit code in the container 241 | If @error Then Return SetError(1, 0, 0) ; If it is a invalid $hProcessHandle then return error 242 | If $bCloseHandle Then _Process_CloseHandle($hProcessHandle) ; Close the $hProcessHandle 243 | Return DllStructGetData($t_ExitCode, 1) ; Return exit code from the container 244 | EndFunc 245 | 246 | ; #FUNCTION# ==================================================================================================================== 247 | ; Name ..........: _Process_DebugRunCommand 248 | ; Description ...: Debugs a command in CMD style, see the example. 249 | ; Syntax ........: _Process_DebugRunCommand($hProcessHandle, $iPID[, $sGuiTitle = "Command Prompt Simulator"]) 250 | ; Parameters ....: $hProcessHandle - The Process Handle. 251 | ; $iPID - The PID of the Process. 252 | ; $sGuiTitle - [optional] The title of the Debug window. Default is "Command Prompt Simulator". 253 | ; Return values .: Success: Will return the output & @extended will contain the exit code for the function 254 | ; Failure: N/A 255 | ; Author ........: TheDcoder 256 | ; Modified ......: N/A 257 | ; Remarks .......: Make sure that the Process Handle & the PID are of the same process, otherwise you get the wrong exit code :P 258 | ; Example .......: Yes, see example.au3 259 | ; =============================================================================================================================== 260 | Func _Process_DebugRunCommand($hProcessHandle, $iPID, $sGuiTitle = "Command Prompt Simulator") 261 | Local $aGrayCmdColor[3] = [197, 197, 197] ; CMD Text Color's combination in RGB 262 | Local Const $iGrayCmdColor = _ColorSetRGB($aGrayCmdColor) ; Get the RGB code of CMD Text Color 263 | Local $hGUI = GUICreate($sGuiTitle, 639, 299, -1, -1, $WS_OVERLAPPEDWINDOW) ; Create the GUI 264 | Local $idEdit = GUICtrlCreateEdit("", 0, 0, 639, 299, BitOR($WS_HSCROLL, $WS_VSCROLL, $ES_MULTILINE, $ES_READONLY, $ES_AUTOVSCROLL), 0) ; Create the Edit control :) 265 | Global $g__hEdit = GUICtrlGetHandle($idEdit) ; Get the edit control's handle 266 | GUICtrlSetBkColor($idEdit, $COLOR_BLACK) ; Set the background color 267 | GUICtrlSetColor($idEdit, $iGrayCmdColor) ; Set the text color 268 | GUICtrlSetFont($idEdit, 8, 0, 0, "Fixedsys") 269 | GUIRegisterMsg($WM_SIZE, "__Process_WM_SIZE") ; Register the resizing function 270 | GUISetState(@SW_SHOW, $hGUI) ; Reveal the GUI 271 | _GUICtrlEdit_AppendText($g__hEdit, "The Process: " & _Process_GetPath($iPID) & @CRLF) ; Append the process information 272 | Local $sOutput = "", $sPartialOutput = "" ; Declare the output variable 273 | While ProcessExists($iPID) ; Loop until the process finishes 274 | $sPartialOutput = StdoutRead($iPID) ; Record the output 275 | $sOutput &= $sPartialOutput 276 | _GUICtrlEdit_AppendText($g__hEdit, $sPartialOutput) ; Append the output 277 | Sleep(250) ; Don't kill the CPU 278 | WEnd 279 | $sPartialOutput = StdoutRead($iPID) ; Record the output 280 | $sOutput &= $sPartialOutput 281 | _GUICtrlEdit_AppendText($g__hEdit, $sPartialOutput) ; Append any remaining chunks of output 282 | Local $iExitCode = _Process_GetExitCode($hProcessHandle) 283 | _GUICtrlEdit_AppendText($g__hEdit, @CRLF & @CRLF & "Debug Complete! The Exit Code was: " & $iExitCode) ; Display the exit code 284 | ; Same steps as in the above loop 285 | Local $nMsg = 0 286 | While 1 ; Wait for user to close the window 287 | $nMsg = GUIGetMsg() 288 | Switch $nMsg 289 | Case $GUI_EVENT_CLOSE 290 | ExitLoop 291 | EndSwitch 292 | WEnd 293 | GUIDelete($hGUI) ; Delete the GUI 294 | Return SetExtended($iExitCode, $sOutput) ; Return True 295 | EndFunc 296 | 297 | Func __Process_WM_SIZE($hWnd, $iMsg, $wParam, $lParam) 298 | Local $iWidth = _WinAPI_LoWord($lParam) 299 | Local $iHeight = _WinAPI_HiWord($lParam) 300 | 301 | _WinAPI_MoveWindow($g__hEdit, 2, 2, $iWidth - 4, $iHeight - 4) 302 | 303 | Return 0 304 | #forceref $hWnd, $iMsg, $wParam 305 | EndFunc ; Thanks Mat :) -------------------------------------------------------------------------------- /Tor.au3: -------------------------------------------------------------------------------- 1 | #include-once 2 | #include 3 | #include 4 | #include 5 | #include "ProcessEx.au3" 6 | 7 | #AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w- 4 -w 5 -w 6 -w- 7 8 | 9 | ; #INDEX# ======================================================================================================================= 10 | ; Title ............: Tor UDF. 11 | ; AutoIt Version ...: 3.3.14.1 12 | ; Description ......: UDF for Tor, meant to be used by ProxAllium. Not the best Tor UDF around ;) 13 | ; Author(s) ........: Damon Harris (TheDcoder). 14 | ; This UDF Uses ....: Process UDF (439a393) - https://git.io/vXmF6 15 | ; Links ............: GitHub - https://github.com/DcodingTheWeb/ProxAllium/blob/master/Tor.au3 16 | ; =============================================================================================================================== 17 | 18 | ; #CURRENT# ===================================================================================================================== 19 | ; _Tor_CheckVersion - Check the version of Tor. 20 | ; _Tor_Controller_Authenticate - Authenticate with the Tor controller 21 | ; _Tor_Controller_CheckReplyForError - Check for errors in a reply/response from the controller 22 | ; _Tor_Controller_Connect - Connect to Tor's TCP controller interface 23 | ; _Tor_Controller_SendRaw - Send raw commands to the controller interface 24 | ; _Tor_Controller_TakeOwnership - Take ownership of the Tor process (Tor closes if it loses the connection) 25 | ; _Tor_Controller_WaitForMsg - Wait for a message to arrive completely and get it 26 | ; _Tor_GenHash - Generate a hash for use with Tor 27 | ; _Tor_Find - Lists the tor executables and geoip files. 28 | ; _Tor_SetPath - Sets Tor.exe's path, it will be used by the UDF in the rest of the functions. 29 | ; _Tor_Start - Starts Tor 30 | ; _Tor_Stop - Stops Tor 31 | ; _Tor_SwitchCircuit - Switch Tor to clean circuits so new application requests don't share any circuits with old ones 32 | ; _Tor_VerifyConfig - Check if the configuration is valid. 33 | ; =============================================================================================================================== 34 | 35 | ; #CONSTANTS# =================================================================================================================== 36 | Global Const $TOR_ERROR_GENERIC = 1 ; Reserved for generic errors. 37 | Global Const $TOR_ERROR_PROCESS = 2 ; Error related to Tor.exe's process. 38 | Global Const $TOR_ERROR_VERSION = 3 ; Error related to version. 39 | Global Const $TOR_ERROR_CONFIG = 4 ; Error related to configuration. 40 | Global Const $TOR_ERROR_NETWORK = 5 ; Error related to networking (TCP). 41 | Global Const $TOR_ERROR_CONTROLLER = 6 ; Error related to the Tor controller. 42 | 43 | Global Enum $TOR_VERSION, $TOR_VERSION_NUMBER, $TOR_VERSION_GIT ; Associated with $aTorVersion returned by _Tor_CheckVersion 44 | Global Enum $TOR_PROCESS_PID, $TOR_PROCESS_HANDLE, $TOR_PROCESS_SOCKET ; Associated with $aTorProcess returned by _Tor_Start 45 | Global Enum $TOR_CONTROLLER_AUTH_NONE, $TOR_CONTROLLER_AUTH_HASH ; Methods of authentication with Tor controller 46 | Global Enum $TOR_FIND_VERSION, $TOR_FIND_PATH ; Associated with $aList returned by _Tor_Find 47 | Global Enum $TOR_FIND_TORLIST, $TOR_FIND_GEOIP, $TOR_FIND_GEOIP6 ; Associated with arrays found inside $aList returned by _Tor_Find 48 | ; =============================================================================================================================== 49 | 50 | ; #VARIABLES# =================================================================================================================== 51 | Global $g__sTorPath = "" ; Path to Tor.exe 52 | ; =============================================================================================================================== 53 | 54 | TCPStartup() 55 | OnAutoItExitRegister(__Tor_OnExitTCPShutdown) 56 | 57 | ; #FUNCTION# ==================================================================================================================== 58 | ; Name ..........: _Tor_CheckVersion 59 | ; Description ...: Check the version of Tor. 60 | ; Syntax ........: _Tor_CheckVersion([$sTorPath = $g__sTorPath]) 61 | ; Parameters ....: $sTorPath - [optional] Path of Tor's executable. Default is $g__sTorPath. 62 | ; Return values .: Success: $aTorVersion with 3 elements: 63 | ; $aTorVersion[$TOR_VERSION] - Will contain the full version string, see remarks for the format. 64 | ; $aTorVersion[$TOR_VERSION_NUMBER] - Will contain the version number in this format: x.x.x.x 65 | ; $aTorVersion[$TOR_VERSION_GIT] - Will contain Git's truncated hash of the commit. 66 | ; Failure: False and @error set to: 67 | ; $TOR_ERROR_PROCESS - If it is an invalid Tor path. 68 | ; $TOR_ERROR_VERSION - If unable to determine version, @extended is set to StringRegExp's @error. 69 | ; Author ........: Damon Harris (TheDcoder) 70 | ; Remarks .......: $TOR_VERSION Format : x.x.x.x (git-a1b2c3d4e5f6g7h8) 71 | ; Example: 0.2.9.10 (git-1f6c8eda0073f464) 72 | ; The git hash may not be present at all times. 73 | ; Example .......: No 74 | ; =============================================================================================================================== 75 | Func _Tor_CheckVersion($sTorPath = $g__sTorPath) 76 | Local $sOutput = _Process_RunCommand($PROCESS_RUNWAIT, $sTorPath & ' --version') 77 | If @error Then Return SetError($TOR_ERROR_PROCESS, @error, False) 78 | Local $aTorVersion[3] 79 | Local $aRegEx = StringRegExp($sOutput, '(\d*\.\d*\.\d*\.\d*)(?: \(git-([a-z0-9]{16})\))?', $STR_REGEXPARRAYFULLMATCH) 80 | If @error Then Return SetError($TOR_ERROR_VERSION, @error, False) 81 | $aTorVersion[$TOR_VERSION] = $aRegEx[0] 82 | $aTorVersion[$TOR_VERSION_NUMBER] = $aRegEx[1] 83 | If UBound($aRegEx) = 3 Then $aTorVersion[$TOR_VERSION_GIT] = $aRegEx[2] 84 | Return $aTorVersion 85 | EndFunc 86 | 87 | ; #FUNCTION# ==================================================================================================================== 88 | ; Name ..........: _Tor_Controller_Authenticate 89 | ; Description ...: Authenticate with the Tor controller 90 | ; Syntax ........: _Tor_Controller_Authenticate(Byref $aTorProcess[, $iMethod = $TOR_CONTROLLER_AUTH_NONE[, $vPassword = ""]]) 91 | ; Parameters ....: $aTorProcess - [in/out] $aTorProcess from _Tor_Start. 92 | ; $iMethod - [optional] One of the $TOR_CONTROLLER_AUTH constants. Default is $TOR_CONTROLLER_AUTH_NONE. 93 | ; $vPassword - [optional] Password. Default is "" (None). 94 | ; Return values .: Success: True 95 | ; Failure: @error is set to: 96 | ; $TOR_ERROR_NETWORK - If there was a network error, @extended is set to TCPSend or TCPRecv's error. 97 | ; $TOR_ERROR_CONTROLLER - If Tor replied with an unexpected response, the response string is returned. 98 | ; Author ........: Damon Harris (TheDcoder) 99 | ; Remarks .......: This should be the second step after _Tor_Controller_Connect 100 | ; Example .......: No 101 | ; =============================================================================================================================== 102 | Func _Tor_Controller_Authenticate(ByRef $aTorProcess, $iMethod = $TOR_CONTROLLER_AUTH_NONE, $vPassword = "") 103 | Local $sRawCommand = "AUTHENTICATE" 104 | If $iMethod = $TOR_CONTROLLER_AUTH_HASH Then $sRawCommand &= ' "' & $vPassword & '"' 105 | _Tor_Controller_SendRaw($aTorProcess, $sRawCommand) 106 | If @error Then Return SetError($TOR_ERROR_NETWORK, @extended, False) 107 | Local $sResponse = _Tor_Controller_WaitForMsg($aTorProcess) 108 | If @error Then Return SetError($TOR_ERROR_NETWORK, @extended, False) 109 | _Tor_Controller_CheckReplyForError($sResponse) 110 | If Not @error Then Return True 111 | Return SetError($TOR_ERROR_CONTROLLER, 0, $sResponse) 112 | EndFunc 113 | 114 | ; #FUNCTION# ==================================================================================================================== 115 | ; Name ..........: _Tor_Controller_CheckReplyForError 116 | ; Description ...: Check for errors in a reply/response from the controller 117 | ; Syntax ........: _Tor_Controller_CheckReplyForError($sReply) 118 | ; Parameters ....: $sReply - The reply or response from the controller server. 119 | ; Return values .: Success: True 120 | ; Failure: False and @error set to $TOR_ERROR_GENERIC, @extended is set to 1 if error is fatal. 121 | ; Special: @extended is set to 2 and @error is not set, this happens if the status is unknown. 122 | ; Author ........: Damon Harris (TheDcoder) 123 | ; Example .......: No 124 | ; =============================================================================================================================== 125 | Func _Tor_Controller_CheckReplyForError($sReply) 126 | Local $aReply = StringSplit($sReply, ' ') 127 | Local $sStatusCode = $aReply[1] 128 | Switch StringLeft($sStatusCode, 1) 129 | Case "2" ; All OK 130 | Return True 131 | Case "4" ; Temporary Negative (Non-fatal error) 132 | Return SetError($TOR_ERROR_GENERIC, 0, False) 133 | Case "5" ; Permanent Negetive (Fatal error) 134 | Return SetError($TOR_ERROR_GENERIC, 1, False) 135 | Case Else ; Unknown error status (error???) 136 | Return SetExtended(2, False) 137 | EndSwitch 138 | EndFunc 139 | 140 | ; #FUNCTION# ==================================================================================================================== 141 | ; Name ..........: _Tor_Controller_Connect 142 | ; Description ...: Connect to Tor's TCP controller interface 143 | ; Syntax ........: _Tor_Controller_Connect(Byref $aTorProcess, $iPort[, $sAddress = '127.0.0.1']) 144 | ; Parameters ....: $aTorProcess - [in/out] $aTorProcess from _Tor_Start. 145 | ; $iPort - The port where the controller interface is listening. 146 | ; $sAddress - [optional] IP Address of the host. Default is '127.0.0.1'. 147 | ; Return values .: Success: True 148 | ; Failure: False and @error is set to TCPConnect's @error 149 | ; Author ........: Damon Harris (TheDcoder) 150 | ; Remarks .......: Autentication should be done before beginning the communication 151 | ; Example .......: No 152 | ; =============================================================================================================================== 153 | Func _Tor_Controller_Connect(ByRef $aTorProcess, $iPort, $sAddress = '127.0.0.1') 154 | Local $iSocket = TCPConnect($sAddress, $iPort) 155 | If @error Then Return SetError(@error, 0, False) 156 | $aTorProcess[$TOR_PROCESS_SOCKET] = $iSocket 157 | Return True 158 | EndFunc 159 | 160 | ; #FUNCTION# ==================================================================================================================== 161 | ; Name ..........: _Tor_Controller_SendRaw 162 | ; Description ...: Send raw commands to the controller interface 163 | ; Syntax ........: _Tor_Controller_SendRaw($aTorProcess, $sRawCommand[, $bAutoCRLF = True]) 164 | ; Parameters ....: $aTorProcess - $aTorProcess from _Tor_Start. 165 | ; $sRawCommand - The string containing the raw command, CRLF is optional by default. 166 | ; $bAutoCRLF - [optional] If True, CRLF is automatically appended before sending the command. Default is True. 167 | ; Return values .: Success: True 168 | ; Failure: False and @error is set to $TOR_ERROR_NETWORK & @extended is set to TCPSend's @error 169 | ; Author ........: Damon Harris (TheDcoder) 170 | ; Example .......: No 171 | ; =============================================================================================================================== 172 | Func _Tor_Controller_SendRaw(ByRef $aTorProcess, $sRawCommand, $bAutoCRLF = True) 173 | If $bAutoCRLF Then $sRawCommand &= @CRLF 174 | TCPSend($aTorProcess[$TOR_PROCESS_SOCKET], $sRawCommand) 175 | If @error Then Return SetError($TOR_ERROR_NETWORK, @error, False) 176 | Return True 177 | EndFunc 178 | 179 | ; #FUNCTION# ==================================================================================================================== 180 | ; Name ..........: _Tor_Controller_TakeOwnership 181 | ; Description ...: Take ownership of the Tor process (Tor closes if it loses the connection) 182 | ; Syntax ........: _Tor_Controller_TakeOwnership($aTorProcess) 183 | ; Parameters ....: $aTorProcess - [in/out] $aTorProcess from _Tor_Start. 184 | ; Return values .: Success: True 185 | ; Failure: False, @error set to: 186 | ; $TOR_ERROR_GENERIC - If controller sent a reply indicating an error and @extended is 187 | ; set to _Tor_Controller_CheckReplyForError's @extended 188 | ; $TOR_ERROR_NETWORK - If a network error occurs, @extended is set to TCPSend/TCPRecv's @error 189 | ; Author ........: Damon Harris (TheDcoder) 190 | ; Example .......: No 191 | ; =============================================================================================================================== 192 | Func _Tor_Controller_TakeOwnership($aTorProcess) 193 | _Tor_Controller_SendRaw($aTorProcess, 'TAKEOWNERSHIP') 194 | If @error Then Return SetError($TOR_ERROR_NETWORK, @extended, False) 195 | Local $sReply = _Tor_Controller_WaitForMsg($aTorProcess) 196 | If @error Then Return SetError($TOR_ERROR_NETWORK, @extended, False) 197 | _Tor_Controller_CheckReplyForError($sReply) 198 | If @error Then Return SetError($TOR_ERROR_GENERIC, @extended, False) 199 | Return True 200 | EndFunc 201 | 202 | ; #FUNCTION# ==================================================================================================================== 203 | ; Name ..........: _Tor_Controller_WaitForMsg 204 | ; Description ...: Wait for a message to arrive completely and get it 205 | ; Syntax ........: _Tor_Controller_WaitForMsg(Byref $aTorProcess[, $iTimeout = 0[, $bTrimCRLF = True]]) 206 | ; Parameters ....: $aTorProcess - [in/out] $aTorProcess from _Tor_Start. 207 | ; $iTimeout - [optional] Timeout in milliseconds. Default is 0 (no timeout). 208 | ; $bTrimCRLF - [optional] Trim the trailing CRLF in the message. Default is True. 209 | ; Return values .: Success: $sMessage 210 | ; Failure: $sMessage (can be blank or contain partial content) and @error is set to: 211 | ; $TOR_ERROR_NETWORK - If TCPRecv set an error, @extended is set to TCPRecv's @error 212 | ; $TOR_ERROR_GENERIC - If $iTimeout is reached 213 | ; Author ........: Damon Harris (TheDcoder) 214 | ; Example .......: No 215 | ; =============================================================================================================================== 216 | Func _Tor_Controller_WaitForMsg(ByRef $aTorProcess, $iTimeout = 0, $bTrimCRLF = True) 217 | Local $sMessage 218 | If $iTimeout > 0 Then Local $hTimer = TimerInit() 219 | Do 220 | $sMessage &= TCPRecv($aTorProcess[$TOR_PROCESS_SOCKET], 2) 221 | If @error Then Return SetError($TOR_ERROR_NETWORK, @error, $sMessage) 222 | If ($iTimeout > 0) And (TimerDiff($hTimer) >= $iTimeout) Then Return SetError($TOR_ERROR_GENERIC, 0, $sMessage) 223 | Sleep(10) 224 | Until (StringRight($sMessage, 2) = @CRLF) 225 | Return ($bTrimCRLF ? StringTrimRight($sMessage, 2) : $sMessage) 226 | EndFunc 227 | 228 | ; #FUNCTION# ==================================================================================================================== 229 | ; Name ..........: _Tor_Find 230 | ; Description ...: Lists the tor executables and geoip files. 231 | ; Syntax ........: _Tor_Find($vFolders) 232 | ; Parameters ....: $vFolders - $vFolders to search. Can be an array or a string delimited by a pipe charecter (|) 233 | ; Return values .: Success: $aList, See remarks for format. 234 | ; Failure: False and @error set to $TOR_ERROR_GENERIC 235 | ; Author ........: Damon Harris (TheDcoder) 236 | ; Remarks .......: 1. $aList is an array with 3 elements: 237 | ; $aList[$TOR_FIND_TORLIST] - This element contains the list of tor executables 238 | ; $aList[$TOR_FIND_GEOIP] - This element contains the list of GeoIP files 239 | ; $aList[$TOR_FIND_GEOIP6] - This element contains the list of GeoIP6 files 240 | ; Each of the elements are made up of 2 columns 241 | ; $TOR_FIND_VERSION - This column contains the version of the found file 242 | ; $TOR_FIND_PATH - This column contains the path fo the found file 243 | ; 2. This function can take some time to return. 244 | ; 3. Arrays inside $aList are not sorted! 245 | ; Example .......: No 246 | ; =============================================================================================================================== 247 | Func _Tor_Find($vFolders) 248 | If IsString($vFolders) Then $vFolders = StringSplit($vFolders, '|', $STR_NOCOUNT) 249 | Local $aFiles[0] 250 | For $sFolder In $vFolders 251 | _ArrayConcatenate($aFiles, _FileListToArrayRec($sFolder, "tor.exe;geoip;geoip6", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH), 1) 252 | Next 253 | If UBound($aFiles) = 0 Then Return SetError($TOR_ERROR_GENERIC, 0, False) 254 | Local $aTorList[0][2] 255 | Local $aGeoIP[0][2] 256 | Local $aGeoIPv6[0][2] 257 | Local $aPath 258 | Local $aTorVersion[0] 259 | Local $aGeoFileDate[0] 260 | For $sFile In $aFiles 261 | $aPath = _PathSplit($sFile, $vFolders, $vFolders, $vFolders, $vFolders) ; $vFolders is just used as a dummy here 262 | Switch $aPath[3] 263 | Case "tor" 264 | $aTorVersion = _Tor_CheckVersion($sFile) 265 | If Not @error Then _ArrayAdd($aTorList, $aTorVersion[$TOR_VERSION_NUMBER] & '|' & $sFile) 266 | 267 | Case "geoip", "geoip6" 268 | $aGeoFileDate = StringRegExp(FileReadLine($sFile), '([A-Z][a-z]*) ([\d]{1,2}) (\d{4})', $STR_REGEXPARRAYMATCH) 269 | If Not @error Then 270 | Switch $aPath[3] 271 | Case "geoip" 272 | _ArrayAdd($aGeoIP, _ArrayToString($aGeoFileDate, ' ') & '|' & $sFile) 273 | Case "geoip6" 274 | _ArrayAdd($aGeoIPv6, _ArrayToString($aGeoFileDate, ' ') & '|' & $sFile) 275 | EndSwitch 276 | EndIf 277 | EndSwitch 278 | Next 279 | Local $aList[3] = [$aTorList, $aGeoIP, $aGeoIPv6] 280 | Return $aList 281 | EndFunc 282 | 283 | ; #FUNCTION# ==================================================================================================================== 284 | ; Name ..........: _Tor_GenHash 285 | ; Description ...: Generate a hash for use with Tor 286 | ; Syntax ........: _Tor_GenHash($sString) 287 | ; Parameters ....: $sString - The string for which will the hash be calculated. 288 | ; Return values .: Success: $aHash (See Remarks) 289 | ; Failure: False and @error is set to: 290 | ; $TOR_ERROR_PROCESS - If Tor didn't launch or run successfully 291 | ; $TOR_ERROR_GENERIC - If the hash was not found in the output 292 | ; Author ........: Damon Harris (TheDcoder) 293 | ; Remarks .......: $aHash is an array with 3 elements: 294 | ; $aHash[0] - Contains the full hash (16:660537E3E1CD49996044A3BF558097A981F539FEA2F9DA662B4626C1C2) 295 | ; $aHash[1] - Contains the salt of the hash (660537E3E1CD4999) 296 | ; $aHash[2] - Contains the salted hash (44A3BF558097A981F539FEA2F9DA662B4626C1C2) 297 | ; Example .......: No 298 | ; =============================================================================================================================== 299 | Func _Tor_GenHash($sString) 300 | Local $sOutput = _Process_RunCommand($PROCESS_RUNWAIT, $g__sTorPath & ' --hash-password "' & $sString & '"') 301 | If @error Then Return SetError($TOR_ERROR_PROCESS, @error, False) 302 | Local $aHash = StringRegExp($sOutput, '16:([A-Z0-9]{16})60([A-Z0-9]{40})', $STR_REGEXPARRAYFULLMATCH) 303 | If @error Then Return SetError($TOR_ERROR_GENERIC, @error, False) 304 | Return $aHash 305 | EndFunc 306 | 307 | ; #FUNCTION# ==================================================================================================================== 308 | ; Name ..........: _Tor_SetPath 309 | ; Description ...: Sets Tor.exe's path, it will be used by the UDF in the rest of the functions. 310 | ; Syntax ........: _Tor_SetPath($sTorPath[, $bVerify = True]) 311 | ; Parameters ....: $sTorPath - Path of Tor.exe, can be relative or short. See Remarks. 312 | ; $bVerify - [optional] If set to False, no checkes are performed. Default is True. 313 | ; Return values .: Success: $aTorVersion from _Tor_CheckVersion or True if $bVerify is False. 314 | ; Failure: False and @error set to: 315 | ; $TOR_ERROR_GENERIC - If $sTorPath does not exist 316 | ; $TOR_ERROR_VERSION - If _Tor_CheckVersion failed to check Tor's version, @extended is set to _Tor_CheckVersion's @error. 317 | ; Author ........: Damon Harris (TheDcoder) 318 | ; Remarks .......: 1. The $sTorPath will always be converted to a long and absolute path before getting assinged. 319 | ; 2. The existing path assigned to Tor.exe will not change if _Tor_SetPath fails. 320 | ; 3. Set $bVerify to False to skip the version check, you will never get failure if you use this method. 321 | ; Example .......: No 322 | ; =============================================================================================================================== 323 | Func _Tor_SetPath($sTorPath, $bVerify = True) 324 | If Not $bVerify Then 325 | $g__sTorPath = $sTorPath 326 | Return True 327 | EndIf 328 | If Not FileExists($sTorPath) Then Return SetError($TOR_ERROR_GENERIC, 0, False) 329 | Local $sOldTorPath = $g__sTorPath 330 | $g__sTorPath = $sTorPath 331 | Local $aTorVersion = _Tor_CheckVersion() 332 | If @error Then 333 | $g__sTorPath = $sOldTorPath 334 | Return SetError($TOR_ERROR_VERSION, @error, False) 335 | EndIf 336 | Return $aTorVersion 337 | EndFunc 338 | 339 | ; #FUNCTION# ==================================================================================================================== 340 | ; Name ..........: _Tor_Start 341 | ; Description ...: Starts Tor 342 | ; Syntax ........: _Tor_Start($sConfig) 343 | ; Parameters ....: $sConfig - Path to the config/torrc file. 344 | ; Return values .: Success: $aTorProcess, See Remarks. 345 | ; Failure: $sCommand used to execute Tor and @error set to: 346 | ; $TOR_ERROR_PROCESS - If there was a problem starting the process 347 | ; $TOR_ERROR_CONFIG - If there was a problem during verification of the $sConfig 348 | ; Author ........: Damon Harris (TheDcoder) 349 | ; Remarks .......: $aTorProcess's Format: 350 | ; $aTorProcess[$TOR_PROCESS_HANDLE] - Contains the process handle of tor.exe 351 | ; $aTorProcess[$TOR_PROCESS_PID] - Contains the PID of tor.exe 352 | ; $aTorProcess[$TOR_PROCESS_SOCKET] - Reserved for the TCP socket, used by _Tor_Controller functions 353 | ; Example .......: No 354 | ; =============================================================================================================================== 355 | Func _Tor_Start($sConfig) 356 | _Tor_VerifyConfig($sConfig) 357 | If @error Then Return SetError($TOR_ERROR_CONFIG, @error, False) 358 | Local $aTorProcess[3] 359 | Local $sCommand = '"' & $g__sTorPath & '" --allow-missing-torrc --defaults-torrc "" -f "' & $sConfig & '"' 360 | $aTorProcess[$TOR_PROCESS_HANDLE] = _Process_RunCommand($PROCESS_RUN, $sCommand, @ScriptDir) 361 | If @error Then Return SetError($TOR_ERROR_PROCESS, @error, $sCommand) 362 | $aTorProcess[$TOR_PROCESS_PID] = @extended 363 | Return $aTorProcess 364 | EndFunc 365 | 366 | ; #FUNCTION# ==================================================================================================================== 367 | ; Name ..........: _Tor_Stop 368 | ; Description ...: Stops Tor 369 | ; Syntax ........: _Tor_Stop(Byref $aTorProcess) 370 | ; Parameters ....: $aTorProcess - [in/out] $aTorProcess from _Tor_Start. 371 | ; Return values .: Success: True and $aTorProcess is modified, See Remarks. 372 | ; Failure: False, @error set to: 373 | ; $TOR_ERROR_GENERIC - If $aTorProcess is invalid (does not contain 3 elements). 374 | ; $TOR_ERROR_PROCESS - If ProcessClose fails, @extended is set to ProcessClose's @error 375 | ; Author ........: Damon Harris (TheDcoder) 376 | ; Remarks .......: Tor is sent the shutdown signal first (using TCP) and if it fails, it is closed forcibly by ProcessClose 377 | ; $aTorProcess[$TOR_PROCESS_PID] and $aTorProcess[$TOR_PROCESS_HANDLE] are set to 0 which help avoid conflict 378 | ; Related .......: _Tor_Start 379 | ; Example .......: No 380 | ; =============================================================================================================================== 381 | Func _Tor_Stop(ByRef $aTorProcess) 382 | If UBound($aTorProcess) <> 3 Then Return SetError($TOR_ERROR_GENERIC, 0, False) 383 | _Tor_Controller_SendRaw($aTorProcess, 'SIGNAL SHUTDOWN') 384 | If Not @error Then 385 | Local $sResponse = _Tor_Controller_WaitForMsg($aTorProcess) 386 | If Not @error Then 387 | _Tor_Controller_CheckReplyForError($sResponse) 388 | If Not @error Then Return 389 | EndIf 390 | Else 391 | ProcessClose($aTorProcess[$TOR_PROCESS_PID]) ; Force closure 392 | If @error Then Return SetError($TOR_ERROR_PROCESS, @error, False) 393 | EndIf 394 | $aTorProcess[$TOR_PROCESS_PID] = 0 395 | _Process_CloseHandle($aTorProcess[$TOR_PROCESS_HANDLE]) 396 | $aTorProcess[$TOR_PROCESS_HANDLE] = 0 397 | Return True 398 | EndFunc 399 | 400 | ; #FUNCTION# ==================================================================================================================== 401 | ; Name ..........: _Tor_SwitchCircuit 402 | ; Description ...: Switch Tor to clean circuits so new application requests don't share any circuits with old ones 403 | ; Syntax ........: _Tor_SwitchCircuit(Byref $aTorProcess) 404 | ; Parameters ....: $aTorProcess - [in/out] $aTorProcess from _Tor_Start. 405 | ; Return values .: Success: True 406 | ; Failure: False, @error set to: 407 | ; $TOR_ERROR_GENERIC - If controller sent a reply indicating an error and @extended is 408 | ; set to _Tor_Controller_CheckReplyForError's @extended 409 | ; $TOR_ERROR_NETWORK - If a network error occurs, @extended is set to TCPSend/TCPRecv's @error 410 | ; Author ........: Damon Harris (TheDcoder) 411 | ; Remarks .......: Tor may rate-limit this action so use it responsibly 412 | ; Example .......: No 413 | ; =============================================================================================================================== 414 | Func _Tor_SwitchCircuit(ByRef $aTorProcess) 415 | _Tor_Controller_SendRaw($aTorProcess, 'SIGNAL NEWNYM') 416 | If @error Then Return SetError($TOR_ERROR_NETWORK, @extended, False) 417 | Local $sReply = _Tor_Controller_WaitForMsg($aTorProcess) 418 | If @error Then Return SetError($TOR_ERROR_NETWORK, @extended, False) 419 | _Tor_Controller_CheckReplyForError($sReply) 420 | If @error Then Return SetError($TOR_ERROR_GENERIC, @extended, False) 421 | Return True 422 | EndFunc 423 | 424 | ; #FUNCTION# ==================================================================================================================== 425 | ; Name ..........: _Tor_VerifyConfig 426 | ; Description ...: Check if the configuration is valid. 427 | ; Syntax ........: _Tor_VerifyConfig($sConfig) 428 | ; Parameters ....: $sConfig - a Path to the config/torrc file. 429 | ; Return values .: Success: True 430 | ; Failure: False and @error set to $TOR_ERROR_CONFIG 431 | ; Author ........: Damon Harris (TheDcoder) 432 | ; Remarks .......: This function just perfroms a bare-minimum check 433 | ; Example .......: No 434 | ; =============================================================================================================================== 435 | Func _Tor_VerifyConfig($sConfig) 436 | Local $sOutput = _Process_RunCommand($PROCESS_RUNWAIT, '"' & $g__sTorPath & '" --verify-config --allow-missing-torrc --defaults-torrc "" -f "' & $sConfig & '"', @ScriptDir) 437 | If @error Then Return SetError($TOR_ERROR_PROCESS, @error, False) 438 | Local $aOutput = StringSplit(StringStripWS($sOutput, $STR_STRIPTRAILING), @CRLF, $STR_ENTIRESPLIT) 439 | If $aOutput[$aOutput[0]] = "Configuration was valid" Then Return True 440 | Return SetError($TOR_ERROR_CONFIG, 0, False) 441 | EndFunc 442 | 443 | Func __Tor_OnExitTCPShutdown() 444 | TCPShutdown() 445 | EndFunc 446 | -------------------------------------------------------------------------------- /ProxAllium.au3: -------------------------------------------------------------------------------- 1 | #NoTrayIcon 2 | 3 | #Region AutoIt3Wrapper Directives 4 | #AutoIt3Wrapper_Icon=icon.ico 5 | #AutoIt3Wrapper_Outfile=Builds\ProxAllium.exe 6 | #AutoIt3Wrapper_Res_Description=ProxAllium - Tor Proxy Bundle 7 | #AutoIt3Wrapper_Res_Fileversion=0.4.3.0 8 | #AutoIt3Wrapper_Res_ProductVersion=0.4.3.0 9 | #AutoIt3Wrapper_Res_LegalCopyright=Dcoding The Web 10 | #AutoIt3Wrapper_Run_Au3Stripper=y 11 | #Au3Stripper_Parameters=/sf /sv /mo /rm 12 | #EndRegion AutoIt3Wrapper Directives 13 | 14 | #Region Includes 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "Tor.au3" 29 | #include "IniReadWrite.au3" 30 | #EndRegion Includes 31 | 32 | #Region Multi-Instance Handler 33 | Handle_MultipleInstance() 34 | #EndRegion Multi-Instance Handler 35 | 36 | #Region Variable Initialization 37 | Global $g_aTorProcess[2] 38 | Global $g_aTorVersion[0] 39 | 40 | #Region Read Configuration 41 | Global Const $CONFIG_INI = @ScriptDir & '\config.ini' 42 | 43 | Global $g_sTorPath = IniReadWrite($CONFIG_INI, "tor", "path", 'Tor\tor.exe') 44 | Global $g_sObfs4Path = IniReadWrite($CONFIG_INI, "tor", "obfs4_path", 'Tor\PluggableTransports\obfs4\obfs4proxy.exe') 45 | Global $g_sSnowflakePath = IniReadWrite($CONFIG_INI, "tor", "snowflake_path", 'Tor\PluggableTransports\snowflake-client.exe') 46 | Global $g_sSnowflakeArgs = IniReadWrite($CONFIG_INI, "tor", "snowflake_args", '-url=https://snowflake-broker.torproject.net.global.prod.fastly.net/ -front=cdn.sstatic.net -ice=stun:stun.voip.blackberry.com:3478,stun:stun.altar.com.pl:3478,stun:stun.antisip.com:3478,stun:stun.bluesip.net:3478,stun:stun.dus.net:3478,stun:stun.epygi.com:3478,stun:stun.sonetel.com:3478,stun:stun.sonetel.net:3478,stun:stun.stunprotocol.org:3478,stun:stun.uls.co.za:3478,stun:stun.voipgate.com:3478,stun:stun.voys.nl:3478') 47 | Global $g_sTorConfigFile = IniReadWrite($CONFIG_INI, "tor", "config_file", 'config.torrc') 48 | Global $g_sTorDataDirPath = IniReadWrite($CONFIG_INI, "tor", "data_dir", 'Tor Data') 49 | Global $g_sTorGeoIPv4File = IniReadWrite($CONFIG_INI, "tor", "geoip4_file", 'Tor\geoip') 50 | Global $g_sTorGeoIPv6File = IniReadWrite($CONFIG_INI, "tor", "geoip6_file", 'Tor\geoip6') 51 | Global $g_iOutputPollInterval = Int(IniReadWrite($CONFIG_INI, "proxallium", "output_poll_interval", "100")) 52 | 53 | Global $g_sTorConfig_Port = IniReadWrite($CONFIG_INI, "tor_config", "port", "9050") 54 | Global $g_sTorConfig_TunnelPort = IniRead($CONFIG_INI, "tor_config", "tunnel_port", "") 55 | Global $g_sTorConfig_ControlPort = IniReadWrite($CONFIG_INI, "tor_config", "control_port", "9051") 56 | Global $g_sTorConfig_ControlPass = IniReadWrite($CONFIG_INI, "tor_config", "control_pass", String(Random(100000, 999999, 1))) 57 | Global $g_bTorConfig_OnlyLocalhost = (IniReadWrite($CONFIG_INI, "tor_config", "localhost_only", "true") = "true") 58 | Global $g_sTorConfig_ExitNodeCC = IniRead($CONFIG_INI, "tor_config", "exit_node_country_code", "") 59 | 60 | Global $g_sTorConfig_ProxyType = IniRead($CONFIG_INI, "proxy", "type", "") 61 | Global $g_sTorConfig_ProxyHost = IniRead($CONFIG_INI, "proxy", "host", "") 62 | Global $g_sTorConfig_ProxyPort = IniRead($CONFIG_INI, "proxy", "port", "") 63 | Global $g_sTorConfig_ProxyUser = IniRead($CONFIG_INI, "proxy", "user", "") 64 | Global $g_sTorConfig_ProxyPass = IniRead($CONFIG_INI, "proxy", "pass", "") 65 | 66 | Global $g_bTorConfig_BridgesEnabled = (IniRead($CONFIG_INI, "bridges", "enabled", "false") = "true") 67 | Global $g_sTorConfig_BridgesPath = IniRead($CONFIG_INI, "bridges", "path", $g_sTorDataDirPath & '\bridges.txt') 68 | 69 | Global $g_bTorConfig_AutoStart = (IniRead($CONFIG_INI, "startup", "auto_start", "false") = "true") 70 | Global $g_sTorConfig_AutoStartShortcut = IniRead($CONFIG_INI, "startup", "auto_start_shortcut", "") 71 | Global $g_bTorConfig_StartMinimized = (IniRead($CONFIG_INI, "startup", "start_minimized", "false") = "true") 72 | #EndRegion Read Configuration 73 | 74 | #EndRegion Variable Initialization 75 | 76 | #Region Tray Creation 77 | Opt("TrayMenuMode", 1 + 2) ; No default menu and automatic checkmarks 78 | Opt("TrayOnEventMode", 1) ; OnEvent mode 79 | Opt("TrayAutoPause", 0) ; No Auto-Pause 80 | 81 | Tray_Initialize() 82 | 83 | Func Tray_Initialize() 84 | TraySetClick(16) ; Will display the menu when releasing the secondary mouse button 85 | TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, "GUI_ToggleMainWindow") 86 | TrayItemSetState(TrayCreateItem("ProxAllium"), $TRAY_DISABLE) 87 | TrayCreateItem("") 88 | Global $g_idTrayMainWinToggle = TrayCreateItem('...') 89 | TrayItemSetOnEvent($g_idTrayMainWinToggle, "GUI_ToggleMainWindow") 90 | Global $g_idTrayTorOutputToggle = TrayCreateItem("Show Tor Output") 91 | TrayItemSetOnEvent($g_idTrayTorOutputToggle, "GUI_ToggleTorOutputWindow") 92 | TrayCreateItem("") 93 | Local $idOptions = TrayCreateMenu("Options") 94 | Global $g_idTrayOptionBridges = TrayCreateItem("Bridges", $idOptions) 95 | TrayItemSetOnEvent($g_idTrayOptionBridges, "Tray_HandleBridgeOption") 96 | TrayCreateItem("", $idOptions) 97 | Global $g_idTrayOptionRegenConfig = TrayCreateItem("Regenerate Tor configuration", $idOptions) 98 | TrayItemSetOnEvent($g_idTrayOptionRegenConfig, "GUI_RegenerateTorrc") 99 | Global $g_idTrayOptionRefreshCircuit = TrayCreateItem("New Tor Circuit for future connections", $idOptions) 100 | TrayItemSetOnEvent($g_idTrayOptionRefreshCircuit, "GUI_RefreshCircuit") 101 | TrayCreateItem("") 102 | Global $g_idTrayToggleTor = TrayCreateItem("Stop Tor") 103 | TrayItemSetOnEvent($g_idTrayToggleTor, "Tor_Toggle") 104 | TrayCreateItem("") 105 | TrayItemSetOnEvent(TrayCreateItem("Exit"), "GUI_MainWindowExit") 106 | TraySetState($TRAY_ICONSTATE_SHOW) 107 | TraySetToolTip("ProxAllium") 108 | EndFunc 109 | 110 | Func Tray_HandleBridgeOption() 111 | Call("GUI_BridgeHandler", $g_idTrayOptionBridges) 112 | EndFunc 113 | #EndRegion Tray Creation 114 | 115 | #Region GUI Creation 116 | Opt("GUIOnEventMode", 1) 117 | GUI_CreateMainWindow() 118 | GUI_LogOut("Starting ProxAllium... Please wait :)") 119 | GUI_CreateTorOutputWindow() 120 | GUI_CreateBridges() 121 | 122 | Func GUI_CreateMainWindow() 123 | Global $g_hMainGUI = GUICreate("ProxAllium", 580, 370) 124 | GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_ToggleMainWindow", $g_hMainGUI) 125 | GUICtrlCreateMenu("ProxAllium") 126 | GUICtrlSetState(-1, $GUI_DISABLE) 127 | Local $idMenuView = GUICtrlCreateMenu("View") 128 | GUICtrlCreateMenuItem("Hide Main Window", $idMenuView) 129 | GUICtrlSetOnEvent(-1, "GUI_ToggleMainWindow") 130 | Global $g_idMainGUI_MenuToggleTorOutput = GUICtrlCreateMenuItem("Show Tor Output", $idMenuView) 131 | GUICtrlSetOnEvent(-1, "GUI_ToggleTorOutputWindow") 132 | Local $idMenuOptions = GUICtrlCreateMenu("Options") 133 | Global $g_idMainGUI_MenuBridges = GUICtrlCreateMenuItem("Bridges", $idMenuOptions) 134 | GUICtrlSetOnEvent(-1, "GUI_BridgeHandler") 135 | GUICtrlCreateMenuItem("", $idMenuOptions) 136 | Global $g_idMainGUI_MenuRegenConfig = GUICtrlCreateMenuItem("Regenerate Tor configuration", $idMenuOptions) 137 | GUICtrlSetOnEvent(-1, "GUI_RegenerateTorrc") 138 | Global $g_idMainGUI_MenuRefreshCircuit = GUICtrlCreateMenuItem("New Tor Circuit for future connections", $idMenuOptions) 139 | GUICtrlSetOnEvent(-1, "GUI_RefreshCircuit") 140 | GUICtrlCreateMenuItem("", $idMenuOptions) 141 | Local $idMenuStartup = GUICtrlCreateMenu("Startup", $idMenuOptions) 142 | Global $g_idMainGUI_MenuAutoStart = GUICtrlCreateMenuItem("Automatically start with Windows", $idMenuStartup) 143 | GUICtrlSetOnEvent(-1, "GUI_AutoStart") 144 | If $g_bTorConfig_AutoStart Then GUICtrlSetState(-1, $GUI_CHECKED) 145 | Global $g_idMainGUI_MenuStartMinimized = GUICtrlCreateMenuItem("Start Minimized", $idMenuStartup) 146 | If $g_bTorConfig_StartMinimized Then GUICtrlSetState(-1, $GUI_CHECKED) 147 | GUICtrlSetOnEvent(-1, "GUI_StartMinimized") 148 | GUICtrlCreateMenuItem("", $idMenuOptions) 149 | Global $g_idMainGUI_MenuRunSetup = GUICtrlCreateMenuItem("Run Tor setup again", $idMenuOptions) 150 | GUICtrlSetOnEvent(-1, "Core_SetupTor") 151 | GUICtrlCreateGroup("Proxy Details", 5, 5, 570, 117) 152 | GUICtrlCreateLabel("Hostname:", 10, 27, 60, 15) 153 | Global $g_idMainGUI_Hostname = GUICtrlCreateInput("localhost", 73, 22, 497, 20, $ES_READONLY, $WS_EX_CLIENTEDGE) 154 | GUICtrlSetBkColor(-1, $COLOR_WHITE) 155 | GUICtrlCreateLabel("IP Address:", 10, 52, 60, 15) 156 | Global $g_idMainGUI_IPAddress = GUICtrlCreateInput("127.0.0.1", 73, 47, 497, 20, $ES_READONLY, $WS_EX_CLIENTEDGE) 157 | GUICtrlSetBkColor(-1, $COLOR_WHITE) 158 | GUICtrlCreateLabel("Port:", 10, 77, 60, 15) 159 | Global $g_idMainGUI_Port = GUICtrlCreateInput('...', 73, 72, 497, 20, $ES_READONLY, $WS_EX_CLIENTEDGE) 160 | GUICtrlSetBkColor(-1, $COLOR_WHITE) 161 | GUICtrlCreateLabel("Proxy Type:", 10, 102, 60, 15) 162 | GUICtrlCreateInput("SOCKS5", 73, 97, 497, 20, $ES_READONLY, $WS_EX_CLIENTEDGE) 163 | GUICtrlSetBkColor(-1, $COLOR_WHITE) 164 | GUICtrlCreateGroup("Tor Details", 5, 125, 570, 64) 165 | GUICtrlCreateLabel("Tor PID:", 10, 144, 60, 15) 166 | Global $g_idMainGUI_TorPID = GUICtrlCreateInput("Not running", 73, 139, 497, 20, $ES_READONLY, $WS_EX_CLIENTEDGE) 167 | GUICtrlSetBkColor(-1, $COLOR_WHITE) 168 | GUICtrlCreateLabel("Tor Version:", 10, 169, 60, 15) 169 | Global $g_idMainGUI_TorVersion = GUICtrlCreateInput('(Yet to be determined)', 73, 164, 497, 20, $ES_READONLY, $WS_EX_CLIENTEDGE) 170 | GUICtrlSetBkColor(-1, $COLOR_WHITE) 171 | GUICtrlCreateGroup("Control Panel", 5, 192, 570, 42) 172 | GUICtrlCreateLabel("Status:", 10, 213, 33, 15) 173 | Global $g_idMainGUI_Status = GUICtrlCreateInput('Initializing', 48, 208, 438, 20, BitOr($ES_CENTER, $ES_READONLY), $WS_EX_CLIENTEDGE) 174 | GUICtrlSetBkColor(-1, $COLOR_WHITE) 175 | Global $g_idMainGUI_ToggleButton = GUICtrlCreateButton('...', 489, 207, 82, 22) 176 | GUICtrlSetState(-1, $GUI_DISABLE) 177 | GUICtrlSetOnEvent(-1, "Tor_Toggle") 178 | Global $g_idMainGUI_Log = GUICtrlCreateEdit("", 5, 238, 570, 107, BitOR($ES_READONLY, $ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) 179 | Global $g_hMainGUI_Log = GUICtrlGetHandle($g_idMainGUI_Log) 180 | GUICtrlSetFont($g_idMainGUI_Log, 9, Default, Default, "Consolas") 181 | GUICtrlSetBkColor($g_idMainGUI_Log, $COLOR_WHITE) 182 | GUI_Reset() 183 | GUI_ToggleMainWindow() 184 | EndFunc 185 | 186 | Func GUI_LogOut($sText, $bEOL = True) 187 | If $bEOL Then $sText &= @CRLF 188 | _GUICtrlEdit_AppendText($g_hMainGUI_Log, $sText) 189 | ConsoleWrite($sText) 190 | EndFunc 191 | 192 | Func GUI_SetStatus($sStatus = '...') 193 | GUICtrlSetData($g_idMainGUI_Status, $sStatus) 194 | EndFunc 195 | 196 | Func GUI_CreateTorOutputWindow() 197 | Local Const $eiGuiWidth = 580, $eiGuiHeight = 280 198 | Global $g_hTorGUI = GUICreate("Tor Output", $eiGuiWidth, $eiGuiHeight, Default, Default, $WS_OVERLAPPEDWINDOW) 199 | GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_ToggleTorOutputWindow") 200 | Global $g_idTorOutput = GUICtrlCreateEdit("", 0, 0, $eiGuiWidth, $eiGuiHeight, BitOR($ES_READONLY, $ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL)) 201 | Global $g_hTorOutput = GUICtrlGetHandle($g_idTorOutput) ; Get the handle of the Edit control for future use in the Tor Output Handler 202 | GUICtrlSetFont($g_idTorOutput, 9, Default, Default, "Consolas") 203 | GUICtrlSetBkColor($g_idTorOutput, $COLOR_BLACK) 204 | Local $aGrayCmdColor[3] = [197, 197, 197] ; CMD Text Color's combination in RGB 205 | Local Const $iGrayCmdColor = _ColorSetRGB($aGrayCmdColor) ; Get the RGB code of CMD Text Color 206 | GUICtrlSetColor($g_idTorOutput, $iGrayCmdColor) 207 | EndFunc 208 | 209 | Func GUI_CreateBridges() 210 | Global $g_hBridgesGUI = GUICreate("Bridges", 515, 245, -1, -1, -1, -1, $g_hMainGUI) 211 | GUISetOnEvent($GUI_EVENT_CLOSE, GUI_BridgeHandler, $g_hBridgesGUI) 212 | GUICtrlCreateLabel("Bridges Status: ", 5, 13, 78, 17) 213 | Global $g_idBridgeStatus = GUICtrlCreateLabel("", 78, 13, 47, 17) 214 | Global $g_idBridgesToggle = GUICtrlCreateButton("", 128, 4, 59, 24) 215 | Global $g_idBridgesSave = GUICtrlCreateButton("Save", 411, 4, 100, 24) 216 | Global $g_idBridgesEdit = GUICtrlCreateEdit("", 5, 32, 505, 208) 217 | 218 | GUICtrlSetFont($g_idBridgeStatus, 8.5, $FW_BOLD) 219 | GUICtrlSetFont($g_idBridgesEdit, 9, Default, Default, "Consolas") 220 | 221 | GUICtrlSetOnEvent($g_idBridgesToggle, GUI_BridgeHandler) 222 | GUICtrlSetOnEvent($g_idBridgesSave, GUI_BridgeHandler) 223 | 224 | Local $sBridges = FileRead($g_sTorConfig_BridgesPath) 225 | If Not @error Then GUICtrlSetData($g_idBridgesEdit, $sBridges) 226 | GUICtrlSetTip($g_idBridgesEdit, "Paste your bridge lines here (one per line)", "Bridges", $TIP_INFOICON) 227 | 228 | GUI_BridgeHandler($g_idBridgesToggle) ; Initialize the GUI 229 | EndFunc 230 | #EndRegion GUI Functions 231 | 232 | #Region Main Script 233 | Tor_Initialize() 234 | If Not @error Then Tor_Start() 235 | 236 | Core_Idle() 237 | #EndRegion Main Script 238 | 239 | #Region Functions 240 | 241 | #Region GUI Handlers Functions 242 | Func GUI_MainWindowExit() 243 | Local $iMsgBoxFlags = $MB_YESNO + $MB_ICONQUESTION 244 | Local $sMsgBoxTitle = "Close ProxAllium" 245 | Local $sMsgBoxMsg = "Do you really want to close ProxAllium?" 246 | Local $iButtonID = MsgBox($iMsgBoxFlags, $sMsgBoxTitle, $sMsgBoxMsg) 247 | If $iButtonID = $IDNO Then Return 248 | If IsTorRunning() Then Tor_Stop() 249 | Exit 250 | EndFunc 251 | 252 | Func GUI_ToggleTorOutputWindow() 253 | Local Static $bHidden = True 254 | If $bHidden Then 255 | $bHidden = Not (GUISetState(@SW_SHOWNORMAL, $g_hTorGUI) = 1) 256 | If Not $bHidden Then 257 | TrayItemSetText($g_idTrayTorOutputToggle, "Hide Tor Output") 258 | GUICtrlSetData($g_idMainGUI_MenuToggleTorOutput, "Hide Tor Output") 259 | EndIf 260 | Return 261 | EndIf 262 | $bHidden = (GUISetState(@SW_HIDE, $g_hTorGUI) = 1) 263 | If $bHidden Then 264 | TrayItemSetText($g_idTrayTorOutputToggle, "Show Tor Output") 265 | GUICtrlSetData($g_idMainGUI_MenuToggleTorOutput, "Show Tor Output") 266 | EndIf 267 | EndFunc 268 | 269 | Func GUI_ToggleMainWindow() 270 | Local Static $bHidden = ($g_bTorConfig_StartMinimized ? False : True) 271 | If $bHidden Then 272 | $bHidden = Not (GUISetState(@SW_SHOWNORMAL, $g_hMainGUI) = 1) 273 | If Not $bHidden Then TrayItemSetText($g_idTrayMainWinToggle, "Hide Main Window") 274 | Else 275 | $bHidden = (GUISetState(@SW_HIDE, $g_hMainGUI) = 1) 276 | If $bHidden Then TrayItemSetText($g_idTrayMainWinToggle, "Show Main Window") 277 | EndIf 278 | EndFunc 279 | 280 | Func GUI_BridgeHandler($iCtrlID = Default) 281 | Local Static $bNotInitialized = True 282 | If $bNotInitialized Then 283 | $g_bTorConfig_BridgesEnabled = ($g_bTorConfig_BridgesEnabled ? False : True) 284 | $bNotInitialized = False 285 | EndIf 286 | Local Static $bModified 287 | Switch (IsDeclared("iCtrlID") = $DECLARED_LOCAL ? $iCtrlID : @GUI_CtrlId) 288 | Case $GUI_EVENT_CLOSE 289 | If $bModified Or (_GUICtrlEdit_GetModify($g_idBridgesEdit)) Then 290 | If MsgBox($MB_ICONQUESTION + $MB_YESNO + $MB_DEFBUTTON2, "Unsaved changes", "You have made some changes, are you sure that you want to exit without saving them to disk?") = $IDNO Then Return 291 | EndIf 292 | GUISetState(@SW_HIDE, $g_hBridgesGUI) 293 | Case $g_idMainGUI_MenuBridges, $g_idTrayOptionBridges 294 | _GUICtrlEdit_SetModify($g_idBridgesEdit, False) 295 | $bModified = False 296 | GUISetState(@SW_SHOW, $g_hBridgesGUI) 297 | Case $g_idBridgesToggle 298 | $bModified = True 299 | If $g_bTorConfig_BridgesEnabled Then 300 | $g_bTorConfig_BridgesEnabled = False 301 | GUICtrlSetData($g_idBridgeStatus, "Disabled") 302 | GUICtrlSetData($g_idBridgesToggle, "Enable") 303 | GUICtrlSetColor($g_idBridgeStatus, $COLOR_RED) 304 | Else 305 | $g_bTorConfig_BridgesEnabled = True 306 | GUICtrlSetData($g_idBridgeStatus, "Enabled") 307 | GUICtrlSetData($g_idBridgesToggle, "Disable") 308 | GUICtrlSetColor($g_idBridgeStatus, $COLOR_GREEN) 309 | EndIf 310 | Case $g_idBridgesSave 311 | Local $hFile = FileOpen($g_sTorConfig_BridgesPath, $FO_OVERWRITE + $FO_CREATEPATH) 312 | If $hFile = -1 Then 313 | MsgBox($MB_ICONERROR, "Failed to open", "Failed to open/create the bridges files for writing!") 314 | Return 315 | EndIf 316 | If FileWrite($hFile, GUICtrlRead($g_idBridgesEdit)) = 0 Then 317 | MsgBox($MB_ICONERROR, "Failed to write", "Failed to write to the bridges files!") 318 | Return 319 | EndIf 320 | $bModified = False 321 | _GUICtrlEdit_SetModify($g_idBridgesEdit, False) 322 | IniWrite($CONFIG_INI, "bridges", "enabled", StringLower($g_bTorConfig_BridgesEnabled)) 323 | MsgBox($MB_ICONINFORMATION, "Saved", "Settings for bridges have been save successfully!") 324 | EndSwitch 325 | EndFunc 326 | 327 | Func GUI_RegenerateTorrc() 328 | GUI_LogOut("Regenerating Tor configuration... ", False) 329 | Core_GenTorrc() 330 | If @error Then 331 | GUI_LogOut("Failed! (Error Code: " & @error & ')') 332 | Else 333 | GUI_LogOut("Done!") 334 | Local $sMessage = "ProxAllium has generated a new configuration, do you want to restart Tor make the changes take effect?" 335 | If IsTorRunning() And MsgBox($MB_ICONQUESTION + $MB_YESNO, "Do you want to restart Tor?", $sMessage) = $IDYES Then 336 | Tor_Stop() 337 | Tor_Start() 338 | EndIf 339 | EndIf 340 | EndFunc 341 | 342 | Func GUI_RefreshCircuit() 343 | GUI_LogOut("Switching to clean circuits... ", False) 344 | _Tor_SwitchCircuit($g_aTorProcess) 345 | If @error Then 346 | GUI_LogOut('Failed to create clean circuits! ' & StringFormat('(Error Code: %i and Extended Code: %i)', @error, @extended)) 347 | Else 348 | GUI_LogOut("Done!") 349 | EndIf 350 | EndFunc 351 | 352 | Func GUI_AutoStart() 353 | Local $iReturn 354 | If $g_bTorConfig_AutoStart Then 355 | $iReturn = FileDelete($g_sTorConfig_AutoStartShortcut) 356 | If $iReturn = 0 Then 357 | MsgBox($MB_ICONERROR, "Failed to remove startup", "Failed to remove shortcut in the Startup folder!") 358 | Else 359 | $g_bTorConfig_AutoStart = False 360 | IniDelete($CONFIG_INI, "startup", "auto_start") 361 | IniDelete($CONFIG_INI, "startup", "auto_start_shortcut") 362 | GUICtrlSetState($g_idMainGUI_MenuAutoStart, $GUI_UNCHECKED) 363 | MsgBox($MB_ICONINFORMATION, "Successfully removed from startup", "ProxAllium will no longer start with Windows") 364 | EndIf 365 | Else 366 | Local $sStartupFolder = _WinAPI_ShellGetKnownFolderPath($FOLDERID_Startup) 367 | $sShortcutPath = $sStartupFolder & '\ProxAllium.lnk' 368 | If FileExists($sShortcutPath) Then $sShortcutPath = _TempFile($sStartupFolder, "ProxAllium_", '.lnk') 369 | $iReturn = FileCreateShortcut(@ScriptFullPath, $sShortcutPath, @WorkingDir) 370 | If $iReturn = 0 Then 371 | MsgBox($MB_ICONERROR, "Cannot add to startup", "Failed to create a shortcut in the Startup folder!") 372 | Else 373 | $g_bTorConfig_AutoStart = True 374 | IniWrite($CONFIG_INI, "startup", "auto_start", "true") 375 | $g_sTorConfig_AutoStartShortcut = $sShortcutPath 376 | IniWrite($CONFIG_INI, "startup", "auto_start_shortcut", $sShortcutPath) 377 | GUICtrlSetState($g_idMainGUI_MenuAutoStart, $GUI_CHECKED) 378 | MsgBox($MB_ICONINFORMATION, "Successfully added to startup", "ProxAllium will start with Windows from now!") 379 | EndIf 380 | EndIf 381 | EndFunc 382 | 383 | Func GUI_StartMinimized() 384 | If $g_bTorConfig_StartMinimized Then 385 | $g_bTorConfig_StartMinimized = False 386 | IniDelete($CONFIG_INI, "startup", "start_minimized") 387 | GUICtrlSetState($g_idMainGUI_MenuStartMinimized, $GUI_UNCHECKED) 388 | Else 389 | $g_bTorConfig_StartMinimized = True 390 | IniWrite($CONFIG_INI, "startup", "start_minimized", "true") 391 | GUICtrlSetState($g_idMainGUI_MenuStartMinimized, $GUI_CHECKED) 392 | EndIf 393 | EndFunc 394 | 395 | Func GUI_Reset() 396 | GUICtrlSetData($g_idMainGUI_Port, $g_sTorConfig_Port & ' (As defined in the settings)') 397 | GUICtrlSetData($g_idMainGUI_TorPID, "Not running") 398 | TrayItemSetText($g_idTrayToggleTor, "Start Tor") 399 | GUICtrlSetData($g_idMainGUI_ToggleButton, "Start") 400 | EndFunc 401 | #EndRegion GUI Handlers 402 | 403 | #Region Event Handler Functions 404 | Func Handle_MultipleInstance() 405 | If _Singleton(StringReplace(@ScriptFullPath, '\', '/'), 1) = 0 Then 406 | Local $iMsgBoxParams = $MB_ICONWARNING + $MB_YESNO + $MB_DEFBUTTON2 407 | Local $sMsgBoxMsg = "ProxAllium seems to be already running, do you still want to create a new instance?" 408 | Local $iUserChoice = MsgBox($iMsgBoxParams, "ProxAllium is already running!", $sMsgBoxMsg) 409 | If $iUserChoice = $IDYES Then Return 410 | Exit 411 | EndIf 412 | EndFunc 413 | 414 | Func Handle_TorOutput() 415 | Local $aCallbackFuncs = [Handle_OpenSockets, Handle_Bootstrap, Handle_WarningAndError] 416 | Local $sPartialTorOutput = "" 417 | Local $aPartialTorOutput[0] 418 | Local $bRemoveCallback, $sRemovalList 419 | While IsTorRunning() ; Loop until Tor is dead 420 | Sleep($g_iOutputPollInterval) ; Don't kill the CPU 421 | $sPartialTorOutput = StdoutRead($g_aTorProcess[$TOR_PROCESS_PID]) 422 | If $sPartialTorOutput = "" Then ContinueLoop 423 | _GUICtrlEdit_AppendText($g_hTorOutput, $sPartialTorOutput) 424 | $aPartialTorOutput = StringSplit(StringStripWS($sPartialTorOutput, $STR_STRIPTRAILING), @CRLF, $STR_ENTIRESPLIT) 425 | For $iLine = 1 To $aPartialTorOutput[0] 426 | For $iFunc = 0 To UBound($aCallbackFuncs) - 1 427 | $bRemoveCallback = $aCallbackFuncs[$iFunc](StringSplit($aPartialTorOutput[$iLine], ' ')) 428 | If $bRemoveCallback Then $sRemovalList &= $iFunc & ';' 429 | Next 430 | If Not $sRemovalList = "" Then 431 | _ArrayDelete($aCallbackFuncs, StringTrimRight($sRemovalList, 1)) 432 | $sRemovalList = "" 433 | EndIf 434 | Next 435 | WEnd 436 | Local $iExitCode = _Process_GetExitCode($g_aTorProcess[$TOR_PROCESS_HANDLE]) 437 | GUI_SetStatus("Stopped") 438 | Local $bUnexpected = Not IsMgcNumPresent($GUI_DISABLE, GUICtrlGetState($g_idMainGUI_ToggleButton)) 439 | If $bUnexpected Then 440 | _Tor_Stop($g_aTorProcess) 441 | GUI_LogOut("Tor has exited unexpectedly with exit code: " & $iExitCode) 442 | TrayTip("Tor exited unexpectedly!", "Tor has exited with exit code: " & $iExitCode, 10, $TIP_ICONEXCLAMATION) 443 | Else 444 | GUICtrlSetState($g_idMainGUI_ToggleButton, $GUI_ENABLE) 445 | GUI_LogOut("Tor exited with exit code: " & $iExitCode) 446 | TrayTip("Tor has exited", "Tor has exited with exit code: " & $iExitCode, 10, $TIP_ICONASTERISK + $TIP_NOSOUND) 447 | EndIf 448 | GUI_Reset() 449 | EndFunc 450 | 451 | Func Handle_WarningAndError(ByRef $aTorOutput) 452 | If $aTorOutput[0] < 4 Then Return 453 | If ($aTorOutput[4] = '[warn]') Or ($aTorOutput[3] = '[err]') Then 454 | If $aTorOutput[5] = "Path" Then Return 455 | GUI_LogOut(_ArrayToString($aTorOutput, ' ', 5)) 456 | EndIf 457 | EndFunc 458 | 459 | Func Handle_OpenSockets(ByRef $aTorOutput) 460 | If ($aTorOutput[0] < 9) Or ($aTorOutput[5] <> "Opening") Then Return 461 | Local Enum $IP, $PORT 462 | Local $aAddress = StringSplit($aTorOutput[($aTorOutput[6] = "HTTP" ? 10 : 9)], ':', $STR_NOCOUNT) 463 | Local Static $bSocksInit = False 464 | Local Static $bControlInit = False 465 | Switch $aTorOutput[6] 466 | Case "Socks" 467 | GUICtrlSetData($g_idMainGUI_Port, $aAddress[$PORT]) 468 | $bSocksInit = True 469 | Case "HTTP" 470 | _GUICtrlEdit_AppendText($g_idMainGUI_Port, ' (HTTP Tunnel Port: ' & $aAddress[$PORT] & ')') 471 | Case "Control" 472 | Core_InitConnectionToController($g_sTorConfig_ControlPort) 473 | $bControlInit = True 474 | EndSwitch 475 | If $bSocksInit And $bControlInit Then 476 | $bSocksInit = False 477 | $bControlInit = False 478 | Return True 479 | EndIf 480 | EndFunc 481 | 482 | Func Handle_Bootstrap(ByRef $aTorOutput) 483 | If Not ($aTorOutput[0] >= 7 And $aTorOutput[5] = "Bootstrapped") Then Return 484 | Local $iPercentage = Int($aTorOutput[6]) 485 | If $iPercentage = 0 Then GUI_LogOut("Trying to build a circuit, please wait...") 486 | Local $sText = _ArrayToString($aTorOutput, ' ', 5) 487 | GUI_SetStatus($sText) 488 | GUI_LogOut($sText) 489 | If $iPercentage = 100 Then 490 | GUI_SetStatus("Running") 491 | GUI_LogOut("Successfully built a circuit, Tor is now ready for use!") 492 | TrayTip("Tor is ready", "Tor has successfully built a circuit, you can now start using the proxy!", 10, $TIP_ICONASTERISK) 493 | Return True 494 | EndIf 495 | EndFunc 496 | #EndRegion Misc. Functions 497 | 498 | #Region Core Functions 499 | Func Core_WaitForExit($sLogText = "") 500 | If Not $sLogText = "" Then GUI_LogOut($sLogText) 501 | GUI_LogOut("ProxAllium now ready to exit...") 502 | GUI_LogOut("Close the window by clicking X to exit ProxAllium!") 503 | Core_Idle() 504 | EndFunc 505 | 506 | Func Core_Idle() 507 | Do 508 | If IsTorRunning() Then Handle_TorOutput() 509 | Sleep($g_iOutputPollInterval) 510 | Until False 511 | EndFunc 512 | 513 | Func Core_GenTorrc() 514 | Local $hTorrc = FileOpen($g_sTorConfigFile, $FO_APPEND + $FO_CREATEPATH) 515 | If @error Then Return SetError(1, 0, False) 516 | FileSetPos($hTorrc, 0, $FILE_BEGIN) 517 | Local $aTorrc = FileReadToArray($hTorrc) 518 | Local $sCustomConfig 519 | If Not @error Then 520 | For $iLine = 0 To @extended - 1 521 | If StringLeft($aTorrc[$iLine], 2) = '#~' Then 522 | $sCustomConfig = _ArrayToString($aTorrc, @CRLF, $iLine + 1) 523 | ExitLoop 524 | EndIf 525 | Next 526 | EndIf 527 | FileSetPos($hTorrc, 0, $FILE_BEGIN) 528 | FileWriteLine($hTorrc, '## Configuration file automatically generated by ProxAllium') 529 | FileWriteLine($hTorrc, '## This file was generated on ' & _Now()) 530 | FileWriteLine($hTorrc, "") 531 | FileWriteLine($hTorrc, '## Open SOCKS proxy on the following port') 532 | FileWriteLine($hTorrc, 'SOCKSPort ' & $g_sTorConfig_Port) 533 | FileWriteLine($hTorrc, "") 534 | If Not $g_sTorConfig_TunnelPort = "" Then 535 | FileWriteLine($hTorrc, '## HTTP Tunnel Proxy') 536 | FileWriteLine($hTorrc, "HTTPTunnelPort " & $g_sTorConfig_TunnelPort) 537 | FileWriteLine($hTorrc, "") 538 | EndIf 539 | FileWriteLine($hTorrc, '## Open the Tor controller interface on the following port') 540 | FileWriteLine($hTorrc, 'ControlPort ' & $g_sTorConfig_ControlPort) 541 | FileWriteLine($hTorrc, 'HashedControlPassword ' & _Tor_GenHash($g_sTorConfig_ControlPass)[0]) 542 | FileWriteLine($hTorrc, "") 543 | If $g_bTorConfig_OnlyLocalhost Then 544 | FileWriteLine($hTorrc, '## Only accept connections from localhost') 545 | FileWriteLine($hTorrc, 'SOCKSPolicy accept 127.0.0.1') 546 | FileWriteLine($hTorrc, 'SOCKSPolicy accept6 [::1]') 547 | FileWriteLine($hTorrc, 'SOCKSPolicy reject *') 548 | FileWriteLine($hTorrc, "") 549 | EndIf 550 | FileWriteLine($hTorrc, '## GeoIP Files') 551 | FileWriteLine($hTorrc, 'GeoIPFile ' & $g_sTorGeoIPv4File) 552 | FileWriteLine($hTorrc, 'GeoIPv6File ' & $g_sTorGeoIPv6File) 553 | FileWriteLine($hTorrc, "") 554 | FileWriteLine($hTorrc, '## Data Directory') 555 | FileWriteLine($hTorrc, 'DataDirectory ' & $g_sTorDataDirPath) 556 | FileWriteLine($hTorrc, "") 557 | If Not $g_sTorConfig_ProxyType = "" Then 558 | FileWriteLine($hTorrc, "## Proxy Settings for Tor (not Tor's proxy settings)") 559 | Local $sProxySettings 560 | Switch $g_sTorConfig_ProxyType 561 | Case "http" 562 | $sProxySettings &= "HTTPProxy " & $g_sTorConfig_ProxyHost 563 | $sProxySettings &= ($g_sTorConfig_ProxyPort = "") ? "" : (':' & $g_sTorConfig_ProxyPort) 564 | $sProxySettings &= @CRLF 565 | If Not $g_sTorConfig_ProxyUser = "" Then $sProxySettings &= "HTTPProxyAuthenticator " & $g_sTorConfig_ProxyUser & ':' & $g_sTorConfig_ProxyPass & @CRLF 566 | 567 | Case "https" 568 | $sProxySettings &= "HTTPSProxy " & $g_sTorConfig_ProxyHost 569 | $sProxySettings &= ($g_sTorConfig_ProxyPort = "") ? "" : (':' & $g_sTorConfig_ProxyPort) 570 | $sProxySettings &= @CRLF 571 | If Not $g_sTorConfig_ProxyUser = "" Then $sProxySettings &= "HTTPSProxyAuthenticator " & $g_sTorConfig_ProxyUser & ':' & $g_sTorConfig_ProxyPass & @CRLF 572 | 573 | Case "socks4" 574 | $sProxySettings &= "Socks4Proxy " & $g_sTorConfig_ProxyHost 575 | $sProxySettings &= ($g_sTorConfig_ProxyPort = "") ? "" : (':' & $g_sTorConfig_ProxyPort) 576 | $sProxySettings &= @CRLF 577 | 578 | Case "socks5" 579 | $sProxySettings &= "Socks5Proxy " & $g_sTorConfig_ProxyHost 580 | $sProxySettings &= ($g_sTorConfig_ProxyPort = "") ? "" : (':' & $g_sTorConfig_ProxyPort) 581 | $sProxySettings &= @CRLF 582 | If Not $g_sTorConfig_ProxyUser = "" Then $sProxySettings &= "Socks5ProxyUsername " & $g_sTorConfig_ProxyUser & @CRLF 583 | If Not $g_sTorConfig_ProxyPass = "" Then $sProxySettings &= "Socks5ProxyPassword " & $g_sTorConfig_ProxyPass & @CRLF 584 | 585 | Case Else 586 | $sProxySettings &= '## Unknown proxy type detected!? Cannot generate config :(' 587 | EndSwitch 588 | FileWriteLine($hTorrc, $sProxySettings) 589 | FileWriteLine($hTorrc, "") 590 | EndIf 591 | If Not $g_sTorConfig_ExitNodeCC = "" Then 592 | FileWriteLine($hTorrc, '## Country of the Exit Node') 593 | FileWriteLine($hTorrc, 'ExitNodes {' & $g_sTorConfig_ExitNodeCC & '}') 594 | FileWriteLine($hTorrc, "StrictNodes 1") 595 | FileWriteLine($hTorrc, "") 596 | EndIf 597 | If $g_bTorConfig_BridgesEnabled Then 598 | FileWriteLine($hTorrc, '## Bridges') 599 | FileWriteLine($hTorrc, 'UseBridges 1') 600 | If FileExists($g_sObfs4Path) Then 601 | FileWriteLine($hTorrc, 'ClientTransportPlugin obfs2,obfs3,obfs4,scramblesuit exec ' & $g_sObfs4Path) 602 | EndIf 603 | If FileExists($g_sSnowflakePath) Then 604 | ; https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake/-/tree/main/client 605 | FileWriteLine($hTorrc, 'ClientTransportPlugin snowflake exec ' & $g_sSnowflakePath & ' ' & $g_sSnowflakeArgs) 606 | EndIf 607 | Local $aBridges = StringSplit(StringStripCR(GUICtrlRead($g_idBridgesEdit)), @LF) 608 | For $iBridge = 1 To $aBridges[0] 609 | If StringIsSpace($aBridges[$iBridge]) Then ContinueLoop ; Skip blank lines 610 | If StringLeft($aBridges[$iBridge], 1) = '#' Then ContinueLoop ; Skip comments 611 | FileWriteLine($hTorrc, 'Bridge ' & $aBridges[$iBridge]) 612 | Next 613 | FileWriteLine($hTorrc, "") 614 | EndIf 615 | FileWriteLine($hTorrc, '###########################################################') 616 | FileWriteLine($hTorrc, '###### STORE YOUR CUSTOM CONFIGURATION ENTRIES BELOW ######') 617 | FileWriteLine($hTorrc, '##### THEY WILL BE PRESERVED ACROSS CHANGES IN CONFIG #####') 618 | FileWriteLine($hTorrc, '###########################################################') 619 | FileWriteLine($hTorrc, '#~ I (this line) am used to identify the start of custom entries, so please do not touch me :)') 620 | FileWriteLine($hTorrc, $sCustomConfig) 621 | FileSetEnd($hTorrc) 622 | FileClose($hTorrc) 623 | EndFunc 624 | 625 | Func Core_InitConnectionToController($iPort) 626 | _Tor_Controller_Connect($g_aTorProcess, $g_sTorConfig_ControlPort) 627 | If @error Then 628 | GUI_LogOut('Failed to connect to Tor contoller! ' & StringFormat('(Error Code: %i and Extended Code: %i)', @error, @extended)) 629 | Return SetError(1, 0, False) 630 | EndIf 631 | _Tor_Controller_Authenticate($g_aTorProcess, $TOR_CONTROLLER_AUTH_HASH, $g_sTorConfig_ControlPass) 632 | If @error Then 633 | GUI_LogOut('Failed to authenticate with Tor contoller! ' & StringFormat('(Error Code: %i and Extended Code: %i)', @error, @extended)) 634 | Return SetError(2, 0, False) 635 | EndIf 636 | GUI_LogOut('Successfully connected to the controller!') 637 | _Tor_Controller_TakeOwnership($g_aTorProcess) 638 | If @error Then 639 | GUI_LogOut('Failed to take ownership of Tor instance ' & StringFormat('(Error Code: %i and Extended Code: %i)', @error, @extended)) 640 | SetExtended(1, True) 641 | EndIf 642 | Return True 643 | EndFunc 644 | 645 | Func Core_SetupTor($bIntro = True) 646 | If Not IsDeclared("bIntro") = $DECLARED_LOCAL Then $bIntro = False 647 | 648 | Local $iMsgBoxFlags, $sMsgBoxTitle, $sMsgBoxMsg 649 | $iMsgBoxFlags = $MB_ICONINFORMATION + $MB_YESNO 650 | $sMsgBoxTitle = "Setup Tor" 651 | If $bIntro Then 652 | $sMsgBoxMsg = "It looks Tor is not configured properly in ProxAllium yet, most likely this is your first run. Do not worry, ProxAllium can guide you through the process!" & @CRLF & @CRLF 653 | EndIf 654 | $sMsgBoxMsg &= "Do you want to continue with the setup process?" 655 | If MsgBox($iMsgBoxFlags, $sMsgBoxTitle, $sMsgBoxMsg) = $IDNO Then Return False 656 | 657 | Local $bUseTB = False 658 | $iMsgBoxFlags = $MB_ICONQUESTION + $MB_YESNO 659 | $sMsgBoxMsg = "Do you have Tor Browser installed?" 660 | If MsgBox($iMsgBoxFlags, $sMsgBoxTitle, $sMsgBoxMsg) = $IDYES Then 661 | $bUseTB = True 662 | Else 663 | $iMsgBoxFlags = $MB_ICONQUESTION + $MB_YESNO 664 | $sMsgBoxMsg = "It is also possible to just use Tor, but I recommend installing the Tor Browser as it automatically updates your copy of Tor when you update the browser and it also adds support for bridges." & @CRLF 665 | $sMsgBoxMsg &= @CRLF & 'Do you want to install Tor Browser and use Tor from it? Choose "No" to continue with only Tor.' 666 | $bUseTB = MsgBox($iMsgBoxFlags, $sMsgBoxTitle, $sMsgBoxMsg) = $IDYES 667 | If $bUseTB Then MsgBox($MB_ICONINFORMATION, $sMsgBoxTitle, "Please download and install the latest version of Tor Browser and click OK to continue.") 668 | EndIf 669 | 670 | Local $sTorFolder, $bFoundTor = False 671 | If $bUseTB Then 672 | Do 673 | $sTorFolder = FileSelectFolder("Please select the folder containing Tor Browser", "", 0, @DesktopDir & '\Tor Browser') 674 | If @error Then Return False 675 | $sTorFolder = $sTorFolder & '\Browser\TorBrowser\Tor' 676 | If FileExists($sTorFolder & '\tor.exe') Then 677 | $bFoundTor = True 678 | EndIf 679 | If Not $bFoundTor Then MsgBox($MB_ICONERROR, "Tor not found", 'Cannot find tor.exe in this folder, please try again and make sure you have selected the installation directory (and not the "Browser" folder inside it).') 680 | Until $bFoundTor 681 | Else 682 | $iMsgBoxFlags = $MB_ICONQUESTION + $MB_YESNO 683 | $sMsgBoxMsg = 'Do you want to download Tor? If you already have a copy of Tor in your computer, then choose "No".' 684 | If MsgBox($iMsgBoxFlags, $sMsgBoxTitle, $sMsgBoxMsg) = $IDYES Then 685 | $iMsgBoxFlags = $MB_ICONINFORMATION 686 | $sMsgBoxMsg = 'The URL (https://www.torproject.org/download/tor) for the page which contains the link to download the "Tor Expert Bundle" has been copied to your clipboard.' & @CRLF 687 | $sMsgBoxMsg &= @CRLF & "Please download it and extract the files to a permanent location (a sub-folder in ProxAllium's folder should be perfect), Click OK when you are done." 688 | ClipPut('https://www.torproject.org/download/tor') 689 | MsgBox($iMsgBoxFlags, $sMsgBoxTitle, $sMsgBoxMsg) 690 | EndIf 691 | Do 692 | $sTorFolder = FileSelectFolder("Please select the folder containing Tor", "") 693 | If @error Then Return False 694 | If FileExists($sTorFolder & '\Tor\tor.exe') Then 695 | $sTorFolder = $sTorFolder & '\Tor' 696 | $bFoundTor = True 697 | ElseIf FileExists($sTorFolder & '\tor.exe') Then 698 | $bFoundTor = True 699 | EndIf 700 | If Not $bFoundTor Then MsgBox($MB_ICONERROR, "Tor not found", "Cannot find tor.exe in this folder, please make sure you have selected the right folder and try again.") 701 | Until $bFoundTor 702 | EndIf 703 | 704 | If $bFoundTor Then 705 | $g_sTorPath = $sTorFolder & '\tor.exe' 706 | IniWrite($CONFIG_INI, "tor", "path", $g_sTorPath) 707 | If $bUseTB Then 708 | Local $sObfs4 = $sTorFolder & '\PluggableTransports\obfs4proxy.exe' 709 | If FileExists($sObfs4) Then 710 | $g_sObfs4Path = $sObfs4 711 | IniWrite($CONFIG_INI, "tor", "obfs4_path", $g_sObfs4Path) 712 | EndIf 713 | Local $sSnowflake = $sTorFolder & '\PluggableTransports\snowflake-client.exe' 714 | If FileExists($sSnowflake) Then 715 | $g_sSnowflakePath = $sSnowflake 716 | IniWrite($CONFIG_INI, "tor", "snowflake_path", $g_sSnowflakePath) 717 | IniWrite($CONFIG_INI, "tor", "snowflake_args", $g_sSnowflakeArgs) 718 | 719 | Local $hBridges = FileOpen($g_sTorConfig_BridgesPath, $FO_APPEND + $FO_CREATEPATH) 720 | If $hBridges <> -1 Then 721 | FileWriteLine($hBridges, '# Uncomment the line below to use snowflake bridge transport') 722 | FileWriteLine($hBridges, '# snowflake 192.0.2.3:1') 723 | FileClose($hBridges) 724 | 725 | GUIDelete($g_hBridgesGUI) 726 | GUI_CreateBridges() 727 | EndIf 728 | EndIf 729 | EndIf 730 | EndIf 731 | 732 | $iMsgBoxFlags = $MB_ICONINFORMATION 733 | $sMsgBoxMsg = 'Setup process is complete!' 734 | MsgBox($iMsgBoxFlags, $sMsgBoxTitle, $sMsgBoxMsg) 735 | 736 | Return $bFoundTor 737 | EndFunc 738 | 739 | Func IsTorRunning() 740 | Return ProcessExists($g_aTorProcess[$TOR_PROCESS_PID]) <> 0 741 | EndFunc 742 | #EndRegion Core Functions 743 | 744 | #Region Tor Functions 745 | Func Tor_Initialize() 746 | GUI_SetStatus("Initializing Tor...") 747 | GUICtrlSetData($g_idMainGUI_TorVersion, "Detecting...") 748 | Local $aTorVersion = _Tor_SetPath($g_sTorPath) 749 | Local $iError = @error 750 | GUI_SetStatus() 751 | If Not $iError Then 752 | $g_aTorVersion = $aTorVersion 753 | GUI_LogOut("Detected Tor version: " & $g_aTorVersion[$TOR_VERSION]) 754 | GUICtrlSetData($g_idMainGUI_TorVersion, $g_aTorVersion[$TOR_VERSION]) 755 | If Not FileExists($g_sTorConfigFile) Then 756 | GUI_LogOut("Cannot find Tor configuration file, generating one now... ", False) 757 | Core_GenTorrc() 758 | If @error Then Core_WaitForExit("Failed to create configuration file!") 759 | GUI_LogOut("Successfully generated Tor configuration file!") 760 | EndIf 761 | Return True 762 | EndIf 763 | GUICtrlSetData($g_idMainGUI_TorVersion, '...') 764 | Switch $iError 765 | Case $TOR_ERROR_GENERIC 766 | GUI_LogOut("Cannot find Tor!") 767 | If Core_SetupTor() Then 768 | Local $vReturn = Tor_Initialize() 769 | Return SetError(@error, 0, $vReturn) 770 | EndIf 771 | Case $TOR_ERROR_VERSION 772 | GUI_LogOut("Unable to identify Tor's version!") 773 | EndSwitch 774 | Return SetError($iError) 775 | EndFunc 776 | 777 | Func Tor_Start() 778 | GUICtrlSetState($g_idMainGUI_ToggleButton, $GUI_DISABLE) 779 | GUI_SetStatus("Starting Tor...") 780 | GUI_LogOut("Starting Tor... ", False) 781 | Local $aTorProcess = _Tor_Start($g_sTorConfigFile) 782 | Local $iError = @error 783 | GUICtrlSetState($g_idMainGUI_ToggleButton, $GUI_ENABLE) 784 | If $iError Then 785 | GUI_SetStatus() 786 | Switch $iError 787 | Case $TOR_ERROR_PROCESS 788 | GUI_LogOut("Unable to start Tor!") 789 | 790 | Case $TOR_ERROR_CONFIG 791 | GUI_LogOut("Invalid Tor configuration, please check your custom entries.") 792 | EndSwitch 793 | Return SetError($iError, 0, False) 794 | EndIf 795 | $g_aTorProcess = $aTorProcess 796 | TrayItemSetText($g_idTrayToggleTor, "Stop Tor") 797 | GUICtrlSetData($g_idMainGUI_ToggleButton, "Stop") 798 | GUI_SetStatus("Waiting for Tor...") 799 | GUI_LogOut("Started Tor with PID: " & $g_aTorProcess[$TOR_PROCESS_PID]) 800 | GUICtrlSetData($g_idMainGUI_TorPID, $g_aTorProcess[$TOR_PROCESS_PID]) 801 | GUICtrlSetData($g_idTorOutput, "") ; Reset the Tor Output 802 | Return True 803 | EndFunc 804 | 805 | Func Tor_Stop() 806 | GUICtrlSetState($g_idMainGUI_ToggleButton, $GUI_DISABLE) 807 | GUI_LogOut("Trying to stop Tor... ", False) 808 | GUI_SetStatus("Stopping Tor...") 809 | If Not ProcessExists($g_aTorProcess[$TOR_PROCESS_PID]) Then 810 | GUI_LogOut("but Tor is already stopped!") 811 | Return True 812 | EndIf 813 | _Tor_Stop($g_aTorProcess) 814 | If @error Then 815 | Local $iError = @extended 816 | GUI_LogOut("Failed to stop Tor (Error Code: " & $iError & ')') 817 | Return SetError($iError, 0, False) 818 | EndIf 819 | GUI_LogOut("Successfully stopped Tor!") 820 | Return True 821 | EndFunc 822 | 823 | Func Tor_Toggle() 824 | If IsTorRunning() Then 825 | Tor_Stop() 826 | Else 827 | Tor_Start() 828 | EndIf 829 | EndFunc 830 | #EndRegion Tor Functions 831 | 832 | #EndRegion Functions 833 | --------------------------------------------------------------------------------