Skip to content

Commit 53873d6

Browse files
Add Linux support for KRNL automation with subprocess and xdotool
Co-authored-by: oicne4 <oicne4@gmail.com>
1 parent 8f8b584 commit 53873d6

1 file changed

Lines changed: 38 additions & 15 deletions

File tree

krnl_automation.py

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import re
22
import time
3+
import subprocess
34
import pyautogui
45
import pyperclip
56
from selenium import webdriver
@@ -9,12 +10,13 @@
910
from selenium.webdriver.support.ui import WebDriverWait
1011
from selenium.webdriver.support import expected_conditions as EC
1112

12-
# キー形式チェック
13+
# Linux用のKRNLパス(実際のパスに変更してください)
14+
KRNL_PATH = "/path/to/krnl" # ここに実際のKRNL実行ファイルパスを入れてください
15+
1316
def check_krnl_key(key: str):
1417
pattern = re.compile(r'^[0-9a-fA-F]{4}(-[0-9a-fA-F]{4}){3}$')
1518
return bool(pattern.match(key))
1619

17-
# KRNLキー自動取得
1820
def auto_get_key_full():
1921
print("\n[+] KRNLキー取得自動化を開始します...")
2022
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
@@ -24,19 +26,16 @@ def auto_get_key_full():
2426
krnl_key = None
2527

2628
try:
27-
# 「次へ」クリック
2829
next_btn = wait.until(EC.element_to_be_clickable((By.XPATH, "//button[contains(text(), '次へ')]")))
2930
time.sleep(1)
3031
next_btn.click()
3132
print("[+] '次へ'ボタンをクリックしました")
3233

33-
# 「続行」クリック
3434
time.sleep(5)
3535
continue_btn = wait.until(EC.element_to_be_clickable((By.XPATH, "//button[contains(text(), '続行')]")))
3636
continue_btn.click()
3737
print("[+] '続行'ボタンをクリックしました")
3838

39-
# キー取得
4039
key_element = wait.until(EC.presence_of_element_located((By.XPATH, "//code")))
4140
krnl_key = key_element.text.strip()
4241
pyperclip.copy(krnl_key)
@@ -49,26 +48,50 @@ def auto_get_key_full():
4948

5049
return krnl_key
5150

52-
# KRNLにキーを入力してInject
51+
def focus_krnl_window():
52+
"""Linux用のウィンドウフォーカス関数"""
53+
try:
54+
# xdotoolを使用してKRNLウィンドウをアクティブにする
55+
subprocess.run(["xdotool", "search", "--name", "KRNL", "windowactivate"], check=True)
56+
time.sleep(1)
57+
print("[+] KRNLウィンドウをアクティブにしました")
58+
return True
59+
except (subprocess.CalledProcessError, FileNotFoundError):
60+
print("[-] xdotoolが見つからないか、KRNLウィンドウが見つかりません。")
61+
print("[-] 手動でKRNLウィンドウをアクティブにしてください。")
62+
time.sleep(5) # ユーザーに手動でアクティブにしてもらう時間
63+
return True
64+
5365
def inject_krnl(key):
5466
print("\n[+] KRNLにキーを入力してInjectします...")
55-
time.sleep(5) # ユーザーにKRNL画面をアクティブにしてもらう時間
56-
57-
# キー入力欄クリック(座標は環境に合わせて調整)
58-
pyautogui.click(500, 400) # 仮の座標
67+
if not focus_krnl_window():
68+
return
69+
70+
# キー入力欄クリック(位置は環境に合わせて調整)
71+
pyautogui.click(500, 400)
5972
time.sleep(0.5)
60-
73+
6174
# キー貼り付け
6275
pyautogui.hotkey("ctrl", "v")
6376
time.sleep(0.5)
64-
65-
# Submitクリック(座標も調整必要
77+
78+
# Injectボタンクリック(位置は調整が必要
6679
pyautogui.click(600, 500)
6780
time.sleep(1)
68-
69-
print("[+] キー送信完了、Injectが開始されます。")
81+
82+
print("[+] Inject処理完了しました。")
7083

7184
if __name__ == "__main__":
85+
print("[+] KRNLを起動します...")
86+
try:
87+
subprocess.Popen([KRNL_PATH])
88+
time.sleep(10) # 起動待機(PC環境によって調整してください)
89+
except FileNotFoundError:
90+
print("[-] KRNL実行ファイルが見つかりません。")
91+
print("[-] KRNL_PATHを正しいパスに設定してください。")
92+
print("[-] 手動でKRNLを起動してください。")
93+
time.sleep(5)
94+
7295
user_key = input("既にKRNLキーを持っていますか?(なければEnter): ").strip()
7396

7497
if user_key and check_krnl_key(user_key):

0 commit comments

Comments
 (0)