MrA7A commited on
Commit
ba03dbe
·
verified ·
1 Parent(s): 17ccb45

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +346 -42
app.py CHANGED
@@ -6,11 +6,12 @@ import json
6
  import time
7
  from datetime import datetime
8
  import logging
 
9
 
10
  logging.basicConfig(level=logging.INFO)
11
  logger = logging.getLogger(__name__)
12
 
13
- app = FastAPI(title="Windows AI Controller - الخادم المركزي")
14
 
15
  # تمكين CORS للسماح بالاتصال من تطبيقات Windows
16
  app.add_middleware(
@@ -73,7 +74,7 @@ def update_client_activity(client_id: str, activity: str = "chat"):
73
  async def root():
74
  return {
75
  "status": "running",
76
- "service": "Windows AI Controller Server",
77
  "timestamp": datetime.now().isoformat(),
78
  "connected_clients": len(connected_clients),
79
  "pending_commands": len(pending_commands),
@@ -82,65 +83,368 @@ async def root():
82
 
83
  @app.post("/api/chat")
84
  async def chat_with_ai(request: ChatRequest):
85
- """نقطة النهاية للمحادثة مع الذكاء الاصطناعي"""
86
  try:
87
  logger.info(f"💬 طلب محادثة من العميل {request.client_id}: {request.message}")
88
-
89
- # تحديث نشاط العميل فوراً
90
  update_client_activity(request.client_id, "chat")
91
 
92
- # محاكاة استجابة من نموذج الذكاء الاصطناعي الحقيقي
93
- thinking = f"🤔 **التفكير الاستراتيجي**: تحليل متعمق لطلب المستخدم '{request.message}'. تحديد الإجراءات المطلوبة بناءً على نوع الطلب والمتطلبات."
94
 
95
- if "لعبة" in request.message or "game" in request.message:
96
- response_msg = "🎮 **الوكيل الاستراتيجي يحلل طلب الألعاب**\n\nتم استلام طلبك المتعلق بالألعاب بنجاح! 🚀\n\nجاري:\n• إعداد أدوات الهندسة العكسية المتقدمة\n• تحضير محلل الذاكرة والعمليات\n• تجهيز مكتبات تعديل القيم\n\n🔍 **أخبرني باسم اللعبة المحددة والميزة التي تريد تعديلها**"
97
- actions = [
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  {
99
- "type": "game_analysis",
100
- "description": "تحليل هياكل اللعبة والذاكرة باستخدام الذكاء الاستراتيجي",
101
- "parameters": {"game_detected": True, "analysis_level": "advanced"}
102
  }
103
  ]
104
- elif "بوت" in request.message or "bot" in request.message:
105
- response_msg = "🤖 **تطوير البوتات - تحليل استراتيجي**\n\nممتاز! جاري:\n• تحضير بيئة التطوير المتقدمة\n• إعداد مكتبات الأتمتة\n• تحليل متطلبات الأداء\n\n💡 **ما نوع البوت الذي تريد تطويره وأي لعبة يستهدفها؟**"
106
- actions = [
 
 
 
 
 
 
 
 
 
 
 
 
 
107
  {
108
- "type": "bot_development",
109
- "description": "إعداد بيئة تطوير البوت باستراتيجيات متقدمة",
110
- "parameters": {"development_phase": "requirements_analysis"}
 
 
111
  }
112
  ]
113
- elif "مرحبا" in request.message or "اهلا" in request.message or "hello" in request.message:
114
- response_msg = "🧠 **الوكيل الاستراتيجي يرحب بك!**\n\n✅ **تم الاتصال بنجاح بالخادم المركزي**\n\n🔧 **الميزات المتاحة عبر الوكيل الاستراتيجي:**\n• تحليل ذاكرة متقدم للألعاب\n• هندسة عكسية باستخدام الذكاء الاصطناعي\n• تطوير برامج وبوتات مخصصة\n• حل مشاكل تقنية معقدة\n• بحث واستخراج معلومات متقدم\n\n🚀 **ما المهمة التي تريدني مساعدتك فيها؟**"
115
- actions = [
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  {
117
- "type": "strategic_welcome",
118
- "description": "تهيئة البيئة الاستراتيجية للعميل",
119
- "parameters": {"welcome_complete": True, "client_registered": True}
120
  }
121
  ]
122
- else:
123
- response_msg = f"🧠 **الوكيل الاستراتيجي يحلل طلبك**: '{request.message}'\n\n✅ **تم استلام طلبك بنجاح عبر الخادم المركزي**\n\n🔧 **جاري المعالجة باستخدام الذكاء الاصطناعي المتقدم...**\n\n💡 **الميزات المتاحة:**\n• تحليل متقدم للذاكرة والعمليات\n• هندسة عكسية متطورة للألعاب\n• تطوير برامج وبوتات مخصصة\n• حل مشاكل تقنية معقدة\n• بحث واستخراج معلومات متقدم"
124
- actions = [
 
 
 
125
  {
126
- "type": "strategic_analysis",
127
- "description": "تحليل استراتيجي متقدم للمهمة المطلوبة",
128
- "parameters": {"analysis_type": "general", "complexity": "high"}
 
 
 
 
 
 
 
 
 
 
 
129
  }
130
  ]
131
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  response = ChatResponse(
133
- thinking_process=thinking,
134
- message=response_msg,
135
- actions=actions
136
  )
137
-
138
- logger.info(f"✅ تم إرسال رد استراتيجي للع��يل {request.client_id} - الإجراءات: {len(actions)}")
139
- return response
140
-
141
- except Exception as e:
142
- logger.error(f"❌ خطأ في معالجة المحادثة: {e}")
143
- raise HTTPException(status_code=500, detail=str(e))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
 
145
  @app.post("/api/register-client")
146
  async def register_client(registration: ClientRegistration):
 
6
  import time
7
  from datetime import datetime
8
  import logging
9
+ import re
10
 
11
  logging.basicConfig(level=logging.INFO)
12
  logger = logging.getLogger(__name__)
13
 
14
+ app = FastAPI(title="Windows AI Controller - الخادم المركزي الحقيقي")
15
 
16
  # تمكين CORS للسماح بالاتصال من تطبيقات Windows
17
  app.add_middleware(
 
74
  async def root():
75
  return {
76
  "status": "running",
77
+ "service": "Windows AI Controller Server - النسخة الحقيقية",
78
  "timestamp": datetime.now().isoformat(),
79
  "connected_clients": len(connected_clients),
80
  "pending_commands": len(pending_commands),
 
83
 
84
  @app.post("/api/chat")
85
  async def chat_with_ai(request: ChatRequest):
86
+ """نقطة النهاية للمحادثة مع الذكاء الاصطناعي - النسخة الحقيقية"""
87
  try:
88
  logger.info(f"💬 طلب محادثة من العميل {request.client_id}: {request.message}")
 
 
89
  update_client_activity(request.client_id, "chat")
90
 
91
+ user_message = request.message.lower()
 
92
 
93
+ # تحليل الطلب وتحديد الإجراءات الحقيقية
94
+ if "مسح" in user_message and "برامج" in user_message:
95
+ return await handle_scan_programs(request)
96
+ elif "مسح" in user_message and "عمليات" in user_message:
97
+ return await handle_scan_processes(request)
98
+ elif "هندسة عكسية" in user_message or "reverse engineer" in user_message:
99
+ return await handle_reverse_engineering(request)
100
+ elif "بوت" in user_message or "bot" in user_message:
101
+ return await handle_bot_development(request)
102
+ elif "شاشة" in user_message or "screenshot" in user_message:
103
+ return await handle_screenshot(request)
104
+ elif "ذاكرة" in user_message or "memory" in user_message:
105
+ return await handle_memory_scan(request)
106
+ elif "تثبيت" in user_message or "install" in user_message:
107
+ return await handle_tool_installation(request)
108
+ elif "مرحبا" in user_message or "اهلا" in user_message or "hello" in user_message:
109
+ return await handle_welcome(request)
110
+ else:
111
+ return await handle_general_request(request)
112
+
113
+ except Exception as e:
114
+ logger.error(f"❌ خطأ في معالجة المحادثة: {e}")
115
+ raise HTTPException(status_code=500, detail=str(e))
116
+
117
+ async def handle_scan_programs(request: ChatRequest):
118
+ """معالجة طلب مسح البرامج"""
119
+ thinking = "🤔 **التفكير الاستراتيجي**: المستخدم يطلب مسح البرامج المثبتة على جهازه. جاري إعداد أمر المسح الشامل..."
120
+
121
+ response = ChatResponse(
122
+ thinking_process=thinking,
123
+ message="🔍 **جاري مسح البرامج المثبتة على جهازك...**\n\nسيقوم الوكيل التنفيذي بمسح شامل لجميع البرامج المثبتة وعرضها لك.",
124
+ actions=[
125
+ {
126
+ "type": "scan_installed_programs",
127
+ "description": "مسح شامل للبرامج المثبتة على النظام",
128
+ "parameters": {
129
+ "scan_type": "comprehensive",
130
+ "include_versions": True
131
+ }
132
+ }
133
+ ]
134
+ )
135
+ return response
136
+
137
+ async def handle_scan_processes(request: ChatRequest):
138
+ """معالجة طلب مسح العمليات"""
139
+ thinking = "🤔 **التفكير الاستراتيجي**: المستخدم يريد مسح العمليات النشطة على جهازه. تحديد العمليات الجارية والألعاب النشطة."
140
+
141
+ response = ChatResponse(
142
+ thinking_process=thinking,
143
+ message="⚡ **جاري مسح العمليات النشطة على جهازك...**\n\nعرض جميع العمليات الجارية حالياً مع التركيز على عمليات الألعاب.",
144
+ actions=[
145
+ {
146
+ "type": "scan_running_processes",
147
+ "description": "مسح العمليات النشطة على النظام",
148
+ "parameters": {
149
+ "include_memory_usage": True,
150
+ "detect_games": True
151
+ }
152
+ }
153
+ ]
154
+ )
155
+ return response
156
+
157
+ async def handle_reverse_engineering(request: ChatRequest):
158
+ """معالجة طلب الهندسة العكسية"""
159
+ thinking = "🤔 **التفكير الاستراتيجي**: المستخدم يطلب هندسة عكسية لملف. تحديد المسار وتحليل المتطلبات..."
160
+
161
+ # استخراج مسار الملف من الرسالة
162
+ file_path = extract_file_path(request.message)
163
+
164
+ if not file_path:
165
+ response = ChatResponse(
166
+ thinking_process=thinking + " لم يتم تحديد مسار الملف. طلب التوضيح من المستخدم.",
167
+ message="🔧 **الهندسة العكسية**\n\nيبدو أنك تريد عمل هندسة عكسية لملف. الرجاء تحديد المسار الكامل للملف:\n\nمثال: `F:\\Coven Kal\\engine.exe`",
168
+ actions=[
169
  {
170
+ "type": "prepare_reverse_engineering",
171
+ "description": "تحضير بيئة الهندسة العكسية",
172
+ "parameters": {}
173
  }
174
  ]
175
+ )
176
+ else:
177
+ response = ChatResponse(
178
+ thinking_process=thinking + f" تم تحديد المسار: {file_path}. جاري إعداد أدوات الهندسة العكسية.",
179
+ message=f"🔬 **جاري تحضير الهندسة العكسية لـ**: `{file_path}`\n\nسيقوم النظام بتحليل الملف بشكل كامل واستخراج جميع المعلومات الممكنة.",
180
+ actions=[
181
+ {
182
+ "type": "reverse_engineer",
183
+ "description": f"هندسة عكسية متقدمة للملف {file_path.split('/')[-1] if '/' in file_path else file_path.split('\\\\')[-1]}",
184
+ "parameters": {
185
+ "file_path": file_path,
186
+ "analysis_depth": "deep",
187
+ "extract_resources": True,
188
+ "analyze_imports": True
189
+ }
190
+ },
191
  {
192
+ "type": "analyze_game_file",
193
+ "description": f"تحليل بنية ملف اللعبة",
194
+ "parameters": {
195
+ "file_path": file_path
196
+ }
197
  }
198
  ]
199
+ )
200
+
201
+ return response
202
+
203
+ async def handle_bot_development(request: ChatRequest):
204
+ """معالجة طلب تطوير البوت"""
205
+ thinking = "🤔 **التفكير الاستراتيجي**: المستخدم يطلب تطوير بوت. تحديد نوع البوت واللعبة المستهدفة..."
206
+
207
+ game_name = extract_game_name(request.message)
208
+ bot_type = extract_bot_type(request.message)
209
+
210
+ if not game_name:
211
+ response = ChatResponse(
212
+ thinking_process=thinking + " لم يتم تحديد اسم اللعبة. طلب التوضيح.",
213
+ message="🤖 **تطوير البوتات**\n\nلنبدأ في تطوير البوت! أخبرني:\n• اسم اللعبة المستهدفة\n• نوع البوت المطلوب (مزرعة، قتال، تجارة، إلخ)\n• الميزات الخاصة التي تريدها",
214
+ actions=[
215
  {
216
+ "type": "prepare_bot_development",
217
+ "description": "تحضير بيئة تطوير البوتات",
218
+ "parameters": {}
219
  }
220
  ]
221
+ )
222
+ else:
223
+ response = ChatResponse(
224
+ thinking_process=thinking + f" تطوير بوت {bot_type} للعبة {game_name}.",
225
+ message=f"🚀 **بدء تطوير بوت {bot_type} للعبة {game_name}**\n\nجاري:\n• تصميم هيكل البوت\n• إعداد مكتبات الأتمتة\n• تطوير الخوارزميات الأساسية\n• إنشاء كود البوت الكامل",
226
+ actions=[
227
  {
228
+ "type": "develop_bot",
229
+ "description": f"تطوير بوت {bot_type} للعبة {game_name}",
230
+ "parameters": {
231
+ "game_name": game_name,
232
+ "bot_type": bot_type,
233
+ "features": ["auto_detection", "memory_control", "image_recognition", "screen_capture"]
234
+ }
235
+ },
236
+ {
237
+ "type": "install_tool",
238
+ "description": "تثبيت أدوات تطوير البوت",
239
+ "parameters": {
240
+ "tool_name": "python"
241
+ }
242
  }
243
  ]
244
+ )
245
+
246
+ return response
247
+
248
+ async def handle_screenshot(request: ChatRequest):
249
+ """معالجة طلب تصوير الشاشة"""
250
+ thinking = "🤔 **التفكير الاستراتيجي**: المستخدم يطلب تصوير شاشة جهازه. إعداد أمر التقاط الصورة."
251
+
252
+ response = ChatResponse(
253
+ thinking_process=thinking,
254
+ message="📸 **جاري التقاط صورة لشاشة جهازك...**\n\nسيتم حفظ الصورة في مجلد البوتات.",
255
+ actions=[
256
+ {
257
+ "type": "take_screenshot",
258
+ "description": "التقاط صورة للشاشة الحالية",
259
+ "parameters": {
260
+ "save_path": f"screenshots/screen_{datetime.now().strftime('%Y%m%d_%H%M%S')}.png"
261
+ }
262
+ }
263
+ ]
264
+ )
265
+ return response
266
+
267
+ async def handle_memory_scan(request: ChatRequest):
268
+ """معالجة طلب مسح الذاكرة"""
269
+ thinking = "🤔 **التفكير الاستراتيجي**: المستخدم يريد مسح ذاكرة لعبة. تحديد اسم العملية المستهدفة."
270
+
271
+ process_name = extract_process_name(request.message)
272
+
273
+ if not process_name:
274
  response = ChatResponse(
275
+ thinking_process=thinking + " لم يتم تحديد اسم العملية. طلب التوضيح.",
276
+ message="🎮 **مسح ذاكرة اللعبة**\n\nأخبرني اسم العملية أو اللعبة التي تريد مسح ذاكرتها:\n\nمثال: `GenshinImpact.exe` أو `Minecraft`",
277
+ actions=[]
278
  )
279
+ else:
280
+ response = ChatResponse(
281
+ thinking_process=thinking + f" مسح ذاكرة العملية: {process_name}",
282
+ message=f"🔍 **جاري مسح ذاكرة اللعبة**: {process_name}\n\nالبحث عن القيم القابلة للتعديل مثل المال، الصحة، الذخيرة...",
283
+ actions=[
284
+ {
285
+ "type": "scan_game_memory",
286
+ "description": f"مسح ذاكرة العملية {process_name}",
287
+ "parameters": {
288
+ "process_name": process_name,
289
+ "scan_for": ["money", "health", "ammo", "experience"]
290
+ }
291
+ }
292
+ ]
293
+ )
294
+
295
+ return response
296
+
297
+ async def handle_tool_installation(request: ChatRequest):
298
+ """معالجة طلب تثبيت الأدوات"""
299
+ thinking = "🤔 **التفكير الاستراتيجي**: المستخدم يريد تثبيت أداة. تحديد الأداة المطلوبة."
300
+
301
+ tool_name = extract_tool_name(request.message)
302
+
303
+ if not tool_name:
304
+ response = ChatResponse(
305
+ thinking_process=thinking + " لم يتم تحديد الأداة. عرض القائمة.",
306
+ message="🔧 **تثبيت الأدوات**\n\nالأدوات المتاحة:\n• cheatengine - أداة تعديل الذاكرة\n• python - لغة برمجة البوتات\n• ida - محلل التجميع\n• x64dbg - مصحح الأخطاء\n\nما الأداة التي تريد تثبيتها؟",
307
+ actions=[]
308
+ )
309
+ else:
310
+ response = ChatResponse(
311
+ thinking_process=thinking + f" تثبيت الأداة: {tool_name}",
312
+ message=f"📥 **جاري تثبيت الأداة**: {tool_name}\n\nسيتم تحضير البيئة اللازمة للعمل.",
313
+ actions=[
314
+ {
315
+ "type": "install_tool",
316
+ "description": f"تثبيت أداة {tool_name}",
317
+ "parameters": {
318
+ "tool_name": tool_name
319
+ }
320
+ }
321
+ ]
322
+ )
323
+
324
+ return response
325
+
326
+ async def handle_welcome(request: ChatRequest):
327
+ """معالجة رسالة الترحيب"""
328
+ thinking = "🤔 **التفكير الاستراتيجي**: المستخدم يرسل تحية. الترحيب به وعرض الميزات الحقيقية."
329
+
330
+ response = ChatResponse(
331
+ thinking_process=thinking,
332
+ message="🧠 **مرحباً بك في النظام الحقيقي المتكامل!**\n\n🚀 **الميزات الحقيقية الجاهزة للتنفيذ على جهازك:**\n\n• 🔍 **مسح شامل** للبرامج والعمليات\n• 🎮 **تحليل الذاكرة** للألعاب والتعديل\n• 🤖 **تطوير بوتات** كاملة وتجربتها\n• 🔬 **هندسة عكسية** متقدمة للملفات\n• 📸 **تصوير الشاشة** والتسجيل\n• ⚡ **تثبيت أدوات** متخصصة\n\n💡 **ما المهمة التي تريد البدء بها؟**",
333
+ actions=[
334
+ {
335
+ "type": "welcome",
336
+ "description": "ترحيب بالمستخدم وتحضير البيئة الحقيقية",
337
+ "parameters": {}
338
+ }
339
+ ]
340
+ )
341
+ return response
342
+
343
+ async def handle_general_request(request: ChatRequest):
344
+ """معالجة الطلبات العامة"""
345
+ thinking = "🤔 **التفكير الاستراتيجي**: تحليل الطلب العام للمستخدم وتحديد أفضل الإجراءات المناسبة."
346
+
347
+ response = ChatResponse(
348
+ thinking_process=thinking,
349
+ message="🧠 **فهمت طلبك!**\n\nسأقوم بمساعدتك في هذه المهمة باستخدام النظام الحقيقي المتكامل.\n\n💡 **جاري تحليل متطلباتك وإعداد الحل المناسب...**",
350
+ actions=[
351
+ {
352
+ "type": "general_analysis",
353
+ "description": "تحليل المهمة العامة وتحديد المتطلبات",
354
+ "parameters": {
355
+ "user_message": request.message,
356
+ "analysis_type": "comprehensive"
357
+ }
358
+ }
359
+ ]
360
+ )
361
+ return response
362
+
363
+ def extract_file_path(message: str) -> str:
364
+ """استخراج مسار الملف من الرسالة"""
365
+ # البحث عن أنماط المسارات في النص
366
+ patterns = [
367
+ r'[A-Z]:\\[^\s]+',
368
+ r'/[^\s]+',
369
+ r'~[^\s]+'
370
+ ]
371
+
372
+ for pattern in patterns:
373
+ matches = re.findall(pattern, message)
374
+ if matches:
375
+ return matches[0]
376
+
377
+ return ""
378
+
379
+ def extract_game_name(message: str) -> str:
380
+ """استخراج اسم اللعبة من الرسالة"""
381
+ games = ["Genshin Impact", "Minecraft", "Among Us", "VALORANT", "Overwatch", "Coven Kal", "Fortnite", "Cyberpunk", "Witcher"]
382
+
383
+ for game in games:
384
+ if game.lower() in message.lower():
385
+ return game
386
+
387
+ return ""
388
+
389
+ def extract_bot_type(message: str) -> str:
390
+ """استخراج نوع البوت من الرسالة"""
391
+ bot_types = {
392
+ "مزرعة": "farming",
393
+ "زراعة": "farming",
394
+ "قتال": "combat",
395
+ "قتل": "combat",
396
+ "تجارة": "trading",
397
+ "تلقائي": "auto",
398
+ "حماية": "defense"
399
+ }
400
+
401
+ for arabic_type, english_type in bot_types.items():
402
+ if arabic_type in message:
403
+ return english_type
404
+
405
+ if "farm" in message.lower():
406
+ return "farming"
407
+ elif "combat" in message.lower():
408
+ return "combat"
409
+ elif "trade" in message.lower():
410
+ return "trading"
411
+
412
+ return "auto"
413
+
414
+ def extract_process_name(message: str) -> str:
415
+ """استخراج اسم العملية من الرسالة"""
416
+ # البحث عن أسماء العمليات الشائعة
417
+ common_processes = ["GenshinImpact", "Minecraft", "AmongUs", "VALORANT", "Overwatch", "Fortnite"]
418
+
419
+ for process in common_processes:
420
+ if process.lower() in message.lower():
421
+ return process + ".exe"
422
+
423
+ # البحث عن نمط .exe في النص
424
+ exe_pattern = r'(\w+\.exe)'
425
+ matches = re.findall(exe_pattern, message, re.IGNORECASE)
426
+ if matches:
427
+ return matches[0]
428
+
429
+ return ""
430
+
431
+ def extract_tool_name(message: str) -> str:
432
+ """استخراج اسم الأداة من الرسالة"""
433
+ tools = {
434
+ "cheat engine": "cheatengine",
435
+ "cheatengine": "cheatengine",
436
+ "python": "python",
437
+ "ida": "ida",
438
+ "x64dbg": "x64dbg",
439
+ "process hacker": "processhacker",
440
+ "processhacker": "processhacker"
441
+ }
442
+
443
+ for tool_name, tool_id in tools.items():
444
+ if tool_name.lower() in message.lower():
445
+ return tool_id
446
+
447
+ return ""
448
 
449
  @app.post("/api/register-client")
450
  async def register_client(registration: ClientRegistration):