Skip to content

Latest commit

 

History

History
49 lines (33 loc) · 1.73 KB

README.md

File metadata and controls

49 lines (33 loc) · 1.73 KB

hlbc-python

A (terrible) Python wrapper for hlbc - A Hashlink bytecode disassembler and decompiler.

Installation

pip install hlbc

Usage

Before running this example, download either the prebuilt bytecode or the source code of the Clazz test file and place the compiled bytecode in the same directory as the script.

import hlbc

# Open and disassemble a file
code = hlbc.Bytecode("./Clazz.hl")

# Get the debug files
print(code.get_debug_files())
# > ['Clazz.hx', 'C:\\HaxeToolkit\\haxe\\std/hl/_std/Std.hx', 'C:\\HaxeToolkit\\haxe\\std/hl/_std/String.hx', ... '?']

# Get all functions from a specific debug file in the bytecode
print(code.get_functions("Clazz.hx"))
# > ['fn main@22 () -> void', 'fn method@23 (Clazz) -> i32', 'fn <none>@337 ((f64, f64) -> i32, i32, i32) -> i32', ...]

# Decompile a single function by index
print(code.decompile("23"))
# > static function method(_: Clazz): Int {
# >  return 42;
# > }

# Stub a function
print(code.stub("23"))
# > static function method(_: Clazz): Int {}

Notes

  • Any errors will be raised back to Python as simple Exceptions, but this is subject to change.
  • The Bytecode class is thread-safe. You can use the same instance multiple times in different threads. It also doesn't hold the file open, so you can create multiple instances of it with the same file.

Credits

  • Gui-Yom (Guillaume Anthouard) for creating hlbc, which this project is just a cheap repackaging of.