Skip to main content

LM_GetThread

Retrieves information about the thread it’s running from.

Function Signature

LM_API lm_bool_t LM_CALL
LM_GetThread(lm_thread_t *thread_out);

Parameters

thread_out
lm_thread_t *
required
A pointer to the lm_thread_t structure that will be populated with information about the current thread, specifically the thread ID (tid) and the process ID (owner_pid).

Return Value

return
lm_bool_t
Returns LM_TRUE if the thread information was successfully retrieved and stored in the provided lm_thread_t structure. Otherwise, returns LM_FALSE.

Example

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

int main()
{
    lm_thread_t thread;
    
    if (LM_GetThread(&thread)) {
        printf("Current thread TID: %u\n", thread.tid);
        printf("Owner process PID: %u\n", thread.owner_pid);
    } else {
        printf("Failed to get current thread information\n");
    }
    
    return 0;
}

LM_GetThreadEx

Retrieves information about a thread in a process.

Function Signature

LM_API lm_bool_t LM_CALL
LM_GetThreadEx(const lm_process_t *process,
               lm_thread_t        *thread_out);

Parameters

process
const lm_process_t *
required
The process that the thread will be retrieved from.
thread_out
lm_thread_t *
required
A pointer to the lm_thread_t variable where the function will store the thread information retrieved from the process.

Return Value

return
lm_bool_t
Returns LM_TRUE if the thread was retrieved successfully, or LM_FALSE if it fails.

Example

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

int main()
{
    lm_process_t process;
    lm_thread_t thread;
    
    // Find target process
    if (!LM_FindProcess("target.exe", &process)) {
        printf("Failed to find process\n");
        return 1;
    }
    
    // Get a thread from the target process
    if (LM_GetThreadEx(&process, &thread)) {
        printf("Retrieved thread from process %u:\n", process.pid);
        printf("  TID: %u\n", thread.tid);
        printf("  Owner PID: %u\n", thread.owner_pid);
    } else {
        printf("Failed to get thread from process\n");
    }
    
    return 0;
}

LM_GetThreadProcess

Retrieves the process that owns a given thread.

Function Signature

LM_API lm_bool_t LM_CALL
LM_GetThreadProcess(const lm_thread_t *thread,
                    lm_process_t      *process_out);

Parameters

thread
const lm_thread_t *
required
The thread whose process will be retrieved.
process_out
lm_process_t *
required
A pointer to the lm_process_t structure where the function will store the process information related to the given thread.

Return Value

return
lm_bool_t
Returns LM_TRUE if the operation was successful or LM_FALSE otherwise.

Example

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

int main()
{
    lm_thread_t thread;
    lm_process_t process;
    
    // Get current thread
    if (!LM_GetThread(&thread)) {
        printf("Failed to get current thread\n");
        return 1;
    }
    
    // Get the process that owns this thread
    if (LM_GetThreadProcess(&thread, &process)) {
        printf("Thread %u belongs to process:\n", thread.tid);
        printf("  PID: %u\n", process.pid);
        printf("  Name: %s\n", process.name);
        printf("  Path: %s\n", process.path);
        printf("  Architecture: %u-bit\n", process.bits);
    } else {
        printf("Failed to get thread process\n");
    }
    
    return 0;
}

Thread Structure

The lm_thread_t structure contains information about a thread:
typedef struct lm_thread_t {
    lm_tid_t tid;       // Thread ID
    lm_pid_t owner_pid; // Process ID that owns this thread
} lm_thread_t;

Fields

tid
lm_tid_t
The thread identifier (TID). This is a unique identifier for the thread within the system.
owner_pid
lm_pid_t
The process identifier (PID) of the process that owns this thread.
  • lm_tid_t - Thread identifier type (typedef of uint32_t)
  • lm_pid_t - Process identifier type (typedef of uint32_t)

Build docs developers (and LLMs) love