| --- |
| license: cc-by-4.0 |
| pretty_name: BCSD Dataset (Binary Code Similarity Detection) |
| language: |
| - en |
| task_categories: |
| - feature-extraction |
| tags: |
| - binary-code-similarity |
| - bcsd |
| - reverse-engineering |
| - disassembly |
| - x86-64 |
| size_categories: |
| - 100K<n<1M |
| --- |
| |
| # BCSD Dataset |
|
|
| A dataset for Binary Code Similarity Detection (BCSD). It contains C/C++ programs compiled |
| with two compilers (GCC, Clang) at five optimization levels (O0, O1, O2, O3, Os) on x86-64, |
| together with their disassembly and precomputed function embeddings. |
|
|
| ## Contents |
|
|
| | File | Size | Description | |
| |------|------|-------------| |
| | `sources.tar.zst` | 22 MB | Original source files (C, C++, Go, Rust) | |
| | `binaries.tar.zst` | 1.85 GB | Compiled ELF binaries (114,532 files) | |
| | `disasm.tar.zst` | 47 MB | Linear disassembly (angr), one JSON per binary | |
| | `disasm_jtrans.tar.zst` | 99 MB | Basic-block disassembly for jTrans models | |
| | `embeddings.tar.zst` | 538 MB | Per-function embeddings (`.npy`) for each approach | |
|
|
| Statistics: 11,639 source programs over 5,212 problems (AtCoder, LeetCode, Rosetta Code). |
|
|
| ## Path layout |
|
|
| The `binaries`, `disasm`, `disasm_jtrans` and `embeddings` archives use the same layout: |
|
|
| ``` |
| <compiler>/<arch>/<optim>/<dataset>/<problem>/<Lang>__impl_NN |
| example: clang/x86_64/Os/rosetta_code/binary_digits/Cpp__impl_01 |
| ``` |
|
|
| Sources use `sources/<dataset>/<problem>/<Lang>/impl_NN.ext`. |
|
|
| ## Download |
|
|
| ```bash |
| pip install -U "huggingface_hub[cli]" |
| |
| # one file |
| hf download <user>/bcsd-dataset disasm.tar.zst --repo-type dataset --local-dir . |
| |
| # everything |
| hf download <user>/bcsd-dataset --repo-type dataset --local-dir ./bcsd-dataset |
| ``` |
|
|
| ## Decompress |
|
|
| The archives are compressed with zstd. Install zstd (`apt install zstd` or `brew install zstd`), |
| then extract: |
|
|
| ```bash |
| tar --use-compress-program=unzstd -xf disasm.tar.zst |
| # or, with a recent tar: |
| tar --zstd -xf disasm.tar.zst |
| ``` |
|
|
| ## Usage |
|
|
| Read a disassembly file (one JSON per binary): |
|
|
| ```python |
| import json |
| d = json.load(open("disasm/clang/x86_64/Os/rosetta_code/binary_digits/Cpp__impl_01.json")) |
| for fn in d["functions"]: |
| print(fn["name"], fn["nb_instructions"]) |
| for mnemonic, operands in fn["instructions"]: |
| print(mnemonic, operands) |
| ``` |
|
|
| Load a function embedding (shape is `(n_functions, dim)`): |
|
|
| ```python |
| import numpy as np |
| v = np.load("embeddings/palmtree/clang/x86_64/Os/rosetta_code/binary_digits/Cpp__impl_01.npy") |
| print(v.shape) # (1, 128) |
| ``` |
|
|
| Embedding dimensions: `baseline` = 16, `palmtree` / `refuse` = 128, `jtrans` = 768. |
| The file `embeddings/index.json` maps each `source_id::function` to its embedding paths. |
|
|
| ## Notes |
|
|
| Only C and C++ are compiled in this release; Go and Rust appear in the sources only. The |
| dataset is x86-64 only. Source programs come from AtCoder, LeetCode and Rosetta Code; please |
| respect their terms when reusing. |
|
|