Created
April 17, 2024 00:46
-
-
Save misyltoad/a4899fd26f1e22e23df71fa965fe4514 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <pipewire/pipewire.h> | |
#include <pthread.h> | |
#include <dlfcn.h> | |
static pthread_once_t lib_once = PTHREAD_ONCE_INIT; | |
static void *pw_lib = NULL; | |
static void load_pw_lib(void) | |
{ | |
pw_lib = dlopen("/usr/lib/libpipewire-0.3.so", RTLD_NOW); | |
} | |
static void *load_pw_func(const char *name) | |
{ | |
pthread_once(&lib_once, load_pw_lib); | |
return dlsym(pw_lib, name); | |
} | |
static pthread_once_t pfn_pw_context_connect_once = PTHREAD_ONCE_INIT; | |
static typeof(pw_context_connect)* pfn_pw_context_connect; | |
static void load_pw_context_connect(void) { pfn_pw_context_connect = (typeof(pfn_pw_context_connect)) load_pw_func("pw_context_connect"); } | |
struct pw_core *pw_context_connect(struct pw_context *context, | |
struct pw_properties *properties, | |
size_t user_data_size) | |
{ | |
struct pw_permission permissions[] = | |
{ | |
{ PW_ID_CORE, PW_PERM_RWX }, | |
{ 65, PW_PERM_RWX }, | |
{ 69, PW_PERM_RWX }, | |
{ 70, PW_PERM_RWX }, | |
{ 71, PW_PERM_RWX }, | |
{ 72, PW_PERM_RWX }, | |
{ 73, PW_PERM_RWX }, | |
{ 74, PW_PERM_RWX }, | |
{ 75, PW_PERM_RWX }, | |
{ 76, PW_PERM_RWX }, | |
{ 77, PW_PERM_RWX }, | |
{ PW_ID_ANY, PW_PERM_R }, | |
}; | |
pthread_once(&pfn_pw_context_connect_once, load_pw_context_connect); | |
fprintf(stderr, "[pw-namespace] Hooking pw_context_connect\n"); | |
struct pw_core *core = (*pfn_pw_context_connect)(context, properties, user_data_size); | |
if (!core) | |
return NULL; | |
pw_client_update_permissions( | |
pw_core_get_client(core), | |
12, | |
permissions); | |
return core; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment