Skip to main content

Your Only Decompiler API Lib - A generic API to script in and out of decompilers

Project description

LibBS

The decompiler API that works everywhere!

LibBS is an abstracted decompiler API that enables you to write plugins/scripts that work, with minimal edit, in every decompiler supported by LibBS. LibBS was originally designed to work with BinSync, and is the backbone for all BinSync based plugins. As an example, with the same script, you can redefine the types of function variables with custom structs, all in less than 30 lines, in any supported decompilers.

Install

pip install libbs

The minimum Python version is 3.10.

Supported Decompilers

  • IDA Pro: >= 8.4 (if you have an older version, use v1.26.0)
  • Binary Ninja: >= 2.4
  • angr-management: >= 9.0
  • Ghidra: >= 12.0 (started in PyGhidra mode)

Usage

LibBS exposes all decompiler API through the abstract class DecompilerInterface. The DecompilerInterface can be used in either the default mode, which assumes a GUI, or headless mode. In headless mode, the interface will start a new process using a specified decompiler.

You can find various examples using LibBS in the examples folder. Examples that are plugins show off more of the complicated API that allows you to use an abstracted UI, artifacts, and more.

UI Mode (default)

To use the same script everywhere, use the convenience function DecompilerInterface.discover_interface(), which will auto find the correct interface. Copy the below code into any supported decompiler and it should run without edit.

from libbs.api import DecompilerInterface

deci = DecompilerInterface.discover()
for addr in deci.functions:
    function = deci.functions[addr]
    if function.header.type == "void":
        function.header.type = "int"
        deci.functions[function.addr] = function

Note that for Ghidra in UI mode you must first start it in PyGhidra mode. You can do this by going to your install dir and running ./support/pyghidraRun.

Headless Mode

To use headless mode you must specify a decompiler to use. You can get the traditional interface using the following:

from libbs.api import DecompilerInterface

deci = DecompilerInterface.discover(force_decompiler="ghidra", headless=True)

In the case of Ghidra, you must have the environment variable GHIDRA_INSTALL_DIR set to the path of the Ghidra installation (the place the ghidraRun script is located).

Artifact Access Caveats

In designing the dictionaries that contain all Artifacts in a decompiler, we had a clash between ease-of-use and speed. When accessing some artifacts like a Function, we must decompile the function. Decompiling is slow. Due to this issue we slightly changed how these dictionaries work to fast accessing.

The only way to access a full artifact is to use the getitem interface of a dictionary. In practice this looks like the following:

for func_addr, light_func in deci.functions.items():
    full_function = deci.function[func_addr]

Notice, when using the items function the function is light, meaning it does not contain stack vars and other info. This also means using keys, values, or list on an artifact dictionary will have the same affect.

Serializing Artifacts

All artifacts are serializable to the TOML and JSON formats. Serialization is done like so:

from libbs.artifacts import Function
import json

my_func = Function(name="my_func", addr=0x4000, size=0x10)
json_str = my_func.dumps(fmt="json")
loaded_dict = json.loads(json_str) # now loadable through normal JSON parsing
loaded_func = Function.loads(json_str, fmt="json")

Sponsors

BinSync and its associated projects would not be possible without sponsorship. In no particular order, we'd like to thank all the organizations that have previously or are currently sponsoring one of the many BinSync projects.

NSF
DARPA
ARPA-H
RevEng AI

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

libbs-3.4.0.tar.gz (127.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

libbs-3.4.0-py3-none-any.whl (130.5 kB view details)

Uploaded Python 3

File details

Details for the file libbs-3.4.0.tar.gz.

File metadata

  • Download URL: libbs-3.4.0.tar.gz
  • Upload date:
  • Size: 127.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for libbs-3.4.0.tar.gz
Algorithm Hash digest
SHA256 ca5c7e6b0e572cdcdc6b25c6bd6d549d3aa7a3c4fc0a1e0a46d62209988064c3
MD5 36a61624cb620302288dba081eed3c2e
BLAKE2b-256 0ae1e096b2e88ab53a7edcfbd5333f2691844940ed6b06a5a80f9d05fe9928dd

See more details on using hashes here.

File details

Details for the file libbs-3.4.0-py3-none-any.whl.

File metadata

  • Download URL: libbs-3.4.0-py3-none-any.whl
  • Upload date:
  • Size: 130.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for libbs-3.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 036015489a9e4dc856f40dbee8dd30be63b2f073c691e0fa7ded36c4003866cf
MD5 b9a95675ea162507df24511c68545704
BLAKE2b-256 3408b074b5efe120b5307f5c5494b51ae76fae5982867def718f06583ccf64c2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page