Rust crate for embedding, manipulating and retrieving data embedded in binaries using linker sections

Overview

linkstore

linkstore is a library that allows you to define global variables in your final compiled binary that can be modified post-compilation.

linkstore currently supports ELF and PE executable formats and can be used with both statically and dynamically linked libraries.

Supported types

Currently, linkstore can serialize and deserialize numbers (excluding usize and isize), bool and fixed-length arrays out of the box.

For anything else, you'll need to implement your own deserialization from fixed-length byte arrays.

Usage

Defining & using linkstore globals

#[macro_use] extern crate linkstore;

linkstore! {
    pub static LINKSTORE_TEST: u64 = 0xDEADBEEF;
    pub static LINKSTORE_YEAH: u32 = 0xDEADBEEF;
    pub static LINKSTORE_BYTES: [u8; 4] = [0xDE, 0xAD, 0xBE, 0xEF];
    pub static LINKSTORE_SHORTS: [u16; 4] = [0xDE, 0xAD, 0xBE, 0xEF];
    pub static LINKSTORE_BIG: u128 = 0xDEADBEEF;
}

fn main() {
    unsafe {
        println!("LINKSTORE_TEST = {:x}", LINKSTORE_TEST::get());
        println!("LINKSTORE_YEAH = {:x}", LINKSTORE_YEAH::get());
        println!("LINKSTORE_BYTES = {:?}", LINKSTORE_BYTES::get());
        println!("LINKSTORE_SHORTS = {:?}", LINKSTORE_SHORTS::get());
        println!("LINKSTORE_BIG = {:b}", LINKSTORE_BIG::get());
    }
}

Manipulating linkstore globals after compilation

Once your binary has been built, you can use linkstore to modify the values.

= std::fs::read("C:\\Windows\\system32\\kernel32.dll").unwrap(); let mut binary: std::io::Cursor<&mut [u8]> = std::io::Cursor::new(&mut binary); let mut embedder = linkstore::Embedder::new(&mut binary).unwrap(); embedder.embed("LINKSTORE_TEST", &69_u64).unwrap(); embedder.embed("LINKSTORE_YEAH", &420_u32).unwrap(); embedder.embed("LINKSTORE_BYTES", &[1_u8, 2, 3, 4]).unwrap(); embedder.embed("LINKSTORE_SHORTS", &[1_u16, 2, 3, 4]).unwrap(); embedder.embed("LINKSTORE_BIG", &(u128::MAX / 2)).unwrap(); embedder.finish().unwrap();">
// You can use `linkstore::open_binary` to open a binary file from the filesystem.
let mut binary: std::fs::File = linkstore::open_binary("C:\\Windows\\system32\\kernel32.dll").unwrap();

// Alternatively, you can work directly on a memory buffer or memory-mapped file using a `std::io::Cursor`
let mut binary: Vec<u8> = std::fs::read("C:\\Windows\\system32\\kernel32.dll").unwrap();
let mut binary: std::io::Cursor<&mut [u8]> = std::io::Cursor::new(&mut binary);

let mut embedder = linkstore::Embedder::new(&mut binary).unwrap();

embedder.embed("LINKSTORE_TEST", &69_u64).unwrap();
embedder.embed("LINKSTORE_YEAH", &420_u32).unwrap();
embedder.embed("LINKSTORE_BYTES", &[1_u8, 2, 3, 4]).unwrap();
embedder.embed("LINKSTORE_SHORTS", &[1_u16, 2, 3, 4]).unwrap();
embedder.embed("LINKSTORE_BIG", &(u128::MAX / 2)).unwrap();

embedder.finish().unwrap();

TODO

  • MacOS binaries support
  • MacO + fat binaries support
  • When specialization is stabilized, implement a ton of specialization and potentially extra serialization/deserialization support
  • Continuous integration
You might also like...
SCEMU The crates.io lib, x86 cpu and systems emulator focused mainly for anti-malware

SCEMU Usage Download the maps32.zip or maps64.zip from: https://github.com/sha0coder/scemu/releases/download/maps/maps32.zip https://github.com/sha0co

The Resurgence VM, a register virtual machine designed for simplicity and ease of use, based on the old Rendor VM
The Resurgence VM, a register virtual machine designed for simplicity and ease of use, based on the old Rendor VM

Resurgence Join the Discord server! Resurgence aims to be an embeddable virtual machine with an easy-to-use API for projects like: Game engines Langua

Emulator and debugger for LPRS1 ISA & CPU

About LPRSemu is a simple emulator and debugger for LPRS1 ISA & CPU. It supports loading programs from assembly text files, binary string representati

