Skip to main content

Overview

The Find Module APIs allow you to search for a specific module (library/DLL) by name and retrieve its information. You can search by exact name or relative path.

lm_module_t Structure

The lm_module_t structure contains information about a loaded module:
typedef struct lm_module_t {
    lm_address_t base;              // Base address of the module
    lm_address_t end;               // End address of the module
    lm_size_t    size;              // Size of the module in bytes
    lm_char_t    path[LM_PATH_MAX]; // Full path to the module
    lm_char_t    name[LM_PATH_MAX]; // Module name
} lm_module_t;

Fields

base
lm_address_t
Base address where the module is loaded in memory
end
lm_address_t
End address of the module in memory
size
lm_size_t
Total size of the module in bytes
path
lm_char_t[LM_PATH_MAX]
Full file system path to the module
name
lm_char_t[LM_PATH_MAX]
Name of the module (filename)

LM_FindModule

Finds a module by name and populates the module_out parameter with the found module information.

Signature

LM_API lm_bool_t LM_CALL
LM_FindModule(lm_string_t  name,
              lm_module_t *module_out);

Parameters

name
lm_string_t
required
The name of the module to find (e.g game.dll). It can also be a relative path, such as /game/hello for a module at /usr/share/game/hello.
module_out
lm_module_t*
required
A pointer to a lm_module_t structure. This function populates this structure with information about the found module, containing information such as base, end, size, path and name.

Returns

Returns LM_TRUE if the module is found successfully, otherwise it returns LM_FALSE.

Example

#include <libmem/libmem.h>
#include <stdio.h>

int main()
{
    lm_module_t game_mod;
    lm_address_t fn_take_damage;
    
    // Find the game module
    if (!LM_FindModule("game.dll", &game_mod)) {
        printf("Failed to find game.dll\n");
        return 1;
    }
    
    printf("[*] Base address of 'game.dll': %p\n", (void *)game_mod.base);
    printf("[*] Module size: %zu bytes\n", game_mod.size);
    printf("[*] Module path: %s\n", game_mod.path);
    
    // Find a function in the module
    fn_take_damage = LM_FindSymbolAddress(&game_mod, "take_damage");
    if (fn_take_damage != LM_ADDRESS_BAD) {
        printf("[*] Found 'take_damage' function: %p\n", (void *)fn_take_damage);
    }
    
    return 0;
}

LM_FindModuleEx

Finds a module by name in a specified process and populates the module_out parameter with the found module information.

Signature

LM_API lm_bool_t LM_CALL
LM_FindModuleEx(const lm_process_t *process,
                lm_string_t         name,
                lm_module_t        *module_out);

Parameters

process
const lm_process_t*
required
The process that the module will be searched in.
name
lm_string_t
required
The name of the module to find (e.g game.dll). It can also be a relative path, such as /game/hello for a module at /usr/share/game/hello.
module_out
lm_module_t*
required
A pointer to a lm_module_t structure. This function populates this structure with information about the found module, containing information such as base, end, size, path and name.

Returns

Returns LM_TRUE if the module is found successfully, otherwise it returns LM_FALSE.

Example

#include <libmem/libmem.h>
#include <stdio.h>

int main()
{
    lm_process_t game_process;
    lm_module_t client_module;
    
    // Find the target process
    if (!LM_FindProcess("game_linux64", &game_process)) {
        printf("Failed to find game process\n");
        return 1;
    }
    
    printf("[*] Found process: %s (PID: %d)\n", game_process.name, game_process.pid);
    
    // Find a module in the target process
    if (!LM_FindModuleEx(&game_process, "libclient.so", &client_module)) {
        printf("Failed to find libclient.so\n");
        return 1;
    }
    
    printf("[*] Found module: %s\n", client_module.name);
    printf("[*] Base address: %p\n", (void *)client_module.base);
    printf("[*] Size: %zu bytes\n", client_module.size);
    
    return 0;
}

Usage with Relative Paths

Both functions support relative path matching, which is useful when the full path is too long or when you want to match modules in subdirectories:
lm_module_t module;

// These are all valid ways to find a module:
LM_FindModule("game.dll", &module);           // Exact filename
LM_FindModule("/plugins/mod.so", &module);     // Relative path
LM_FindModule("libengine.so.1", &module);      // Full filename with version

See Also

Build docs developers (and LLMs) love