LM_CodeLength
Calculates the instruction-aligned size based on a minimum length requirement.The memory address of the instructions to measure.
The minimum size in bytes that should be covered by complete instructions.
Returns the size aligned to the next complete instruction boundary on success, or
0 on failure.This function is useful when you need to overwrite code with a hook or patch, and you want to ensure you don’t split an instruction in half. For example, if you need at least 5 bytes for a jump instruction,
LM_CodeLength will tell you the actual number of bytes you need to overwrite to maintain instruction boundaries.Example
If you need to write a 5-byte jump but the first instruction at the target is 3 bytes and the second is 4 bytes:min_length = 5would return7(3 + 4 bytes)- This ensures you overwrite complete instructions without breaking code execution
LM_CodeLengthEx
Calculates the instruction-aligned size in a remote process based on a minimum length requirement.Pointer to the remote process structure.
The memory address of the instructions in the remote process.
The minimum size in bytes that should be covered by complete instructions.
Returns the size aligned to the next complete instruction boundary on success, or
0 on failure.LM_GetArchitecture
Returns the current process architecture.Returns the architecture of the current process:
LM_ARCH_X86- x86 32-bitLM_ARCH_X64- x86 64-bitLM_ARCH_ARMV7- ARMv7LM_ARCH_ARMV8- ARMv8LM_ARCH_AARCH64- ARM64/AArch64LM_ARCH_THUMBV7- ARMv7 Thumb modeLM_ARCH_THUMBV8- ARMv8 Thumb modeLM_ARCH_MIPS,LM_ARCH_MIPS64- MIPS variantsLM_ARCH_PPC32,LM_ARCH_PPC64- PowerPC variants- And more (see full enum in libmem.h)
The architecture returned by this function is automatically detected based on the compilation target and runtime environment.
Architecture Constants
Thelm_arch_t enum defines all supported architectures: