diff --git a/ida-plugin.json b/ida-plugin.json index 64833c9..41b3d18 100644 --- a/ida-plugin.json +++ b/ida-plugin.json @@ -38,7 +38,7 @@ "requests==2.32.5", "loguru==0.7.3", "pydantic==2.12.3", - "revengai==4.75.0", + "revengai==4.77.1", "libbs==3.8.1" ] } diff --git a/reai_toolkit/app/coordinators/detach_coordinator.py b/reai_toolkit/app/coordinators/detach_coordinator.py index a56f8e2..71d20d3 100644 --- a/reai_toolkit/app/coordinators/detach_coordinator.py +++ b/reai_toolkit/app/coordinators/detach_coordinator.py @@ -43,7 +43,7 @@ def run_dialog(self) -> None: result = msg.exec_() if result == QtWidgets.QMessageBox.Ok: - self.log.info("RevEng.AI: Detaching analysis.") + self.log.info("Detaching analysis.") self._detach_analysis() def is_authed(self) -> bool: diff --git a/reai_toolkit/app/core/logging_setup.py b/reai_toolkit/app/core/logging_setup.py index 6bc0d55..137d56d 100644 --- a/reai_toolkit/app/core/logging_setup.py +++ b/reai_toolkit/app/core/logging_setup.py @@ -3,10 +3,24 @@ from loguru import logger +# IDA's output window already prepends a timestamp, so skip loguru's own. +_COMPACT = "[RevEng.AI] {message}\n{exception}" +_LEVELED = "[RevEng.AI] {level}: {message}\n{exception}" +_DEBUG = "[RevEng.AI] {level} {name}:{function}:{line} - {message}\n{exception}" + + +def _format(record) -> str: + level = record["level"].no + if level >= 30: + return _LEVELED + if level <= 10: + return _DEBUG + return _COMPACT + def configure_logging() -> None: level = os.environ.get("REAI_LOG_LEVEL") if not level: level = "DEBUG" if os.environ.get("REAI_DEBUG") == "1" else "INFO" logger.remove() - logger.add(sys.stderr, level=level.upper()) + logger.add(sys.stderr, level=level.upper(), format=_format) diff --git a/reai_toolkit/app/services/ai_decomp/ai_decomp_service.py b/reai_toolkit/app/services/ai_decomp/ai_decomp_service.py index 43ffe6d..1d63096 100644 --- a/reai_toolkit/app/services/ai_decomp/ai_decomp_service.py +++ b/reai_toolkit/app/services/ai_decomp/ai_decomp_service.py @@ -400,7 +400,7 @@ def _run_task( if on_attributions is not None: self._run_attribution_phase(function_id, stop_event, on_attributions) except Exception as e: - logger.error(f"RevEng.AI: AI decompilation task crashed for {function_id}: {e}") + logger.error(f"AI decompilation task crashed for {function_id}: {e}") finally: with self._inflight_lock: if self._inflight.get(function_id) is stop_event: diff --git a/reai_toolkit/app/services/analysis_status/analysis_status.py b/reai_toolkit/app/services/analysis_status/analysis_status.py index fcb1e06..cdb4725 100644 --- a/reai_toolkit/app/services/analysis_status/analysis_status.py +++ b/reai_toolkit/app/services/analysis_status/analysis_status.py @@ -86,7 +86,7 @@ def _poll_analysis_status(self, stop_event: threading.Event, analysis_id: int) - logger.debug(f"RevEng.AI Remote Analysis - {entry.text}") if get_status_response.data and (status := get_status_response.data.status): - logger.info(f"RevEng.AI: Status - {status}") + logger.info(f"Status - {status}") if status == "Complete": self.call_callback( generic_return=GenericApiReturn( diff --git a/reai_toolkit/app/services/analysis_sync/analysis_sync.py b/reai_toolkit/app/services/analysis_sync/analysis_sync.py index 82bdfb4..9912468 100644 --- a/reai_toolkit/app/services/analysis_sync/analysis_sync.py +++ b/reai_toolkit/app/services/analysis_sync/analysis_sync.py @@ -141,7 +141,7 @@ def _perform_function_sync( int(addr): int(fid) for fid, addr in func_map.function_map.items() } - logger.info(f"RevEng.AI: Retrieved {len(local_vaddr_to_matched_name)} functions from analysis") + logger.info(f"Retrieved {len(local_vaddr_to_matched_name)} functions from analysis") matched_function_count: int = 0 unmatched_function_count: int = 0 @@ -186,9 +186,9 @@ def _perform_function_sync( total_function_count += 1 - logger.info(f"RevEng.AI: Matched {matched_function_count} functions") - logger.info(f"RevEng.AI: {unmatched_function_count} functions not matched") - logger.info(f"RevEng.AI: {missing_symbol_name_count} functions with missing symbol names") + logger.info(f"Matched {matched_function_count} functions") + logger.info(f"{unmatched_function_count} functions not matched") + logger.info(f"{missing_symbol_name_count} functions with missing symbol names") summary: MatchedFunctionSummary = MatchedFunctionSummary( matched_function_count=matched_function_count, @@ -205,7 +205,7 @@ def _match_functions( try: return self._perform_function_sync(func_map=func_map) except Exception as e: - logger.error(f"RevEng.AI: Exception during function sync: {e}") + logger.error(f"Exception during function sync: {e}") return ( GenericApiReturn(success=False, error_message=f"Exception during function sync: {e}"), [], diff --git a/reai_toolkit/app/services/auth/auth_service.py b/reai_toolkit/app/services/auth/auth_service.py index 872b2fd..6ec3f8b 100644 --- a/reai_toolkit/app/services/auth/auth_service.py +++ b/reai_toolkit/app/services/auth/auth_service.py @@ -86,7 +86,7 @@ def verify(self) -> Tuple[bool, str]: api_client.user_agent = self.sdk_config.user_agent try: ConfigApi(api_client).v3_get_config() - logger.info("RevEng.AI: User authenticated successfully.") + logger.debug("User authenticated successfully.") self._is_authed = True self.get_me(force_refresh=True) return True, "" @@ -114,7 +114,7 @@ def verify(self) -> Tuple[bool, str]: except Exception as e: self._is_authed = False - logger.error(f"RevEng.AI: Authentication failed. Unexpected Error: {e}") + logger.error(f"Authentication failed. Unexpected Error: {e}") return False, f"Unexpected Error: {e}" def is_authenticated(self) -> bool: @@ -146,7 +146,7 @@ def get_me(self, force_refresh: bool = False) -> User | None: except ValidationError: self._user = self._get_me_unvalidated(api_client) except Exception as e: - logger.error(f"RevEng.AI: Failed to fetch current user: {e}") + logger.error(f"Failed to fetch current user: {e}") self._user = None return self._user @@ -162,7 +162,7 @@ def _get_me_unvalidated(api_client: ApiClient) -> User | None: return None return User.model_construct(**json.loads(response.data)) except Exception as e: - logger.error(f"RevEng.AI: Failed to fetch current user: {e}") + logger.error(f"Failed to fetch current user: {e}") return None def is_enthusiast(self) -> bool: diff --git a/reai_toolkit/app/services/auto_unstrip_status/auto_unstrip_status.py b/reai_toolkit/app/services/auto_unstrip_status/auto_unstrip_status.py index a988e1b..e36c3b3 100644 --- a/reai_toolkit/app/services/auto_unstrip_status/auto_unstrip_status.py +++ b/reai_toolkit/app/services/auto_unstrip_status/auto_unstrip_status.py @@ -61,7 +61,7 @@ def _poll_auto_unstrip_status( return status: str | None = status_response.data - logger.info(f"RevEng.AI: Auto-unstrip status - {status}") + logger.info(f"Auto-unstrip status - {status}") if status == STATUS_COMPLETED: if first_poll and not resync_if_already_complete: diff --git a/reai_toolkit/app/services/data_types/analysis_catalogue.py b/reai_toolkit/app/services/data_types/analysis_catalogue.py index fd1fe02..3129e6e 100644 --- a/reai_toolkit/app/services/data_types/analysis_catalogue.py +++ b/reai_toolkit/app/services/data_types/analysis_catalogue.py @@ -139,12 +139,12 @@ def sync(self, analysis_id: int) -> Catalogue: offset += len(items) else: logger.warning( - f"RevEng.AI: stopped paging analysis {analysis_id} data types at {MAX_PAGES} pages" + f"stopped paging analysis {analysis_id} data types at {MAX_PAGES} pages" ) catalogue = Catalogue.of(entries) self._cache[analysis_id] = catalogue - logger.debug(f"RevEng.AI: analysis {analysis_id} holds {len(catalogue)} data types") + logger.debug(f"analysis {analysis_id} holds {len(catalogue)} data types") return catalogue def resolve(self, analysis_id: int, type_name: Optional[str]) -> Optional[int]: diff --git a/reai_toolkit/app/services/data_types/data_types_service.py b/reai_toolkit/app/services/data_types/data_types_service.py index cd0751b..09b0ca3 100644 --- a/reai_toolkit/app/services/data_types/data_types_service.py +++ b/reai_toolkit/app/services/data_types/data_types_service.py @@ -36,7 +36,7 @@ def import_data_types_async(self, matches: dict[int, int]) -> None: def _import_worker(self, _: threading.Event, matches: dict[int, int]) -> None: result: DataTypesImportResult = self.import_data_types(matches) if result.error: - logger.error(f"RevEng.AI: {result.error}") + logger.error(f"{result.error}") def import_data_types(self, matches: dict[int, int]) -> DataTypesImportResult: if len(matches) == 0: @@ -51,10 +51,10 @@ def import_data_types(self, matches: dict[int, int]) -> DataTypesImportResult: logger.warning(f"failed to apply data types for {len(matched_function_ids)} functions: {e}") return DataTypesImportResult(remote_absent_ids=set(matched_function_ids)) except ApiException as e: - logger.error(f"RevEng.AI: failed to sync function data types: HTTP {e.status} {e.reason}") + logger.error(f"failed to sync function data types: HTTP {e.status} {e.reason}") return DataTypesImportResult(error=f"Failed to sync function data types: HTTP {e.status} {e.reason}") except Exception as e: - logger.error(f"RevEng.AI: failed to sync function data types: {e}") + logger.error(f"failed to sync function data types: {e}") return DataTypesImportResult(error=f"Failed to sync function data types: {e}") present_ids: set[int] = ( diff --git a/reai_toolkit/app/services/rename/rename_service.py b/reai_toolkit/app/services/rename/rename_service.py index 2da57ee..765c908 100644 --- a/reai_toolkit/app/services/rename/rename_service.py +++ b/reai_toolkit/app/services/rename/rename_service.py @@ -94,7 +94,7 @@ def _rename_worker(self, stop_event: Optional[threading.Event] = None) -> None: try: total_errors = self._rename_function(function_list=function_list) except Exception as e: - logger.error(f"RevEng.AI: failed to rename functions: {e}") + logger.error(f"failed to rename functions: {e}") total_errors = len(function_list) if total_errors == 0: break @@ -190,7 +190,7 @@ def _rename_remote_function( status=False, server_error=bool(e.status and e.status >= 500) ) except Exception as e: - logger.error(f"RevEng.AI: failed to rename functions remotely: {e}") + logger.error(f"failed to rename functions remotely: {e}") return RemoteRenameOutcome(status=False) return RemoteRenameOutcome( @@ -230,7 +230,7 @@ def canonicalize_names(self, names: list[str]) -> dict[str, str]: canonicalize_names_input_body=CanonicalizeNamesInputBody(names=chunk) ) except Exception as e: - logger.error(f"RevEng.AI: failed to canonicalize names: {e}") + logger.error(f"failed to canonicalize names: {e}") continue for result in (out.results or []): diff --git a/reai_toolkit/app/services/upload/upload_service.py b/reai_toolkit/app/services/upload/upload_service.py index 205c092..82b0272 100644 --- a/reai_toolkit/app/services/upload/upload_service.py +++ b/reai_toolkit/app/services/upload/upload_service.py @@ -98,7 +98,7 @@ def analyse_file( ) if upload_response.success: - logger.info("RevEng.AI: Uploaded binary file") + logger.info("Uploaded binary file") else: self.call_callback(generic_return=upload_response) return @@ -111,7 +111,7 @@ def analyse_file( ) if upload_response.success: - logger.info("RevEng.AI: Uploaded debug file") + logger.info("Uploaded debug file") else: logger.error( f"RevEng.AI: Failed to upload binary file: {upload_response.error_message}" @@ -211,7 +211,7 @@ def analyse( logger.info( f"RevEng.AI: Collected {len(symbols.function_boundaries)} functions from IDA" ) - logger.info(f"RevEng.AI: Base address: 0x{symbols.base_address:X}") + logger.info(f"Base address: 0x{symbols.base_address:X}") analysis_create_request = AnalysisCreateRequest( filename=file_name, diff --git a/reai_toolkit/app/services/variable_sync/variable_sync_service.py b/reai_toolkit/app/services/variable_sync/variable_sync_service.py index ddb9f45..8c4cfe9 100644 --- a/reai_toolkit/app/services/variable_sync/variable_sync_service.py +++ b/reai_toolkit/app/services/variable_sync/variable_sync_service.py @@ -35,7 +35,7 @@ def _read_decompiler_function(deci, func_addr: int): else: func = read_ida_function(lowered, decompiler_available=False) except Exception as e: - logger.debug(f"RevEng.AI: could not read function at 0x{lowered:x}: {e}") + logger.debug(f"could not read function at 0x{lowered:x}: {e}") return None return deci.art_lifter.lift(func) if func is not None else None @@ -79,9 +79,9 @@ def enqueue_change(self, function_id: int, func_addr: int, artifact: object) -> last = self._last_ts.get(key, 0.0) self._last_ts[key] = now if (now - last) * 1000.0 <= self._debounce_ms: - logger.debug(f"RevEng.AI: debounced data types change for function {function_id}") + logger.debug(f"debounced data types change for function {function_id}") return - logger.debug(f"RevEng.AI: queued data types change for function {function_id}") + logger.debug(f"queued data types change for function {function_id}") self._q.put((function_id, func_addr, artifact)) self._start_worker_if_needed() @@ -106,17 +106,17 @@ def _worker(self, stop_event: Optional[threading.Event] = None) -> None: try: self._push_change(function_id, func_addr) except ApiException as e: - logger.error(f"RevEng.AI: failed to push data types: HTTP {e.status} {e.reason}") + logger.error(f"failed to push data types: HTTP {e.status} {e.reason}") except Exception as e: - logger.error(f"RevEng.AI: failed to push data types: {e}") + logger.error(f"failed to push data types: {e}") finally: self._q.task_done() def _push_change(self, function_id: int, func_addr: int) -> None: - logger.debug(f"RevEng.AI: processing data types change for function {function_id}") + logger.debug(f"processing data types change for function {function_id}") analysis_id: int | None = self.netstore_service.get_analysis_id() if analysis_id is None: - logger.debug("RevEng.AI: no analysis id; skipping data types push") + logger.debug("no analysis id; skipping data types push") return signature = self._build_signature(analysis_id, func_addr) @@ -127,7 +127,7 @@ def _push_change(self, function_id: int, func_addr: int) -> None: return if self._put_signature(analysis_id, function_id, signature): - logger.info(f"RevEng.AI: pushed data types for function {function_id}") + logger.info(f"pushed data types for function {function_id}") def _build_signature(self, analysis_id: int, func_addr: int) -> Optional[dict]: if self._deci is None: @@ -231,7 +231,7 @@ def push_local_function_types_batch(self, targets: dict[int, int], analysis_id: self.attach_decompiler(DecompilerInterface.discover(force_decompiler="ida")) except Exception as e: - logger.error(f"RevEng.AI: could not attach decompiler for type push-back: {e}") + logger.error(f"could not attach decompiler for type push-back: {e}") return 0 base: int = self._deci.binary_base_addr @@ -240,7 +240,7 @@ def push_local_function_types_batch(self, targets: dict[int, int], analysis_id: try: signature = self._build_signature(analysis_id, ea - base) except Exception as e: - logger.debug(f"RevEng.AI: could not build local types for function {function_id}: {e}") + logger.debug(f"could not build local types for function {function_id}: {e}") continue if signature is None: continue diff --git a/reai_toolkit/app/transformations/import_data_types.py b/reai_toolkit/app/transformations/import_data_types.py index e90c41d..84588e2 100644 --- a/reai_toolkit/app/transformations/import_data_types.py +++ b/reai_toolkit/app/transformations/import_data_types.py @@ -224,7 +224,7 @@ def execute( def _install_primitives() -> None: declared = install_ghidra_primitives() if declared: - logger.info(f"RevEng.AI: declared {declared} Ghidra primitive type(s)") + logger.info(f"declared {declared} Ghidra primitive type(s)") @staticmethod def _prototype(item: dict, resolver: _TypeResolver) -> Optional[_Prototype]: @@ -270,7 +270,7 @@ def _apply_dependencies(self, artifacts: dict[str, Any]) -> None: try: self.apply_dependency(artifact) except Exception as e: - logger.warning(f"RevEng.AI: skipped dependency {name!r}: {e!r}") + logger.warning(f"skipped dependency {name!r}: {e!r}") def apply_dependency(self, artifact: Any) -> None: if self.deci is None: diff --git a/reai_toolkit/hooks/artifacts.py b/reai_toolkit/hooks/artifacts.py index 6f2109c..31d1851 100644 --- a/reai_toolkit/hooks/artifacts.py +++ b/reai_toolkit/hooks/artifacts.py @@ -30,7 +30,7 @@ def start(self) -> bool: return False self._deci = deci self.app.variable_sync_service.attach_decompiler(deci) - logger.info("[ArtifactChangeHooks] Hook registered.") + logger.debug("[ArtifactChangeHooks] Hook registered.") return True def stop(self) -> None: diff --git a/reai_toolkit_entry.py b/reai_toolkit_entry.py index 158280d..4c9cdc4 100644 --- a/reai_toolkit_entry.py +++ b/reai_toolkit_entry.py @@ -32,8 +32,12 @@ def _add_vendor_paths(): # flake8: noqa: E402 from loguru import logger -from reai_toolkit.app.app import App from reai_toolkit.app.core.logging_setup import configure_logging + +# Must run before the imports below, which log at import time. +configure_logging() + +from reai_toolkit.app.app import App from reai_toolkit.app.coordinator import Coordinator from reai_toolkit.app.factory import DialogFactory from reai_toolkit.hooks.artifacts import ArtifactChangeHooks @@ -71,7 +75,6 @@ def __init__(self): self._setup_handled = False def init(self): - configure_logging() self.app = App(__IDA_VERSION__, __PLUGIN_VERSION__) self.factory = DialogFactory(self.app) self.coordinator = Coordinator(app=self.app, factory=self.factory, log=logger) @@ -95,8 +98,6 @@ def init(self): self._ui_hooks.ready_to_run = self._on_ui_ready self._ui_hooks.hook() - # ida_kernwin.msg("[REAI] init() called, waiting for DB or UI ready...\n") - # Fallback timer in case the events are missed idaapi.register_timer(1000, lambda: (self._show_setup_if_needed(), -1)[1]) idaapi.register_timer(1500, self._artifact_hook_timer) @@ -110,14 +111,12 @@ def _artifact_hook_timer(self) -> int: return -1 if self._artifact_start_attempts >= 30 else 1000 def _on_idb_loaded(self, is_new_database, idc_script): - ida_kernwin.msg( - f"[REAI] _on_idb_loaded is_new={is_new_database} script={idc_script}\n" - ) + logger.debug(f"idb loaded (is_new={is_new_database}, script={idc_script})") self._show_setup_if_needed() return 0 def _on_ui_ready(self): - ida_kernwin.msg("[REAI] _on_ui_ready triggered\n") + logger.debug("UI ready") self._show_setup_if_needed() self.coordinator.refresh_disassembly_view() if self._artifact_hooks is not None: @@ -128,10 +127,8 @@ def _show_setup_if_needed(self): return self._setup_handled = True - ida_kernwin.msg("[REAI] _show_setup_if_needed called\n") self.app.auth_service.verify() if self.app.auth_service.is_authenticated(): - ida_kernwin.msg("[REAI] SDK config is valid, no dialog.\n") ida_kernwin.refresh_idaview_anyway() return @@ -147,7 +144,7 @@ def run(self, arg): # not used def term(self): if self._artifact_hooks is not None: self._artifact_hooks.stop() - ida_kernwin.msg("[REAI] term.\n") + logger.debug("plugin terminated") def PLUGIN_ENTRY():