Skip to main content
This guide demonstrates the fundamental operations for reading and writing memory in both the current process and external processes.

Reading Memory

To read memory from a specific address, use LM_ReadMemory for the current process or LM_ReadMemoryEx for external processes.
#include <libmem/libmem.h>

lm_address_t source_addr = 0x12345678;
lm_byte_t buffer[256];
lm_size_t bytes_read;

// Read from current process
bytes_read = LM_ReadMemory(source_addr, buffer, sizeof(buffer));
printf("Read %zu bytes\n", bytes_read);

// Read from external process
lm_process_t target_process;
LM_FindProcess("game.exe", &target_process);
bytes_read = LM_ReadMemoryEx(&target_process, source_addr, buffer, sizeof(buffer));

Writing Memory

To write data to memory, use LM_WriteMemory for the current process or LM_WriteMemoryEx for external processes.
#include <libmem/libmem.h>

lm_address_t dest_addr = 0x12345678;
lm_byte_t data[] = {0xDE, 0xAD, 0xBE, 0xEF};
lm_size_t bytes_written;

// Write to current process
bytes_written = LM_WriteMemory(dest_addr, data, sizeof(data));
printf("Wrote %zu bytes\n", bytes_written);

// Write to external process
lm_process_t target_process;
LM_FindProcess("game.exe", &target_process);
bytes_written = LM_WriteMemoryEx(&target_process, dest_addr, data, sizeof(data));

Setting Memory

You can fill a memory region with a specific byte value using LM_SetMemory or LM_SetMemoryEx.
#include <libmem/libmem.h>

lm_address_t dest_addr = 0x12345678;
lm_size_t region_size = 1024;
lm_byte_t fill_byte = 0x90; // NOP instruction

// Fill memory in current process
lm_size_t bytes_set = LM_SetMemory(dest_addr, fill_byte, region_size);
printf("Set %zu bytes to 0x%02X\n", bytes_set, fill_byte);

Key Concepts

  • Internal vs External: Functions without the Ex suffix operate on the current process, while Ex variants work on external processes
  • Return Values: Memory functions return the number of bytes successfully read/written, which may be less than requested if an error occurs
  • Process Handle: External operations require a valid lm_process_t structure obtained from functions like LM_FindProcess

Next Steps

Pattern Scanning

Learn to find specific byte patterns in memory

Pointer Chains

Resolve multi-level pointer chains

Build docs developers (and LLMs) love