Skip to content

A Rust-based tool for extracting, decoding, and analyzing Solana BPF opcodes from compiled programs

Notifications You must be signed in to change notification settings

luishsr/rust-solana-opcode-extractor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 

Repository files navigation

Rust Solana Opcode Extractor

Rust Solana Opcode Extractor is a tool designed to decode, analyze, and extract BPF opcodes from Solana smart contracts. This utility leverages the solana_rbpf library to map raw BPF instructions to human-readable operations, enabling developers to gain deeper insights into the structure and execution of Solana programs.

Features

  • Extract and decode BPF instructions from compiled Solana programs.
  • Map raw opcodes to their corresponding operations using solana_rbpf.
  • Generate a detailed JSON output with decoded operations, operands, and metadata.
  • Analyze program flow for debugging and optimization.

How It Works

  1. Parses a JSON file (output.json) containing BPF instructions.
  2. Uses the solana_rbpf library to decode the instructions.
  3. Maps each instruction to its corresponding operation and extracts additional metadata.
  4. Outputs the decoded instructions into a JSON file (bytecode.json).

Prerequisites

  • Rust installed.
  • Familiarity with Solana development and BPF opcodes.

Installation

Clone the repository and build the project:

git clone https://github.com/luishsr/rust-solana-opcode-extractor.git
cd rust-solana-opcode-extractor
cargo build --release

Usage

  1. Ensure you have a valid output.json file containing BPF instructions (generated by your Solana program analysis tool).
  2. Run the executable:
    ./target/release/rust-solana-opcode-extractor path/to/output.json path/to/bytecode.json
  3. The decoded instructions will be saved to bytecode.json.

Example

Input (output.json):

{
  "file": "example_program.so",
  "instructions": [
    "[95, 00, 00, 00, 00, 00, 00, 00]",
    "[79, 12, 08, 00, 00, 00, 00, 00]"
  ],
  "type": "BPFInstructions"
}

Output (bytecode.json):

[
  {
    "opcode": "EXIT",
    "operation": "Exit",
    "operands": [],
    "metadata": {}
  },
  {
    "opcode": "MOV32_IMM",
    "operation": "Move Immediate",
    "operands": ["dst=1", "src=0", "imm=8"],
    "metadata": {}
  }
]

Contributing

Contributions are welcome! Please fork the repository, make your changes, and submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

  • Solana for the innovative blockchain platform.
  • solana_rbpf for the BPF tools and utilities.

Happy decoding!

About

A Rust-based tool for extracting, decoding, and analyzing Solana BPF opcodes from compiled programs

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages