-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reorganize the repository, update readmes and changelogs
- Loading branch information
Showing
22 changed files
with
208 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
/target | ||
.idea/ | ||
*.hl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,2 @@ | ||
[package] | ||
name = "hlbc" | ||
version = "0.4.0" | ||
authors = ["Guillaume Anthouard <[email protected]>"] | ||
edition = "2021" | ||
rust-version = "1.56" | ||
description = "Hashlink bytecode disassembler, analyzer and decompiler" | ||
repository = "https://github.com/Gui-Yom/hlbc" | ||
license = "MIT" | ||
keywords = ["hashlink", "bytecode", "disassembler", "analysis", "decompiler"] | ||
categories = ["parser-implementations", "visualization", "compilers"] | ||
include = ["src/**/*", "LICENSE", "README.md"] | ||
|
||
[workspace] | ||
members = ["hlbc-derive", "hlbc-decompiler", "hlbc-cli"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
# Endianess utilities | ||
byteorder = "1" | ||
# Advanced formatting functionalities | ||
fmtools = "0.1" | ||
# Compile time code generation for hlbc::Opcode | ||
hlbc-derive = { version = "0.3", path = "hlbc-derive" } | ||
# Graph utilities | ||
petgraph = { version = "0.6", default-features = false, features = ["graphmap"], optional = true } | ||
# Error types | ||
thiserror = "1" | ||
|
||
[features] | ||
default = ["graph"] | ||
# Generate a callgraph | ||
graph = ["petgraph"] | ||
members = ["hlbc-derive", "hlbc", "hlbc-decompiler", "hlbc-cli"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,41 @@ | ||
# hlbc ![Crates.io](https://img.shields.io/crates/v/hlbc?label=hlbc) ![Crates.io](https://img.shields.io/crates/v/hlbc-cli?label=hlbc-cli) | ||
<div align="center"> | ||
<h1><b>H</b>ash<b>l</b>ink <b>b</b>yte<b>c</b>ode</h1> | ||
<a href="https://crates.io/crates/hlbc"> | ||
<img src="https://img.shields.io/crates/v/hlbc?label=hlbc"> | ||
</a> | ||
<a href="https://crates.io/crates/hlbc-decompiler"> | ||
<img src="https://img.shields.io/crates/v/hlbc-decompiler?label=hlbc-decompiler"> | ||
</a> | ||
<a href="https://crates.io/crates/hlbc-cli"> | ||
<img src="https://img.shields.io/crates/v/hlbc-cli?label=hlbc-cli"> | ||
</a> | ||
<br/> | ||
This repository contains a collection of Rust crates and cli tools to load, disassemble, decompile and | ||
analyze <a href="https://hashlink.haxe.org/">Hashlink</a> bytecode. | ||
<br/> | ||
<img src="hlbc-cli/screenshot.png"> | ||
</div> | ||
|
||
[**H**ash**l**ink](https://hashlink.haxe.org/) **b**yte**c**ode disassembler, analyzer, decompiler and assembler. | ||
|
||
*This crate is a library, see [hlbc-cli](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](hlbc-cli)) | ||
|
||
## Planned features | ||
|
||
- Integrate with the Haxe/Hashlink standard library to restore more names, exclude them from analysis and such | ||
- Gui to render the callgraph in real time | ||
- Gui to render instructions and decompiled code | ||
- 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](CHANGELOG.md). | ||
|
||
## Decompiler | ||
## Repository structure | ||
|
||
The decompiler is currently incomplete (and will probably always be). | ||
[See the wiki](https://github.com/Gui-Yom/hlbc/wiki/Decompilation) for examples of decompilation output. | ||
- `data/` : Haxe source files to test the tools | ||
- `hlbc/` : Core library to load and disassemble bytecode | ||
- `hlbc-cli/` : CLI frontend for `hlbc` | ||
- `hlbc-decompiler/` : Decompiler library | ||
- `hlbc-derive/` : helper proc macros for hlbc | ||
|
||
## Wiki | ||
|
||
A wiki detailing the specifics of Hashlink bytecode is available [here](https://github.com/Gui-Yom/hlbc/wiki). | ||
The wiki also details the inner workings of haxe to hashlink compilation and decompilation. | ||
A wiki detailing the specifics of Hashlink bytecode is available [here](https://github.com/Gui-Yom/hlbc/wiki) or by | ||
using the command `wiki`. | ||
|
||
## Macros | ||
|
||
There are 98 different bytecode instructions, there is no way I manually write code for it each time. Most of the code | ||
for these opcodes is generated through a proc macro (see [hlbc-derive](/hlbc-derive)). | ||
The only time I needed to write 98 different branches was for the formatting used when displaying the | ||
instructions ([src/fmt.rs](src/fmt.rs)). | ||
|
||
## Repository structure | ||
## Planned features | ||
|
||
- `/` : hlbc (lib) | ||
- `hlbc-derive/` : hlbc-derive, helper proc macros for hlbc | ||
- `hlbc-cli/` : CLI using hlbc | ||
- `data/` : Haxe source files to test the decompiler | ||
- GUI | ||
- C API | ||
|
||
## Credits | ||
|
||
Development of this crate wouldn't be possible without the [hashlink](https://github.com/HaxeFoundation/hashlink) source | ||
code. Some algorithms are directly derived from the original C code reading bytecode files. | ||
|
||
## 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](https://github.com/HaxeFoundation/hashlink) source code in C | ||
- Using the in-progress [**_*dashlink*_**](https://github.com/Steviegt6/dashlink) made in Haxe but probably compilable | ||
to many other languages. | ||
|
||
## Notes about using Rust | ||
|
||
Rust isn't a very good fit for this project, the whole bytecode is a large graph and self-references do not mix well | ||
with Rust. Further iterations of this crate could make use of an arena. | ||
Development of this project would not have been possible without | ||
the [hashlink](https://github.com/HaxeFoundation/hashlink) source code. Some algorithms are directly derived from the | ||
original C code reading bytecode files. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
# Decompiler test data | ||
|
||
The files in this directory are used to test the decompiler output. | ||
|
||
## Building | ||
|
||
To build a particular source file : | ||
|
||
```shell | ||
haxe -hl <file>.hl -main <file>.hx | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,13 +4,18 @@ version = "0.4.0" | |
authors = ["Guillaume Anthouard <[email protected]>"] | ||
edition = "2021" | ||
rust-version = "1.56" | ||
description = "Hashlink bytecode disassembler, analyzer and decompiler" | ||
description = "Hashlink bytecode disassembler, analyzer and decompiler cli" | ||
repository = "https://github.com/Gui-Yom/hlbc" | ||
license = "MIT" | ||
categories = ["command-line-utilities", "parser-implementations", "visualization", "compilers"] | ||
include = ["src/**/*", "README.md", "CHANGELOG.md"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[[bin]] | ||
name = "hlbc" | ||
path = "src/main.rs" | ||
|
||
[dependencies] | ||
# Result type | ||
anyhow = "1" | ||
|
@@ -21,7 +26,7 @@ chumsky = { version = "0.8" } | |
# CLI args | ||
clap = { version = "3", features = ["derive"] } | ||
# Core functionnality | ||
hlbc = { version = "0.4", path = "..", default-features = false } | ||
hlbc = { version = "0.4", path = "../hlbc", default-features = false } | ||
# Decompiler | ||
hlbc-decompiler = { version = "0.4", path = "../hlbc-decompiler" } | ||
# File system watching | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Changelog | ||
|
||
This is the changelog for `hlbc-decompiler`, other crates have their own changelogs. | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [Unreleased](https://github.com/Gui-Yom/hlbc/compare/v0.3.0...HEAD) | ||
|
||
### Added | ||
|
||
- If and else statements are unified for better formatting and easier post-processing | ||
- New (currently hidden) ast post-processing step (AST-PP) to improve the decompiler output | ||
- New AST_PP : if-expressions | ||
- New AST-PP : string concatenations :(`__add__("a", "b")` to `"a" + "b"`) | ||
- New AST-PP : Hide calls to itos. Int to strings conversions are usually hidden. | ||
- Ability to generate comments in the AST | ||
- Display closure if InstanceClosure on an enum (the enum is the closure capture) | ||
|
||
### Fixed | ||
|
||
- Remove excessive `;` in constructor calls | ||
|
||
--- | ||
|
||
Previous releases of the decompiler can be found in the `hlbc` crate changelog. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# hlbc-decompiler [![Crates.io](https://img.shields.io/crates/v/hlbc-decompiler?label=hlbc-decompiler)](https://crates.io/crates/hlbc-decompiler) | ||
|
||
[**H**ash**l**ink](https://hashlink.haxe.org/) **b**yte**c**ode disassembler and analyzer. | ||
|
||
*This crate is a library, see [hlbc-cli](https://crates.io/crates/hlbc-cli) for an actual program to use.* | ||
|
||
--- | ||
|
||
[See the wiki](https://github.com/Gui-Yom/hlbc/wiki/Decompilation) for examples of decompilation output. |
Oops, something went wrong.