Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/williamvenner/linkstore
Rust crate for embedding, manipulating and retrieving data embedded in binaries using linker sections
https://github.com/williamvenner/linkstore
ar binaries binary coff drm elf executable fingerprint fingerprinting linker linking mach-o macho pe program rust steganography
Last synced: 3 months ago
JSON representation
Rust crate for embedding, manipulating and retrieving data embedded in binaries using linker sections
- Host: GitHub
- URL: https://github.com/williamvenner/linkstore
- Owner: WilliamVenner
- License: mit
- Created: 2022-01-22T22:30:04.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-11-18T10:51:23.000Z (about 2 years ago)
- Last Synced: 2024-10-11T11:33:27.441Z (4 months ago)
- Topics: ar, binaries, binary, coff, drm, elf, executable, fingerprint, fingerprinting, linker, linking, mach-o, macho, pe, program, rust, steganography
- Language: Rust
- Homepage:
- Size: 108 KB
- Stars: 8
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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 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.
```rust
// 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 = 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();
```