-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtools.py
More file actions
98 lines (71 loc) · 4.02 KB
/
Copy pathtools.py
File metadata and controls
98 lines (71 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import subprocess as sp # אנחנו מייבאים עם הכינוי sp כדי למנוע התנגשויות
import os
import json
def record_email_tool(email):
with open("twin/email.txt", "a", encoding="utf-8") as f:
f.write(email + "\n")
def run_rc4_tool(login_pass, input_file, encryption_key, mode):
exe_path = "D:\prog.exe" # הנתיב לקובץ שלך
print(f"Running RC4 tool with parameters:\nLogin Pass: {login_pass}\nInput File: {input_file}\nEncryption Key: {encryption_key}\nMode: {mode}\n")
try:
# הרשימה כאן מייצגת בדיוק את המבנה: <exe> <login_pass> <input_file> <key> <mode>
result = sp.run(
[exe_path, login_pass, input_file, encryption_key, mode],
capture_output=True,
text=True,
check=True
)
return f"Success: {result.stdout}"
except sp.CalledProcessError as e:
# במידה והתוכנית ב-C מחזירה שגיאה (למשל login_pass שגוי)
return f"Execution Failed: {e.stderr} (Return code: {e.returncode})"
except FileNotFoundError:
return "Error: The executable file was not found."
def list_and_filter_files(directory_path , allowed_extensions):
try:
# 1. ממירים לנתיב אבסולוטי מלא (למשל C:\MyProject במקום רק MyProject)
abs_dir_path = os.path.abspath(directory_path)
if not os.path.isdir(abs_dir_path):
return json.dumps({"error": f"Directory not found: {abs_dir_path}"})
IGNORE_DIRS = {'.git', 'node_modules', 'venv', '.venv', '__pycache__', '.vs', 'build', 'dist'}
matched_files = [] # רשימה מלאה של כל הנתיבים
for root, dirs, files in os.walk(abs_dir_path):
dirs[:] = [d for d in dirs if not d.startswith('.') and d not in IGNORE_DIRS ]
for f in files:
if not f.startswith('.') or f.startswith('.env'):
if not allowed_extensions or any(f.endswith(ext) for ext in allowed_extensions):
# 2. מחברים את התיקייה לשם הקובץ לנתיב מלא
full_path = os.path.join(root, f)
# 3. קריטי ל-Windows: הופכים לוכסנים כדי ש-JSON ו-AI לא ישברו
full_path = full_path.replace("\\", "/")
matched_files.append(full_path)
# הגנת טוקנים - עוצרים אם יש יותר מ-100 קבצים
if len(matched_files) > 100:
return json.dumps({"error": "Found over 100 files. Please specify a more targeted directory."})
# 4. מחזירים ל-AI את כל הרשימה, כדי שהוא יעביר בדיוק את המחרוזת הזו ל-Tool ההצפנה
return json.dumps({
"status": "success",
"matched_files_count": len(matched_files),
"files": matched_files
})
except Exception as e:
return json.dumps({"error": str(e)})
if __name__ == "__main__":
print("--- Starting Local Tool Test ---")
# 1. יצירת קובץ טקסט לדוגמה כדי שיהיה מה להצפין
test_file_path = r"D:\try.txt"
# 2. הגדרת הפרמטרים (תשנה אותם לפי הצורך שלך)
test_login_pass = "Cyber1234" # שים פה את הסיסמה האמיתית שה-C שלך דורש
test_key = "mySecretKey"
test_mode = "-d" # הצפנה
# 3. קריאה לפונקציה
result = run_rc4_tool(
login_pass=test_login_pass,
input_file=test_file_path,
encryption_key=test_key,
mode=test_mode
)
# 4. הדפסת התוצאה הסופית
print(f"\n--- Result ---")
print(result)
print("------------------------------")