GithubHelp home page GithubHelp logo

slatbox / varbert_api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from binsync/varbert_api

0.0 0.0 0.0 3.46 MB

A Python API to VarBERT, a BERT based LLM for suggesting variable names in decompiled code.

License: BSD 2-Clause "Simplified" License

Python 100.00%

varbert_api's Introduction

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

varbert_api's People

Contributors

mahaloz avatar atipriya avatar adamdoupe avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.