Skip to main content

VarBERT API

The VarBERT API is a Python library to access and use the latest models from the S&P 2024 work ""Len or index or count, anything but v1": Predicting Variable Names in Decompilation Output with Transfer Learning", featuring VarBERT. VarBERT is a BERT-based model that predicts variable names for decompiled code. To train new models and understand the pipeline, see the VarBERT paper repo. Specialized models exist for IDA Pro and Ghidra, but can be used on any decompiler.

DAILA context menu

The main focus of this project is to provide an library API and CLI access to VarBERT models, but, it has been designed to be used in decompiler directly using the DAILA project. DAILA comes with the VarBERT API bundled, so you do not need to install VarBERT if you are using DAILA.

Install

pip3 install varbert && varbert --download-models

This will install the VarBERT API library and download the models to be stored inside the VarBERT package. You can optionally provide a decompiler name to --download-models to only download the models for that decompiler.

Usage

The VarBERT API can be used in three ways:

  • From the CLI, directly on decompiled text (without an attached decompiler)
  • As a scripting library
  • As a decompiler plugin (using DALIA)

Command Line (without running a decompiler)

Note that VarBERT runs better when it is directly hooked up to a decompiler because it can use additional semantic information that the decompiler knows about the decompiled code. However, we do have the ability to run VarBERT without a running decompiler, only operating on the text from the command line.

Running the following will cause VarBERT to read a function from standard input and output the function with predicted variable names to standard out:

varbert --predict --decompiler ida

You can select different decompilers that will use different models that are trained on the different decompilers. If you do not specify a decompiler, the default is IDA Pro. As an example, you can also give no decompiler:

 echo "__int64 sub_400664(char *a1,char *a2)\n {}" | varbert -p

Scripting

Without Decompiler

from varbert import VariableRenamingAPI
api = VariableRenamingAPI(decompiler_name="ida", use_decompiler=False)
new_names, new_code = api.predict_variable_names(decompilation_text="__int64 sub_400664(char *a1,char *a2)\n {}", use_decompiler=False)
print(new_code)

You can also find more examples in the tests.py file.

Inside Decompiler

You can use VarBERT as a scripting library inside your decompiler, utilizing LibBS.

from varbert import VariableRenamingAPI
from libbs.api import DecompilerInterface
dec = DecompilerInterface()
api = VariableRenamingAPI(decompiler_interface=dec)
for func_addr in dec.functions:
    new_names, new_code = api.predict_variable_names(function=dec.functions[func_addr])
    print(new_names)

As a Decompiler Plugin

If you would like to use VarBERT as a decompiler plugin, you can use DAILA. You should follow the instructions on the DAILA repo to install DAILA, but it's generally as simple as:

pip3 install dailalib && daila --install

You can find a demo of VarBERT running inside DAILA below:

VarBERT Demo

Citing

If you use VarBERT in your research, please cite our paper:

TODO

Release files for varbert 2.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for varbert 2.3.1
File Size Uploaded
varbert-2.3.1.tar.gz 20.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for varbert 2.3.1
File Interpreter ABI Platform
varbert-2.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 37.6 kB

Release files / varbert-2.3.1.tar.gz

Download URL varbert-2.3.1.tar.gz
Size 20.1 kB
Tags Source
SHA-256 checksum
How to use checksums
ac57efea4075483e9cb4734e32622317798feb35df5f2577bf1d3b66fabfd203
BLAKE2b-256 checksum
How to use checksums
65f7833a542e08264c7904871fb9f4491fb4791b49d1a23fbf212291bc9905ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / varbert-2.3.1-py3-none-any.whl

Download URL varbert-2.3.1-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e8383e6336c6ac39fdf4fd44dbc9ca0af8bfcedec5af99dc6c955d9f7a8f996c
BLAKE2b-256 checksum
How to use checksums
d1711f7b0ee09a72f9ccd3ab562cdff2cfa0f9890221b1cc4ad9b70bfbfc657b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

2.3.1 This release

2 release files

2.3.0

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.10

2 release files

2.0.9

2 release files

2.0.8

2 release files

2.0.7

2 release files

2.0.6

2 release files

2.0.5

2 release files

2.0.4

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page