https://github.com/elykdeer/gecil
a good enough c to hlil compiler
https://github.com/elykdeer/gecil
binaryninja c compiler il
Last synced: 11 months ago
JSON representation
a good enough c to hlil compiler
- Host: GitHub
- URL: https://github.com/elykdeer/gecil
- Owner: ElykDeer
- Created: 2021-01-27T12:25:38.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-02-02T20:55:51.000Z (almost 5 years ago)
- Last Synced: 2024-08-25T20:04:01.439Z (over 1 year ago)
- Topics: binaryninja, c, compiler, il
- Language: Python
- Homepage:
- Size: 81.1 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# gecil - the good enough c-to-il "compiler"
We take this binary:

and this source snippet:

to make this:

---
This serves just as a minimal proof of concept that one may be able to compile limited snippets of code, such as a single function, to BinaryNinja's HLIL for the purposes of matching it against HLIL generated from a compiled binary and propagating information from the source to the BNDB.
This example is only complete enough to compile hello world, and to copy comments from source to the BNDB.
Graph matching is also only complete enough to do basically just an exact match.
It's just a POC.
---
To run this:
1. Have BinaryNinja installed (plus the headless API)
2. `./test_matching_algo.py`
3. Open `output.bndb` in BinaryNinja and look at the main function
4. Say "oohh" and "aahh"
or
1. Put this folder into your user plugins folder
2. Open the example binary in Binary Ninja
3. Copy the source for the main function from `example.c`
4. Right Click->Plugins->Annotate Binary From Source
5. Paste source, hit "ok"
6. Say "oohh" and "aahh"
---
File list:
- gecil.py - This is the compiler
- gecil.lark - This is the EBNF/Lark grammar I'm using to parse C
- test_matching_algo.py - Is the exemplary graph-matching/artifact propagation "engine"
- hlil.py - Is a bunch of garbage you should ignore; HLIL in the BN API doesn't have the required APIs to "create" arbitrary instructions, so copy/pasted/fixed that up
- example.c - The file used for the test matching algo
- example - compiled with `gcc example.c -o example`
- requirements.txt - you need to have `lark-parser` installed to run this demo/POC