Skip to content

Commit

Permalink
Fix logging in decompiler mode (#7)
Browse files Browse the repository at this point in the history
* Fix logging in decompiler mode

* Kill the old packaging system

* Update angr management
  • Loading branch information
mahaloz authored Dec 28, 2023
1 parent 1b09b45 commit 69be3f6
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 46 deletions.
41 changes: 0 additions & 41 deletions pyproject.toml

This file was deleted.

28 changes: 28 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[metadata]
name = varbert
version = attr: varbert.__version__
url = https://github.com/binsync/varbert_api
classifiers =
License :: OSI Approved :: BSD License
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
license = BSD 2 Clause
license_files = LICENSE
description = The VarBERT API for renaming variables in decompiled code.
long_description = file: README.md
long_description_content_type = text/markdown

[options]
install_requires =
torch
transformers
tqdm
dailalib
libbs>=0.9.0

python_requires = >= 3.8
packages = find:

[options.entry_points]
console_scripts =
varbert = varbert.__main__:main
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from setuptools import setup

setup()
2 changes: 1 addition & 1 deletion varbert/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.0.4"
__version__ = "2.0.5"

import importlib.resources
import tarfile
Expand Down
30 changes: 26 additions & 4 deletions varbert/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ def predict_variable_names(
:param remove_bad_names: Removes names that are duplicates or decompiler generated
:return: (dict of old name to new name, renamed code)
"""
self.info(f"Predicting for function {function}...")
# sanity checks
if function is None and decompilation_text is None:
raise ValueError("Must provide either a Function or decompilation text.")
if function:
if not function.args and not function.stack_vars:
_l.debug(f"{function} has no arguments or stack variables to predict names for.")
self.debug(f"{function} has no arguments or stack variables to predict names for.")
return {}, ""
if function.size < self._min_func_size:
_l.debug(f"{function} is smaller than min size of {self._min_func_size} bytes.")
self.debug(f"{function} is smaller than min size of {self._min_func_size} bytes.")
return {}, ""
# can be None because of the delay init
if self._model_interface is None:
Expand All @@ -76,7 +77,7 @@ def predict_variable_names(
predict_for_decompiler_generated_vars=False
)
if not orig_name_2_popular_name:
_l.warning(f"Unable to predict any names for function {function}")
self.warning(f"Unable to predict any names for function {function}")

if remove_bad_names:
name_pairs = list()
Expand All @@ -93,7 +94,7 @@ def predict_variable_names(
}

# check after filtering
_l.info(f"Predicted {len(orig_name_2_popular_name)} new names for function {function}")
self.info(f"Predicted {len(orig_name_2_popular_name)} new names for function {function}")
return orig_name_2_popular_name, renamed_code

@AIAPI.requires_function
Expand Down Expand Up @@ -136,3 +137,24 @@ def predict_for_functions(func_addrs: Optional[List[int]] = None, decompiler: Op
# make sure things are destroyed
del varbert, dec_interface

#
# special printers for decompiler proxying (if available)
#

def info(self, msg):
if self._dec_interface:
self._dec_interface.info(msg)
else:
_l.info(msg)

def debug(self, msg):
if self._dec_interface:
self._dec_interface.debug(msg)
else:
_l.debug(msg)

def warning(self, msg):
if self._dec_interface:
self._dec_interface.warning(msg)
else:
_l.warning(msg)

0 comments on commit 69be3f6

Please sign in to comment.