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.

Install

pip install libbs

The minimum Python version is 3.10. If you plan on using libbs alone (without installing some other plugin), you must do libbs --install after pip install. This will copy the appropriate files to your decompiler.

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: >= 11.1

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

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 decompilers that don't have a native python library for working with, like Ghidra and IDA, you will to tell libbs where the headless binary path exists. This can be passed through either headless_dec_path flag, or through your environment. For Ghidra this would be: GHIDRA_HEADLESS_PATH.

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")

Project details


Release history Release notifications | RSS feed

This version

2.0.2

Download files

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

Source Distribution

libbs-2.0.2.tar.gz (118.4 kB view details)

Uploaded Source

Built Distribution

libbs-2.0.2-py3-none-any.whl (130.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: libbs-2.0.2.tar.gz
  • Upload date:
  • Size: 118.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for libbs-2.0.2.tar.gz
Algorithm Hash digest
SHA256 b6d82f3fa2c2c08d5c11e7edb65919b5626f9874fe123cf9126ebe1b83ebc745
MD5 b5b1a7cbe0d0f26704f0bfa6b8d612e7
BLAKE2b-256 1ec602e7b7fa75ae454e36ab2c6b0b444d9697f5eb2d6cfaab3e230db9eb67e8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: libbs-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 130.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for libbs-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b456271187366d6aa3e24c9db3d814bbf58c8380f06f85d34514f938c74663e2
MD5 b67bd21bdc914cea4771e39542cf7384
BLAKE2b-256 7307fd842a37c87018390b51e786e6a7e05e20c887d752d10274db370e7e0094

See more details on using hashes here.

Supported by

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