Package: libmem
Advanced Game Hacking Library (C/C++/Rust/Python) (Windows/Linux/FreeBSD)Made by rdboDiscord Serverhttps://discord.com/invite/Qw8jsPD99XLicenseThis project is licensed under theGNU AGPLv3.0(no later versions)ReadLICENSEfor more informationNOTE: Submodules and external dependencies might have their own licenses! Check for otherLICENSEfiles as well.FeaturesCross Platform (Windows/Linux/FreeBSD)Cross Architecture (x86/x64/ARM/ARM64)libmemcan:Find ProcessesFind ModulesFind SymbolsRead/Write/Set MemoryAllocate/Protect MemoryScan Memory by Pattern/SignatureHook/Unhook FunctionsAssemble/Dissassemble Code (JIT)Do VMT Hooking/UnhookingLoad/Unload ModulesGet Page InformationEnumerate Process ThreadsAnd much more!ExamplesFor more examples and API manual, access thedocumentationC/C++#include<libmem/libmem.h>intmain(){lm_module_tmod;lm_address_tmain_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);return0;}Rustuselibmem::*;fnsome_function(){// ...}fnhk_some_function(){// ...}unsafefntest(){// reading/writing memoryletnumber:i32=0;letnumber_addr=&numberas*consti32aslm_address_t;letvalue:i32=1337;LM_WriteMemory(number_addr,&value).unwrap();// write 1337 to numberletread_number:i32=LM_ReadMemory(number_addr).unwrap();println!("[*] Number Value: {}",read_number);// it will show 1337// hooking/detouring functionsletfunc_addr=some_functionas*const()aslm_address_t;lethk_addr=hk_some_functionas*const()aslm_address_t;println!("[*] Hooking 'some_function'");println!("[*] Original Address: {:#x}",func_addr);lettrampoline=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}fnmain(){unsafe{test();}}Pythonfromlibmemimport*# Assemble/Disassemble codeprint("[*] Assembly")inst=LM_Assemble("mov eax, ebx")print(f"{code}:{inst.bytes}")print("[*] Disassembly:")inst=LM_Disassemble(bytearray(b"\x55"))print(f"{inst.bytes}:{inst.mnemonic}{inst.op_str}")CMake Usage (without installing)Add the following commands to yourCMakeLists.txt.They will fetchlibmem-config.cmakefrom the root of this repository, which will download libmem binaries for your system and include libmem in your CMake project.include(FetchContent)# Download and set up libmemFetchContent_Declare(libmem-configURL"https://raw.githubusercontent.com/rdbo/libmem/config-v1/libmem-config.cmake"DOWNLOAD_NO_EXTRACTTRUE)FetchContent_MakeAvailable(libmem-config)set(CMAKE_PREFIX_PATH"${libmem-config_SOURCE_DIR}""${CMAKE_PREFIX_PATH}")set(LIBMEM_DOWNLOAD_VERSION"4.4.0")# Find libmem packagefind_package(libmemCONFIGREQUIRED)Use the following to link against libmem (NOTE: it might be necessary to link against other dependencies - go to theDependenciessection for more information):# Link against libmemtarget_link_libraries(<YOUR_TARGET_NAME>PRIVATElibmem::libmem)InstallingWindowsNote: If you download a binary version of libmem in the GitHub releases, you only need to install the Windows SDK. Building is not necessary, just addlibmem/includeto your project's include directories and link it against the binary you downloaded.Install the Windows SDK:Windows 7-Windows 10/11InstallPython 3(Check the option to add Python to PATH) (UsePython 3.8.9for Windows 7)InstallVisual Studio2022 or newer (with C++ support and CMake) (older versions might work, but they were not tested). NOTE: You can install only the Visual Studio Build Tools if you don't want the whole IDE.InstallGit BashRun a Visual StudioDeveloper Command Prompt(orx64 Native Tools Command Prompt for VS 2022for 64 bits) as AdministratorRun the following command to append libmem's destination directory to your%PATH%user variable (WARNING- watch for your%PATH%size limit!):setx PATH "%PATH%;%ProgramFiles%\libmem\include;%ProgramFiles%\libmem\lib"Continue reading atBuild and InstallLinuxNote: The following commands are for Debian/Ubuntu based distributions. Make sure to find the appropriate commands for your Linux distribution.Open a terminalInstall GCC, G++, Git, CMake, Make, Python 3, and the Linux headers:sudo apt install gcc g++ git cmake make python3 linux-headersContinue reading atBuild and InstallFreeBSDAdd a mountpoint for theprocfsfilesystem in your/etc/fstabby appending the following line:proc		/proc		procfs	rw	0	0Manually mount theprocfs. This will only be necessary if you don't reboot. If you reboot, it will be automatically mounted because of the line at/etc/fstab. Run the following command (as root):mount -t procfs proc /procInstall Git, CMake and Python3 (run as root) (clang, clang++ and make should already be installed):pkg install git cmake python3Continue reading atBuild and InstallBuild and InstallNote: Run the following commands on Git Bash (Windows) or a terminal (Linux/FreeBSD).Clone the repository:git clone --recursive --depth 1 https://github.com/rdbo/libmemGenerate the CMake cache:mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=ReleaseCompile libmem:Windows:nmakeUnix-like:make -j 4Install libmem (run as root or as Administrator):Windows:nmake installUnix-like:make installAfter installing, follow the the properUsagesection for your programming languageUsage (C/C++)Add#include <libmem/libmem.h>(C/C++) or#include <libmem/libmem.hpp>(C++) to your source code.
Link the generated libmem library against your binary (liblibmem.sofor Unix-like orlibmem.dllfor Windows).For GCC-like compilers: add the flag-llibmemto your compiler and it should link it.#include<libmem/libmem.h>/* C/C++ */#include<libmem/libmem.hpp>/* Force C++ */Usage (Rust)Add the following line to yourCargo.tomlunder[dependencies]:libmem="4"Import libmem in your Rust source code:uselibmem::*;Usage (Python)Make sure to have Python >= 3.6 activeEither install thelibmempackage from PyPi by running the following command:pip install --upgrade libmemOr build and install it yourself by running the following commands:cd libmem-py
python configure.py
python setup.py installNow to import libmem, just do the following in your Python code:fromlibmemimport*DependenciesAll:capstone (included in root project)keystone (included in root project)LIEF (included in root project)libstdc++ (used in keystone, LIEF and LLVM)libmath (used in keystone)Windows:Windows SDK (-luser32, -lpsapi, -lntdll)Linux/Android:libdl (-ldl)BSD:libdl (-ldl)libkvm (-lkvm)libprocstat (-lprocstat)libelf (-lelf)API OverviewLM_EnumProcesses
LM_GetProcess
LM_GetProcessEx
LM_FindProcess
LM_IsProcessAlive
LM_GetSystemBits

LM_EnumThreads
LM_EnumThreadsEx
LM_GetThread
LM_GetThreadEx
LM_GetThreadProcess

LM_EnumModules
LM_EnumModulesEx
LM_FindModule
LM_FindModuleEx
LM_LoadModule
LM_LoadModuleEx
LM_UnloadModule
LM_UnloadModuleEx

LM_EnumSymbols
LM_FindSymbolAddress
LM_DemangleSymbol
LM_FreeDemangleSymbol
LM_EnumSymbolsDemangled
LM_FindSymbolAddressDemangled

LM_EnumPages
LM_EnumPagesEx
LM_GetPage
LM_GetPageEx

LM_ReadMemory
LM_ReadMemoryEx
LM_WriteMemory
LM_WriteMemoryEx
LM_SetMemory
LM_SetMemoryEx
LM_ProtMemory
LM_ProtMemoryEx
LM_AllocMemory
LM_AllocMemoryEx
LM_FreeMemory
LM_FreeMemoryEx

LM_DataScan
LM_DataScanEx
LM_PatternScan
LM_PatternScanEx
LM_SigScan
LM_SigScanEx

LM_HookCode
LM_HookCodeEx
LM_UnhookCode
LM_UnhookCodeEx

LM_Assemble
LM_AssembleEx
LM_FreeCodeBuffer
LM_Disassemble
LM_DisassembleEx
LM_FreeInstructions
LM_CodeLength
LM_CodeLengthEx

LM_VmtNew
LM_VmtHook
LM_VmtUnhook
LM_VmtGetOriginal
LM_VmtReset
LM_VmtFreeProjectsMade with libmem:AssaultCube MultihackX-InjectDirectX9 BaseHookDirectX11 BaseHookOpenGL BaseHookCounter-Strike 1.6 BaseHookCrazymem - NodeJS Memory Library