Files
Interceptor-APS/interceptor-aps-a-2.py
2026-02-06 18:53:49 -05:00

230 lines
8.5 KiB
Python

import threading
import sys
import time
from watchfiles import watch
import pygetwindow as gw
import pyautogui
import subprocess
from termcolor import colored
# ___ _ _ _ ____ ____
# |_ _|_ __ | |_ ___ _ __ ___ ___ _ __ | |_ ___ _ __ / \ | _ \/ ___|
# | || '_ \| __/ _ \ '__/ __/ _ \ '_ \| __/ _ \| '__| / _ \ | |_) \___ \
# | || | | | || __/ | | (_| __/ |_) | || (_) | | / ___ \| __/ ___) |
# |___|_| |_|\__\___|_| \___\___| .__/ \__\___/|_| /_/ \_\_| |____/
# |_| APS Version Alpha-2 by P7MJ
# ---------- CONFIGURATION ---------- #
monitor_path = r"C:\Program Files\Renato Software\Senso.Cloud.Client" # Path to be monitored
# ---------- DON'T TOUCH ---------- #
program = "" # 0 is use path, -1 is use name, 1-4 is programs
p_name = ""
p_path = "" # used only if program = 0.
# ---------- BRING TO FRONT ---------- #
def bring_to_front(window_title):
time.sleep(0.5)
try:
print("Bringing to front...", end = " ")
windows = gw.getWindowsWithTitle(window_title)
if windows:
window = windows[0]
window.restore()
window.activate()
print("Window has been brought to front.")
else:
print(colored("ERROR: Window not found", 'red'))
except Exception as e:
print(colored(f"Error: {e}", 'red'))
# ---------- FILE WATCHER ---------- #
def file_watch(iftest):
print("=" * 80)
print("Monitoring changes in " + monitor_path + ".")
print("-" * 80)
try:
if iftest == False:
for changes in watch(monitor_path):
for change_type, path in changes:
print(f"Change type: {change_type}, Path: {path}")
return True
else:
return True
except Exception as e:
print(colored(f"File Watch Error: {e}", 'red'))
# ---------- MINIMIZE ---------- #
def minimize():
print("=" * 80)
print("Minimizing all windows...", end = " ")
pyautogui.hotkey('win', 'd')
print("Completed.")
# ---------- LAUNCH COVER PROGRAM ---------- #
def launch_cover(programs):
time.sleep(0.5)
print("=" * 80)
print("Launching cover application...", end = " ")
if programs == "1": # Chrome
try:
subprocess.run(
["C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"]
)
print("Launched Chrome.")
except Exception as e:
print(colored(f"Chrome Launch Error: {e}", 'red'))
elif programs == "2": # Edge
try:
subprocess.run(
["C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe"]
)
print("Launched Edge.")
except Exception as e:
print(colored(f"Edge Launch Error: {e}", 'red'))
elif programs == "3": # Adobe Illustrator
try:
subprocess.run(
["C:\\Program Files\\Adobe\\Adobe Illustrator 2025\\Support Files\\Contents\\Windows\\Illustrator.exe"]
)
print("Launched Illustrator.")
except Exception as e:
print(colored(f"Illustrator Launch Error: {e}", 'red'))
elif programs == "4": # Onenote
try:
subprocess.run(
["C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\ONENOTE.EXE"]
)
print("Launched OneNote.")
except Exception as e:
print(colored(f"OneNote Launch Error: {e}", 'red'))
else:
print(colored("Error: Invalid Cover App Specified.", 'red'))
# ---------- LAUNCH COVER PROGRAM PATH ---------- #
def launch_cover_path(path):
print("Launching custom path...", end = " ")
time.sleep(0.5)
subprocess.run(
[path]
)
print("Launched custom path.")
# ---------- LAUNCH SPECIFIC CHROME TAB ---------- #
def specific_tab(browser, tab_no):
time.sleep(0.5)
try:
print(f"Bringing browser {browser} to front...", end = " ")
windows = gw.getWindowsWithTitle(browser)
if windows:
window = windows[0]
window.restore()
window.activate()
print(f"{browser} has been brought to front.")
print(f"Going to tab {tab_no} in browser...", end = " ")
try:
pyautogui.hotkey('ctrl', '1')
if tab_no == 1:
print("Success.")
else:
for i in range(tab_no - 1):
pyautogui.hotkey('ctrl', 'tab')
time.sleep(0.1)
print("Success.")
except Exception as e:
print(colored(f"Tab switch error: {e}", 'red'))
else:
print(colored("ERROR: Window not found", 'red'))
except Exception as e:
print(colored(f"Specific-Tab Error: {e}", 'red'))
# ---------- Main Process ---------- #
def main():
global p_name, p_path, testmode
testmode = False
while True:
print()
print("=" * 80)
print(f"Interceptor APS (Active Protection System) ===== TESTMODE: {testmode}")
print("-" * 80)
print("Choose a cover app to open:")
print("[1] Chrome (1)")
print("[2] Edge (1)")
print("[3] Adobe Illustrator (2)")
print("[4] Onenote (3)")
print("[5] Enter a path (4)")
print("[6] Specify Chrome Tab Number (5)")
print("[7] Specify Window Name (6)\n")
print("[x] Help")
print("[y] Set test mode", end = "\n\n")
program = input("Enter your option > ")
if program == "5": # If path is selected (I doubt that)
p_path = input("Enter full path > ")
program = "0" # Indicate that the path option is selected
elif program == "6":
try:
tabs_no = input("Tab number > ")
if tabs_no.isdigit():
pass
else:
print("Error: Not a digit")
main()
watchresults = file_watch(testmode) # STILL TESTING Switch to false if finished!!!
minimize()
specific_tab("chrome", int(tabs_no))
main()
except KeyboardInterrupt:
print("Canceled by user.")
main()
elif program == "7": # If name is chosen
program = "-1" # Indicate that the name option is selected
p_name = input("Name > ")
elif program.lower() == "x":
print("- (1): Opens a new, empty window of this program")
print("- (2): Opens the window. You have to open the application first and set it up to the desired state to have it work.")
print("- (3): Opens an identical but new window of what you already have. The program can be closed, but you must set it up to the desired state before closing it.")
print("- (4): Enter a path to the program. This only opens the program and requires you to do research on the program behavior when opened. I am still verifying if you need to enter \"\\\\\" for each \\.")
print("- (5): Opens the specified chrome tab. This method is newly developed and is a bit slower to respond, but can precisely open any tab in chrome.")
print("- (6): Specifies a window name. Partial names (wildcards) are default.")
elif program.lower() == "y":
if testmode == False:
testmode == True
print("Test mode set to True.\n")
main()
else:
testmode == False
main()
else:
pass # All other options, if selected, are already stored in program by this time
# Begin the watching process.
try:
watchresults = file_watch(testmode)
except KeyboardInterrupt:
print("Canceled by user.")
main()
# If it advances to below then there must have been a file change. (VERIFY)
if program == "0": # If we chose path
minimize()
launch_cover_path(p_path) # VERIFY IF DOUBLE ESCAPES ARE NEEDED WHEN PATH IS FIRST ENTERED BY USER
elif program == "-1": # If we chose name
minimize()
bring_to_front(p_name)
else:
minimize()
launch_cover(program) # Other options must be string numbers 1-4
# ---------- Running the code ---------- #
if __name__ == "__main__":
main()