A hardware-accelerated GPU terminal emulator powered by WebGPU, focusing to run in desktops, browsers, tvs and everywhere.
A hardware-accelerated GPU terminal emulator powered by WebGPU, focusing to run in desktops, browsers, tvs and everywhere.

Rio term tl;dr: Rio is a terminal built to run everywhere, as a native desktop applications by Rust/WebGPU or even in the browser powered by WebAssemb

NES emulator written in Rust to learn Rust

OxideNES A NES emulator in Rust. CPU should be accurate, PPU is mostly accurate, timing between the 2 is off for some corner cases and hardware qui

Commodore 64 emulator written in Rust
Commodore 64 emulator written in Rust

Rust64 - a C64 emulator written in Rust This is my attempt to study the Rust programming language and have fun at the same time. The goal is to presen

A Flash Player emulator written in Rust
A Flash Player emulator written in Rust

website | demo | nightly builds | wiki Ruffle Ruffle is an Adobe Flash Player emulator written in the Rust programming language. Ruffle targets both t

A Gameboy Emulator in Rust

RBoy A Gameboy Color Emulator written in Rust Implemented CPU All instructions correct All timings correct Double speed mode GPU Normal mode Color mod

RGB (Rust Game Boy) is a simple emulator for the original game boy
RGB (Rust Game Boy) is a simple emulator for the original game boy

RGB RGB (Rust Game Boy) is a simple emulator for the original game boy and the color game boy. Warning: This no longer compiles in the latest versions

Comments
  • Update Cargo.toml

    Update Cargo.toml

    Mentioning "0" would mean cargo would pick the latest dependency which is versioned "0.*" which would include versions incompatible with the one that this crate was written with and may break your create.

    opened by Dylan-DPC 1
Releases(1.0.2)
Owner
William
aka Billy
William
Another Chip8 Emulator(ACE) made using Rust

ACE(Another Chip8 Emulator) ACE(Another Chip8 Emulator) This is a chip8 emulator created using Rust programming Language. It's purpose is to learn Rus

Sakura 4 Nov 12, 2021
A Game Boy research project and emulator written in Rust

Mooneye GB Mooneye GB is a Game Boy research project and emulator written in Rust. The main goals of this project are accuracy and documentation. Some

Joonas Javanainen 802 Dec 28, 2022
RustBoyAdvance-NG is a Nintendo™ Game Boy Advance emulator and debugger, written in the rust programming language.

RustBoyAdvance-NG Nintendo GameBoy Advance ™ emulator and debugger, written in rust. WebAssembly Demo: https://michelhe.github.io/rustboyadvance-ng/ P

MishMish 510 Dec 30, 2022
A NES emulator written in Rust, with a focus on expandability and accuracy

A NES emulator written in Rust, with a focus on expandability and accuracy

Benjamin Mordaunt 4 Sep 19, 2022
Unicorn Emulator Debug Server - Written in Rust, with bindings of C, Go, Java and Python

udbserver - Unicorn Emulator Debug Server When you do emulation with Unicorn Engine, do you want to inspect the inner state during every step? udbserv

Bet4 246 Dec 27, 2022
Learning Rust and ECS by implementing an emulator for Silkroad Online.

Skrillax Learning Rust and ECS by implementing an emulator for an MMORPG. Skrillax is my learning project for playing around with Rust, learning about

Tim Hagemann 10 Dec 22, 2022
🥔 MOS-6502 and NES emulator in Rust (SDL/WebAssembly)

?? Potatis /mos6502 - Generic CPU emulator. Passes all tests, including illegal ops. (No BCD mode). /nes - A very incomplete NES emulator. /nes-sdl -

Henrik Persson 28 Jan 9, 2023
TestSuite4 is a framework designed to simplify development and testing of TON Contracts. It includes light-weight emulator of blockchain making it easy to develop contracts.

TestSuite4 0.1.2 TestSuite4 is a framework designed to simplify development and testing of TON Contracts. It contains lightweight blockchain emulator

TON Labs 26 Feb 3, 2022
Learn emulator and programming languages, target chip8, nes, gbc, gba ...

[WIP]learn emulator go-chip8 go run main.go source https://en.wikipedia.org/wiki/CHIP-8 http://devernay.free.fr/hacks/chip8/C8TECH10.HTM https://githu

早晨海风 4 Apr 30, 2021
A game about evolution, cooperation, and predation

Biomass Breakout Backstory An ark has crash landed on the failed colony of Vivemortis, which humans had tried and failed to tame. As it crashes, the t

Samuel Schlesinger 1 Dec 5, 2021