9 releases (breaking)

0.7.0 Nov 16, 2023
0.6.1 May 13, 2023
0.5.0 Sep 14, 2022
0.4.0 Aug 3, 2022
0.1.1 May 21, 2022

#906 in Parser implementations

24 downloads per month
Used in 4 crates

MIT license

120KB
3K SLoC

hlbc Crates.io

Hashlink bytecode disassembler and analyzer.

This crate is a library, see hlbc-cli for an actual program to use.


Features

  • Parse the whole bytecode file or any bytecode element
  • Display any bytecode element
  • Restore all possible names
  • Link elements between them (with manual references for flexibility)
  • Link elements with their debug information
  • Serialize bytecode back to bytes
  • Decompiler to haxe source code for classes and functions
  • Commandline interface to use the features of this library (hlbc-cli)

Planned features

  • Properly test serialization, ensure we get a byte-to-byte equivalent.
  • Integrate with the Haxe/Hashlink standard library to restore more names, exclude them from analysis and such
  • C API to integrate with other tools
  • Text search engine to search for strings and names
  • Assemble and inject bytecode or inject haxe source code directly

Changelog

See CHANGELOG.md.

Decompiler

The decompiler is present in the hlbc-decompiler crate and is currently incomplete (and might never be 100% complete). See the wiki for examples of decompilation output.

Wiki

A wiki detailing the specifics of Hashlink bytecode is available here. The wiki also details the specifics of Haxe to hashlink compilation and decompilation.

Alternatives

This library is made in Rust, a C API is in the works which could permit using this lib in many other projects, but for now it is only Rust friendly.

Other alternatives include :

  • Tinkering directly with the hashlink source code in C (my first attempt was doing this, but it turned out that everything in C is pain in the ass)
  • Using the in-progress dashlink made in Haxe but probably compilable to many other languages.

Macros

There are 98 different bytecode instructions, there is no way I manually write code for them. Most of the serialization code for these opcodes is generated through a proc macro (see hlbc-derive). Making that a declarative macro would probably turn out really hard. The only time I needed to write 98 different branches was for the formatting used when displaying the instructions (src/fmt.rs).

Dependencies

~0.5–1.4MB
~27K SLoC