Skip to content

Commit 1e6a85b

Browse files
authored
Allow renaming of functions without stack or parameters (#13)
* Allow renaming of functions without stack or parameters * return on failure
1 parent acb1b42 commit 1e6a85b

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

varbert/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "2.2.1"
1+
__version__ = "2.3.0"
22

33
import importlib.resources
44
import tarfile

varbert/api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,8 @@ def predict_variable_names(
4747
if function is None and decompilation_text is None:
4848
raise ValueError("Must provide either a Function or decompilation text.")
4949
if function:
50-
if not function.args and not function.stack_vars:
51-
self.debug(f"{function} has no arguments or stack variables to predict names for.")
52-
return {}, ""
5350
if function.size < self._min_func_size:
54-
self.debug(f"{function} is smaller than min size of {self._min_func_size} bytes.")
51+
self.error(f"{function} is smaller than min size of {self._min_func_size} bytes.")
5552
return {}, ""
5653
# can be None because of the delay init
5754
if self._model_interface is None:
@@ -70,6 +67,9 @@ def predict_variable_names(
7067
preprocessor = DecompilationTextProcessor(
7168
decompilation_text, func=function, decompiler=self._dec_interface if use_decompiler else None
7269
)
70+
if preprocessor.failed:
71+
return {}, ""
72+
7373
processed_code, func_args = preprocessor.processed_code, preprocessor.func_args
7474
scores, score_origins = self._model_interface.process(processed_code)
7575
if scores is None:

varbert/text_processor.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def __init__(self, raw_code, func: Optional[Function] = None, decompiler: Option
1919
self._decompiler = decompiler
2020
self._func = func
2121

22+
self.failed = False
23+
2224
# updated in process_code
2325
self.processed_code = raw_code
2426
# TODO: this actually needs to be disabled for now because Function does not handle register variables
@@ -83,6 +85,11 @@ def _process_code_with_decompiler(self):
8385
# refresh the decompiled obj backend
8486
self._func.dec_obj = self._decompiler.get_decompilation_object(self._func)
8587
original_names = self._decompiler.local_variable_names(self._func)
88+
if not original_names:
89+
self._decompiler.error(f"No variable names (local or args) found in decompiled function {self._func} for renaming.")
90+
self.failed = True
91+
return
92+
8693
og_name_to_tokenized_name = self._tokenize_names(original_names, token=tmp_token)
8794
tokenized_name_to_og_name = {v: k for k, v in og_name_to_tokenized_name.items()}
8895

0 commit comments

Comments
 (0)