Skip to content

Instantly share code, notes, and snippets.

@NSEcho
Created March 22, 2023 09:39
Show Gist options
  • Save NSEcho/be4cea70f444638a9a5103eb278de6cd to your computer and use it in GitHub Desktop.
Save NSEcho/be4cea70f444638a9a5103eb278de6cd to your computer and use it in GitHub Desktop.
LLDB dlopen and dlsym

Minimal dynamic library with one function in it.

#include <stdio.h>

void hello(const char *name) {
    printf("hello %s\n", name);
}
$ gcc -dynamiclib /tmp/dynamic.c -o /tmp/dynamic.dylib
$ lldb ...
(lldb) expr int $RTLD_LAZY = 1
(lldb) expr void* $handle = (void*)dlopen("/tmp/dynamic.dylib", $RTLD_LAZY)
(lldb) expr void* $address = (void*)dlsym($handle, "hello")
(lldb) expr ((void(*)(char*))$address)("there")
hello there
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment