libmem-logo

Made by rdbo

Discord Server

https://discord.com/invite/Qw8jsPD99X

License

Read LICENSE

Examples

C/C++

```c

include

int main() { lmmodulet mod; lmaddresst main_sym;

LM_FindModule("mygamemodule.so", &mod);
main_sym = LM_FindSymbolAddress(&mod, "main");
printf("[*] Module Name: %s\n", mod.name);
printf("[*] Module Path: %s\n", mod.path);
printf("[*] Module Base: %p\n", mod.base);
printf("[*] Module Size: %p\n", mod.size);
printf("[*] Module End:  %p\n", mod.end);
printf("[*] Main Addr:   %p\n"), main_sym);

return 0;

} ```

Rust

```rust fn some_function() { // ... }

fn hksomefunction() { // ... }

fn main() { // reading/writing memory let number : i32 = 0; let numberaddr = &number as *const i32 as lmaddresst; let value : i32 = 1337; LMWriteMemory(numberaddr, &value).unwrap(); // write 1337 to number let readnumber : i32 = LMReadMemory(numberaddr).unwrap(); println!("[*] Number Value: {}", read_number); // it will show 1337

// hooking/detouring functions
let func_addr = some_function as *const () as lm_address_t;
let hk_addr = hk_some_function as *const () as lm_address_t;
println!("[*] Hooking 'some_function'");
println!("[*] Original Address: {:#x}", func_addr;

let trampoline = LM_HookCode(func_addr, hk_addr).unwrap();
println!("[*] Trampoline: {:#x?}", trampoline);

some_function(); // this will call 'hk_some_function'

// restore the original code from 'some_function'
LM_UnhookCode(some_function_addr, trampoline).unwrap();

println!("[*] Unhooked 'some_function'");
some_function(); // call 'some_function' to see if it has been unhooked

}

```

Python

```py

Assemble/Disassemble code

print("[*] Assembly") inst = LM_Assemble("mov eax, ebx") print(f"{code} : {inst.bytes}")

print("[*] Disassembly:") inst = LMDisassemble(bytearray(b"\x55")) print(f"{inst.bytes} : {inst.mnemonic} {inst.opstr}") ```

Installing

Clone the repository: git clone https://github.com/rdbo/libmem Initialize and update the submodules: git submodule init git submodule update Compile libmem: mkdir build cd build cmake .. make -j 4 Install libmem: ```

Run as root

make install `` After installing, follow the the properUsage` section for your programming language

Usage (C/C++)

Add #include <libmem/libmem.h> (C) or #include <libmem/libmem.hpp> (C++) to your source code Link the generated libmem library against your binary (libmem.so for Unix-like or libmem.dll for Windows)

Usage (Rust)

Add the following line to your Cargo.toml under [dependencies]: toml libmem = "0.1.0" Import libmem in your Rust source code: rust use libmem::*;

Usage (Python)

Make sure to have Python >= 3.6 active
Either install the libmem package from PyPi by running the following command:
pip install --upgrade libmem Or build and install it yourself by running the following commands: cd libmem-py python configure.py python setup.py install Now to import libmem, just do the following in your Python code: py from libmem import *

Dependencies

All: - capstone (included in root project) - keystone (included in root project) - LIEF (included in root project) - libstdc++ (used in keystone and LIEF) - libmath (used in keystone)

Windows:
- Windows SDK (-luser32, -lpsapi)

Linux/Android:
- libdl (-ldl)

BSD:
- libdl (-ldl)
- libkvm (-lkvm) - libprocstat (-lprocstat)
- libelf (-lelf)

API Overview

``` LMEnumProcesses LMGetProcess LMFindProcess LMIsProcessAlive LM_GetSystemBits

LMEnumThreadIds LMEnumThreadIdsEx LMGetThreadId LMGetThreadIdEx

LMEnumModules LMEnumModulesEx LMFindModule LMFindModuleEx LMLoadModule LMLoadModuleEx LMUnloadModule LMUnloadModuleEx

LMEnumSymbols LMFindSymbolAddress

LMEnumPages LMEnumPagesEx LMGetPage LMGetPageEx

LMReadMemory LMReadMemoryEx LMWriteMemory LMWriteMemoryEx LMSetMemory LMSetMemoryEx LMProtMemory LMProtMemoryEx LMAllocMemory LMAllocMemoryEx LMFreeMemory LMFreeMemoryEx

LMDataScan LMDataScanEx LMPatternScan LMPatternScanEx LMSigScan LMSigScanEx

LMHookCode LMHookCodeEx LMUnhookCode LMUnhookCodeEx

LMAssemble LMAssembleEx LMFreeCodeBuffer LMDisassemble LMDisassembleEx LMFreeInstructions LMCodeLength LMCodeLengthEx ```

Projects

Made with libmem:
- AssaultCube Multihack
- X-Inject
- DirectX9 BaseHook
- DirectX11 BaseHook
- OpenGL BaseHook
- Counter-Strike 1.6 BaseHook
- Crazymem - NodeJS Memory Library