Giter Club home page Giter Club logo

linkstore's Introduction

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.

// 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();

linkstore's People

Contributors

dylan-dpc avatar williamvenner avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

linkstore's Issues

Add support for changing the name of the binary section

If it is possible it would be nice to be able to change the name of the section in the binary so that if someone is looking to port a program from another language that uses a similar technique as linkstore they would be able to port their code over to rust while still allowing the dynamic library or static library to work the same way

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.