| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- import sys
- import os
- # Agregar el directorio padre al path para importar config
- sys.path.append(os.path.dirname(os.path.abspath(__file__)))
- from config import TARGET_PROCESS, UI_MESSAGES
- from core.memory_manager import MemoryManager
- from patterns.pattern_searcher import StaminaPatternSearcher
- from patches.patch_factory import PatchFactory
- from utils.helpers import HexDumper, BackupManager, UserInterface
- class AdvancedPatcher:
- """Clase principal del patcher que coordina todos los módulos (Facade Pattern)"""
-
- def __init__(self):
- self.memory_manager = MemoryManager()
- self.pattern_searcher = StaminaPatternSearcher()
- self.patch_factory = PatchFactory()
- self.hex_dumper = HexDumper()
- self.backup_manager = BackupManager(self.memory_manager)
- self.ui = UserInterface()
- self.target_process = TARGET_PROCESS['name']
-
- def apply_stamina_patch(self) -> bool:
- """Aplica el parche de stamina usando todos los módulos"""
- # Buscar y abrir el proceso
- if not self.memory_manager.open_process(self.target_process):
- print(UI_MESSAGES['error']['process_not_found'].format(process_name=self.target_process))
- return False
-
- print(UI_MESSAGES['info']['searching_stamina'])
-
- # Buscar patrones
- found_addresses = self.pattern_searcher.search(self.memory_manager)
-
- if not found_addresses:
- print(UI_MESSAGES['error']['no_patterns_found'])
- return False
-
- # Mostrar direcciones encontradas
- self.ui.print_found_addresses(found_addresses)
-
- # Seleccionar dirección objetivo
- target_address = self.ui.select_target_address(found_addresses)
-
- # Crear el parche
- patch = self.patch_factory.create_patch('stamina')
- if not patch:
- print("❌ No se pudo crear el parche de stamina")
- return False
-
- # Leer código original
- original_size = patch.get_patch_size()
- original_code = self.memory_manager.read_memory(target_address, original_size)
- if not original_code:
- print("❌ No se pudo leer el código original")
- return False
-
- # Crear backup
- self.backup_manager.backup_original_code(target_address, len(original_code))
-
- # Mostrar código original
- print(UI_MESSAGES['info']['original_code'])
- self.hex_dumper.print_hex_dump(original_code, target_address)
-
- # Generar datos del parche
- patch_data = patch.create_patch(original_code)
-
- # Mostrar código del parche
- print(UI_MESSAGES['info']['patch_to_apply'])
- self.hex_dumper.print_hex_dump(patch_data)
-
- # Confirmar aplicación
- if not self.ui.confirm_patch():
- print(UI_MESSAGES['error']['operation_cancelled'])
- return False
-
- # Aplicar el parche
- print(UI_MESSAGES['info']['applying_patch'])
- if self.memory_manager.write_memory(target_address, patch_data):
- print(UI_MESSAGES['success']['patch_applied'])
-
- # Verificar que el patch se escribió correctamente
- verification_data = self.memory_manager.read_memory(target_address, len(patch_data))
- if verification_data == patch_data:
- print(UI_MESSAGES['success']['verification_successful'])
- return True
- else:
- print(UI_MESSAGES['error']['verification_failed'])
- return False
- else:
- print(UI_MESSAGES['error']['patch_failed'])
- return False
-
- def cleanup(self):
- """Limpia los recursos utilizados"""
- self.memory_manager.close_process()
-
- def run(self) -> bool:
- """Ejecuta el proceso completo de patcheo"""
- print(UI_MESSAGES['info']['starting_patch_process'])
-
- success = False
- try:
- success = self.apply_stamina_patch()
- if success:
- print(UI_MESSAGES['success']['patching_completed'])
- print(UI_MESSAGES['success']['stamina_maintained'])
- else:
- print(UI_MESSAGES['error']['patching_failed'])
- except Exception as e:
- print(UI_MESSAGES['error']['patching_error'].format(error=e))
- finally:
- self.cleanup()
-
- return success
|