Skip to content

Commit acb1b42

Browse files
authored
Fix new LibBS decompiler interface (#12)
* Fix new decomp interface * bump * bump libbs version for copy fix
1 parent 62c543c commit acb1b42

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ install_requires =
1818
transformers
1919
tqdm
2020
dailalib
21-
libbs
21+
libbs>=1.18.1
2222

2323
python_requires = >= 3.8
2424
packages = find:

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.0"
1+
__version__ = "2.2.1"
22

33
import importlib.resources
44
import tarfile

varbert/api.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def __init__(self, **kwargs):
2020
) if not self._delay_init else None
2121

2222
def predict_variable_names(
23-
self, function: Function = None, decompilation_text: Optional[str] = None, use_decompiler=True,
24-
remove_bad_names=True
23+
self, function: Function = None, decompilation_text: Optional[str] = None, use_decompiler=True,
24+
remove_bad_names=True, **kwargs
2525
) -> Tuple[Dict[str, str], str]:
2626
"""
2727
Predict variable names for a function or decompilation text. You can use this function in two ways:
@@ -61,7 +61,10 @@ def predict_variable_names(
6161
if not use_decompiler:
6262
raise ValueError("Must provide decompilation text if not using decompiler")
6363

64-
decompilation_text = self._dec_interface.decompile(function.addr)
64+
decomp = self._dec_interface.decompile(function.addr)
65+
if decomp is None or not decomp.text:
66+
raise ValueError(f"Unable to decompile function {function}")
67+
decompilation_text = decomp.text
6568

6669
# preprocess text for training
6770
preprocessor = DecompilationTextProcessor(

varbert/text_processor.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ def _process_code_with_decompiler(self):
8989
# replace all original names with tmp tokenized names
9090
self._decompiler.rename_local_variables_by_names(self._func, og_name_to_tokenized_name)
9191
# get the decomp, fix the tmp tokens
92-
tokenized_dec_text = self._decompiler.decompile(self._func.addr)
92+
tokenized_decomp = self._decompiler.decompile(self._func.addr)
93+
if tokenized_decomp is None:
94+
_l.error("Decompiler failed to decompile function.")
95+
return
96+
97+
tokenized_dec_text = tokenized_decomp.text
9398
tokenized_dec_text = tokenized_dec_text.replace(tmp_token, "@@")
9499

95100
# revert to the original names in the decomp

0 commit comments

Comments
 (0)