|
7 | 7 |
|
8 | 8 | from loguru import logger |
9 | 9 | 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 |
11 | 11 |
|
12 | 12 | from reai_toolkit.app.core.netstore_service import SimpleNetStore |
13 | 13 | from reai_toolkit.app.core.shared_schema import GenericApiReturn |
@@ -59,14 +59,24 @@ def _fetch_model_id(self, analysis_id: int) -> int: |
59 | 59 | model_name = analysis_details.data.model_name |
60 | 60 | self.safe_put_model_name_local(model_name=model_name) |
61 | 61 |
|
| 62 | + local_base_address: int = self._get_current_base_address() |
| 63 | + |
62 | 64 | 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) |
64 | 70 |
|
65 | 71 | return model_id |
66 | 72 |
|
| 73 | + @execute_read |
| 74 | + def _get_current_base_address(self) -> int: |
| 75 | + return idaapi.get_imagebase() |
| 76 | + |
67 | 77 | @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) |
70 | 80 |
|
71 | 81 | def _fetch_function_map(self, analysis_id: int) -> FunctionMapping: |
72 | 82 | """ |
@@ -100,21 +110,17 @@ def _match_functions( |
100 | 110 |
|
101 | 111 | # Track local functions matched |
102 | 112 | local_function_vaddrs_matched = set() |
103 | | - # print(inverse_function_map) |
104 | | - # FUN COUNT |
105 | 113 | fun_count = 0 |
106 | 114 | for key, value in func_map.name_map.items(): |
107 | 115 | if "FUN_" in value: |
108 | 116 | fun_count += 1 |
109 | 117 |
|
110 | | - # print(f"Function count with 'FUN_': {fun_count}") |
111 | | - # print(f"Inverse function map: {inverse_function_map}") |
112 | 118 | for start_ea in idautils.Functions(): |
113 | 119 | if str(start_ea) in inverse_function_map: |
114 | 120 | new_name: str | None = func_map.name_map.get(str(start_ea), None) |
115 | 121 | 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 | + |
118 | 124 | self.safe_set_name(start_ea, new_name, check_user_flags=True) |
119 | 125 | matched_functions.append( |
120 | 126 | (int(inverse_function_map[str(start_ea)]), start_ea) |
|
0 commit comments