1+ #include <dlfcn.h>
2+ #include <memory.h>
3+ #include <logging.h>
4+
5+ #ifdef __LP64__
6+ #define LIB "/system/lib64/libmemtrack.so"
7+ #else
8+ #define LIB "/system/lib/libmemtrack.so"
9+ #endif
10+
11+ static void * riru_handle ;
12+ static char * riru_module_name ;
13+
14+ static void * get_handle () {
15+ if (riru_handle == NULL )
16+ riru_handle = dlopen (LIB , RTLD_NOW | RTLD_GLOBAL );
17+
18+ return riru_handle ;
19+ }
20+
21+ const char * riru_get_module_name () {
22+ return riru_module_name ;
23+ }
24+
25+ void riru_set_module_name (const char * name ) {
26+ riru_module_name = strdup (name );
27+ }
28+
29+ int riru_get_version () {
30+ static void * * sym ;
31+ void * handle ;
32+ if ((handle = get_handle ()) == NULL ) return -1 ;
33+ if (sym == NULL ) sym = dlsym (handle , "riru_get_version" );
34+ if (sym ) return ((int (* )()) sym )();
35+ return -1 ;
36+ }
37+
38+ void * riru_get_func (const char * name ) {
39+ static void * * sym ;
40+ void * handle ;
41+ if ((handle = get_handle ()) == NULL ) return NULL ;
42+ if (sym == NULL ) sym = dlsym (handle , "riru_get_func" );
43+ if (sym ) return ((void * (* )(const char * , const char * )) sym )(riru_get_module_name (), name );
44+ return NULL ;
45+ }
46+
47+ void * riru_get_native_method_func (const char * className , const char * name , const char * signature ) {
48+ static void * * sym ;
49+ void * handle ;
50+ if ((handle = get_handle ()) == NULL ) return NULL ;
51+ if (sym == NULL ) sym = dlsym (handle , "riru_get_native_method_func" );
52+ if (sym )
53+ return ((void * (* )(const char * , const char * , const char * , const char * )) sym )(
54+ riru_get_module_name (), className , name , signature );
55+ return NULL ;
56+ }
57+
58+ void riru_set_func (const char * name , void * func ) {
59+ static void * * sym ;
60+ void * handle ;
61+ if ((handle = get_handle ()) == NULL ) return ;
62+ if (sym == NULL ) sym = dlsym (handle , "riru_set_func" );
63+ if (sym )
64+ ((void * (* )(const char * , const char * , void * )) sym )(riru_get_module_name (), name , func );
65+ }
66+
67+ void riru_set_native_method_func (const char * className , const char * name , const char * signature ,
68+ void * func ) {
69+ static void * * sym ;
70+ void * handle ;
71+ if ((handle = get_handle ()) == NULL ) return ;
72+ if (sym == NULL ) sym = dlsym (handle , "riru_set_native_method_func" );
73+ if (sym )
74+ ((void * (* )(const char * , const char * , const char * , const char * , void * )) sym )(
75+ riru_get_module_name (), className , name , signature , func );
76+ }
0 commit comments