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

```rust

[macro_use] extern crate linkstore;

linkstore! { pub static LINKSTORETEST: u64 = 0xDEADBEEF; pub static LINKSTOREYEAH: u32 = 0xDEADBEEF; pub static LINKSTOREBYTES: [u8; 4] = [0xDE, 0xAD, 0xBE, 0xEF]; pub static LINKSTORESHORTS: [u16; 4] = [0xDE, 0xAD, 0xBE, 0xEF]; pub static LINKSTORE_BIG: u128 = 0xDEADBEEF; }

fn main() { unsafe { println!("LINKSTORETEST = {:x}", LINKSTORETEST::get()); println!("LINKSTOREYEAH = {:x}", LINKSTOREYEAH::get()); println!("LINKSTOREBYTES = {:?}", LINKSTOREBYTES::get()); println!("LINKSTORESHORTS = {:?}", LINKSTORESHORTS::get()); println!("LINKSTOREBIG = {:b}", LINKSTOREBIG::get()); } } ```

Manipulating linkstore globals after compilation

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

``rust // You can uselinkstore::openbinary` to open a binary file from the filesystem. let mut binary: std::fs::File = linkstore::openbinary("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 = 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("LINKSTORETEST", &69u64).unwrap(); embedder.embed("LINKSTOREYEAH", &420u32).unwrap(); embedder.embed("LINKSTOREBYTES", &[1u8, 2, 3, 4]).unwrap(); embedder.embed("LINKSTORESHORTS", &[1u16, 2, 3, 4]).unwrap(); embedder.embed("LINKSTORE_BIG", &(u128::MAX / 2)).unwrap();

embedder.finish().unwrap(); ```