Skip to content

Commit 2f51e61

Browse files
authored
Merge pull request #85 from RevEngAI/fix-PLU-200-incorrect-rebase-on-sync
fix(PLU-200) rebase miscalculation and reserved prefix warning
2 parents f13dad2 + 2988d42 commit 2f51e61

2 files changed

Lines changed: 19 additions & 11 deletions

File tree

reai_toolkit/app/interfaces/base_service.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,11 @@ def _do():
189189
pass
190190

191191
# Prefer setting sync names as AUTO so users can easily override them later.
192+
# https://python.docs.hex-rays.com/ida_name/index.html#ida_name.set_name
192193
# SN_CHECK: check for validity
193194
# SN_AUTO: mark as auto-generated name
194-
flags = ida_name.SN_CHECK | ida_name.SN_AUTO
195+
# SN_NODUMMY: Prevents warning "can't rename byte as '<func_name>' because the name has a reserved prefix".
196+
flags = ida_name.SN_CHECK | ida_name.SN_AUTO | ida_name.SN_NODUMMY
195197
result["ok"] = bool(ida_name.set_name(ea, new_name, flags))
196198

197199
# hop to UI thread, make it a write transaction

reai_toolkit/app/services/analysis_sync/analysis_sync.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from loguru import logger
99
from revengai import AnalysesCoreApi, Configuration, FunctionMapping
10-
from libbs.decompilers.ida.compat import execute_write
10+
from libbs.decompilers.ida.compat import execute_write, execute_read
1111

1212
from reai_toolkit.app.core.netstore_service import SimpleNetStore
1313
from reai_toolkit.app.core.shared_schema import GenericApiReturn
@@ -59,14 +59,24 @@ def _fetch_model_id(self, analysis_id: int) -> int:
5959
model_name = analysis_details.data.model_name
6060
self.safe_put_model_name_local(model_name=model_name)
6161

62+
local_base_address: int = self._get_current_base_address()
63+
6264
if analysis_details.data and analysis_details.data.base_address is not None:
63-
self._rebase_program(analysis_details.data.base_address)
65+
remote_base_address: int = analysis_details.data.base_address
66+
67+
if local_base_address != remote_base_address:
68+
base_address_delta: int = remote_base_address - local_base_address
69+
self._rebase_program(base_address_delta)
6470

6571
return model_id
6672

73+
@execute_read
74+
def _get_current_base_address(self) -> int:
75+
return idaapi.get_imagebase()
76+
6777
@execute_write
68-
def _rebase_program(self, base_address: int) -> None:
69-
idaapi.rebase_program(base_address, idaapi.MSF_FIXONCE)
78+
def _rebase_program(self, base_address_delta: int) -> None:
79+
idaapi.rebase_program(base_address_delta, idaapi.MSF_FIXONCE)
7080

7181
def _fetch_function_map(self, analysis_id: int) -> FunctionMapping:
7282
"""
@@ -100,21 +110,17 @@ def _match_functions(
100110

101111
# Track local functions matched
102112
local_function_vaddrs_matched = set()
103-
# print(inverse_function_map)
104-
# FUN COUNT
105113
fun_count = 0
106114
for key, value in func_map.name_map.items():
107115
if "FUN_" in value:
108116
fun_count += 1
109117

110-
# print(f"Function count with 'FUN_': {fun_count}")
111-
# print(f"Inverse function map: {inverse_function_map}")
112118
for start_ea in idautils.Functions():
113119
if str(start_ea) in inverse_function_map:
114120
new_name: str | None = func_map.name_map.get(str(start_ea), None)
115121
if new_name is None:
116-
return False
117-
# logger.info(f"RevEng.AI: Renaming function at {start_ea} to {new_name}")
122+
continue
123+
118124
self.safe_set_name(start_ea, new_name, check_user_flags=True)
119125
matched_functions.append(
120126
(int(inverse_function_map[str(start_ea)]), start_ea)

0 commit comments

Comments
 (0)