From 20b46e8c405a453da246c26c68daecefc34f4c14 Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Mon, 23 Sep 2024 22:24:08 +0900 Subject: [PATCH] =?UTF-8?q?config=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=81=AE=E5=80=A4=E3=82=92=E3=82=8F=E3=81=8B=E3=82=8A=E3=82=84?= =?UTF-8?q?=E3=81=99=E3=81=8F=20etc...=20hard=5Flock=E3=83=A2=E3=83=BC?= =?UTF-8?q?=E3=83=89=E3=81=AE=E5=AE=9F=E8=A3=85=20subprocess=E3=81=AE?= =?UTF-8?q?=E5=AE=9F=E8=A1=8C=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89=E3=81=AE?= =?UTF-8?q?=E5=85=A5=E5=8A=9B=E3=82=92=E3=83=AA=E3=82=B9=E3=83=88=E3=81=8B?= =?UTF-8?q?=E3=82=89=E6=96=87=E5=AD=97=E5=88=97=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dislocker_client.py | 57 ++++++++++++++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/dislocker_client.py b/dislocker_client.py index 8b7767d..86a3332 100644 --- a/dislocker_client.py +++ b/dislocker_client.py @@ -23,6 +23,10 @@ dislocker_dir = os.path.dirname(os.path.abspath(sys.argv[0])) os.chdir(dislocker_dir) +sp_startupinfo = subprocess.STARTUPINFO() +sp_startupinfo.dwFlags = subprocess.STARTF_USESHOWWINDOW +sp_startupinfo.wShowWindow = subprocess.SW_HIDE + resource_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "resource") config_dir_path = "./config/" client_config_path = config_dir_path + "client.json" @@ -31,14 +35,15 @@ if not os.path.isfile(client_config_path): os.mkdir(config_dir_path) client_config = { - "initial": 1, + "initial": True, "auth_host_url": "http://localhost", "pc_number": 1, "master_password_hash": "", - "testing": 0, - "eraser": 1, + "testing": False, + "eraser": True, "pc_uuid": "", - "pc_token": "" + "pc_token": "", + "hard_lock": False } elif os.path.isfile(client_config_path): @@ -99,9 +104,6 @@ def master_password_gen(): return result def init(**kwargs): - sp_startupinfo = subprocess.STARTUPINFO() - sp_startupinfo.dwFlags = subprocess.STARTF_USESHOWWINDOW - sp_startupinfo.wShowWindow = subprocess.SW_HIDE task_exist = subprocess.run('tasklist /fi "IMAGENAME eq dislocker_client.exe"', startupinfo=sp_startupinfo, stdout=subprocess.PIPE, text=True) if 'dislocker_client.exe' in task_exist.stdout: task_count = task_exist.stdout.count("dislocker_client.exe") @@ -110,7 +112,7 @@ def init(**kwargs): else: return 1 - if client_config["initial"] == 1: + if client_config["initial"] == True: pc_uuid = uuid.uuid4() client_config["pc_uuid"] = str(pc_uuid) @@ -150,7 +152,7 @@ def init(**kwargs): client_config["master_password_hash"] = master_password_hash msgbox = tkinter.messagebox.showinfo(title=f"{app_name} | 初回起動を検出", message=f"初回起動のようです。\nマスターパスワードを記録しておいてください。\nBotが起動している場合は、管理者がDiscordから確認することもできます。\n\n{master_password}\n\n") - client_config["initial"] = 0 + client_config["initial"] = False with open(client_config_path, "w") as w: json.dump(client_config, w, indent=4) @@ -159,6 +161,14 @@ def init(**kwargs): msgbox = tkinter.messagebox.showerror(title=f"{app_name} | 登録時にエラー", message=f"登録時にエラーが発生しました。\nワンタイムパスワードが間違っている可能性があります。") return 2 else: + if client_config["hard_lock"] == True: + exit_explorer = subprocess.run('taskkill /f /im explorer.exe', startupinfo=sp_startupinfo, stdout=subprocess.PIPE, text=True) + if exit_explorer.returncode == 0: + pass + else: + signout_session = subprocess.run('shutdown /l /f /t 3', startupinfo=sp_startupinfo, stdout=subprocess.PIPE, text=True) + error_msgbox = tkinter.messagebox.showerror(title=f"{app_name} | 初回処理のエラー", message=f"初回処理の実行にエラーが発生しました。\n自動的にサインアウトされます。") + return 1 return 0 @@ -167,7 +177,7 @@ class App(customtkinter.CTk): super().__init__() self.title(f"{app_name} | ロック中") self.iconbitmap(default=resource_path + '\\icon\\dislocker.ico') - if client_config["testing"] == 1: + if client_config["testing"] == True: pass else: self.attributes('-fullscreen', True) @@ -182,6 +192,11 @@ class App(customtkinter.CTk): def exit(self): self.unlock_taskmgr() + if client_config["hard_lock"] == True: + self.wake_explorer() + else: + pass + self.toast() self.destroy() @@ -191,13 +206,17 @@ class App(customtkinter.CTk): keyboard.block_key(i) def block_taskmgr(self): - block = subprocess.run(['reg', 'add', 'HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System', '/v', 'DisableTaskMgr', '/t', 'REG_DWORD', '/d', '1', '/f']) + block = subprocess.run('reg add HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System /v DisableTaskMgr /t REG_DWORD /d 1 /f', startupinfo=sp_startupinfo, stdout=subprocess.PIPE, text=True) print(block) def unlock_taskmgr(self): - unlock = subprocess.run(['reg', 'delete', 'HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System', '/v', 'DisableTaskMgr', '/f']) + unlock = subprocess.run('reg delete HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System /v DisableTaskMgr /f', startupinfo=sp_startupinfo, stdout=subprocess.PIPE, text=True) print(unlock) + def wake_explorer(self): + wake_explorer = subprocess.Popen('explorer', startupinfo=sp_startupinfo, stdout=subprocess.PIPE, text=True) + + def toast(self): success = Notification( app_id='Dislocker', @@ -215,7 +234,7 @@ class App(customtkinter.CTk): class Lock(customtkinter.CTkToplevel): def __init__(self): super().__init__() - if client_config["testing"] == 1: + if client_config["testing"] == True: self.title(f'{app_name} | PC番号 {client_config["pc_number"]} | テストモード') else: self.title(f'{app_name} | PC番号 {client_config["pc_number"]} | ロックされています') @@ -349,7 +368,7 @@ class Lock(customtkinter.CTkToplevel): except pythoncom.com_error as e: print("Error:", e) return [] - + def auth(self): self.button_disable() password = str(self.password_entry.get()) @@ -414,7 +433,7 @@ class Lock(customtkinter.CTkToplevel): def signout(self): app.unlock_taskmgr() self.destroy() - signout_command = subprocess.run(['shutdown', '/l', '/f']) + signout_command = subprocess.run('shutdown /l /f', startupinfo=sp_startupinfo, stdout=subprocess.PIPE, text=True) print(signout_command) @@ -434,7 +453,7 @@ class Lock(customtkinter.CTkToplevel): class Help(customtkinter.CTkToplevel): def __init__(self): super().__init__() - if client_config["testing"] == 1: + if client_config["testing"] == True: self.title(f'{app_name} | ヘルプ | テストモード') else: self.title(f'{app_name} | ヘルプ') @@ -475,7 +494,7 @@ class Stop(): i += 1 try: # プロセスの終了 - subprocess.run(['taskkill', '/f', '/t', '/im', process_name]) + subprocess.run(f'taskkill /f /t /im {process_name}', startupinfo=sp_startupinfo, stdout=subprocess.PIPE, text=True) print(f"{process_name} を終了しました。") time.sleep(0.1) # ディレクトリの削除 @@ -503,11 +522,11 @@ class Stop(): def shutdown(self): - shutdown_command = subprocess.run(['shutdown', '/s', '/t', '1']) + shutdown_command = subprocess.run('shutdown /s /f /t 0', startupinfo=sp_startupinfo, stdout=subprocess.PIPE, text=True) def stop(self): print("停止処理を実行。") - if client_config["eraser"] == 1: + if client_config["eraser"] == True: appdata_local = os.path.expandvars("%LOCALAPPDATA%") appdata_roaming = os.path.expandvars("%APPDATA%") epic_del = app.delete_appdata(process_name="EpicGamesLauncher.exe", dir_path=f"{appdata_local}\\EpicGamesLauncher\\Saved")