disasm2vec is a research framework designed to generate vector representations from disassembled C/C++ binaries. It provides a modular pipeline that handles compilation, disassembly, tokenization, and vectorization, enabling researchers and security analysts to transform raw code into machine-learning-ready features.
Project description
disasm2vec
disasm2vec is a research framework designed to generate vector representations from disassembled C/C++ binaries. It provides a modular pipeline that handles compilation, disassembly, tokenization, and vectorization, enabling researchers and security analysts to transform raw code into machine-learning-ready features.
Features
- Automated Compilation: Seamlessly compiles C and C++ source files using GCC.
- Disassembly Wrapper: Extracts assembly instructions using
objdump, supporting both full and function-specific disassembly. - Intelligent Tokenization: Normalizes and cleans assembly instructions, with options to preserve or abstract register names.
- Vectorization: Implements TF-IDF vectorization with a flexible factory pattern for easy model management.
- End-to-End Pipeline: Orchestrates the entire process from source code to vector embedding.
- Extensible Architecture: Built with abstract base classes to easily support new compilers, disassemblers, or vectorizers.
Prerequisites
- Python: version 3.10 or higher.
- Operating System: Linux or Windows Subsystem for Linux (WSL).
- GCC: Required for compiling source files.
- Objdump: Required for disassembling binaries.
Note: The compilation (gcc) and disassembly (objdump) modules rely on system-level tools typically found in Linux environments. If you are on Windows, please use WSL.
Ensure both gcc and objdump are installed and available in your system's PATH.
Installation
Install directly from PyPI:
pip install disasm2vec
Or install from source:
git clone https://github.com/yourusername/disasm2vec.git
cd disasm2vec
pip install .
Usage
The core of the framework is the PipelineRunner, which processes a source file based on a configuration object.
Basic Example
from disasm2vec.pipeline import PipelineConfig, run_pipeline
# Configure the pipeline
config = PipelineConfig(
source_file="examples/sample.c",
build_dir="build",
asm_dir="asm",
model_path="models/base_tfidf_asm.pkl" # Path to pre-trained model or where to save a new one
)
# Run the pipeline
# returns:
# vector: The vector representation of the source file
# vectorizer: The fitted vectorizer instance
vector, vectorizer = run_pipeline(config)
print(f"Generated Vector Shape: {vector.shape}")
License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file disasm2vec-0.1.0.tar.gz.
File metadata
- Download URL: disasm2vec-0.1.0.tar.gz
- Upload date:
- Size: 36.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4efda753719a43240132b567ed558926ff43b47171f41f62caba1db0f7acb8ae
|
|
| MD5 |
ec6bffdee55942b8eef9d40b20c2e11e
|
|
| BLAKE2b-256 |
b39ce43f371defe1363fff3d8cfeb56b7f4f7e174413657f2df919c457b8e621
|
File details
Details for the file disasm2vec-0.1.0-py3-none-any.whl.
File metadata
- Download URL: disasm2vec-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72acca07311400d24c50bb7f600abf11e2c4a73fb4e9ad7c94e0722191a8abb2
|
|
| MD5 |
d682540302c9c8a5750486cb16539f36
|
|
| BLAKE2b-256 |
90b3e06768a8c83dfbc9b0adf2fb99f47ff49eac081956aa977919a2aa148917
|