1
+ #include <stdlib.h>
2
+ // #include <stdbool.h>
3
+ // #include <unistd.h>
4
+ #include <dlfcn.h>
5
+ // #include <string.h>
6
+
7
+
8
+
9
+ static void * tp1801_gui_lib = NULL ;
10
+ static uint32_t (* setChannelPilotOriginal )(void * this ,unsigned short param_1 , bool param_2 ) = 0 ;
11
+ static uint32_t (* userSettingsGetInstanceOriginal )() = 0 ;
12
+ static uint32_t userSettingsInstance = 0 ;
13
+
14
+ void changeChannel (uint16_t channelIdx ) {
15
+ //Load SetPilotChannel original
16
+ setChannelPilotOriginal = dlsym (RTLD_NEXT , "_ZN17GlassUserSettings15setPilotChannelEtb" );
17
+ if (setChannelPilotOriginal == NULL ) {
18
+ if (!tp1801_gui_lib ){
19
+ tp1801_gui_lib = dlopen ("/system/lib/libtp1801_gui.so" , 1 );
20
+ }
21
+ setChannelPilotOriginal = dlsym (tp1801_gui_lib , "_ZN17GlassUserSettings15setPilotChannelEtb" );
22
+ if (setChannelPilotOriginal == NULL )
23
+ {
24
+ printf ("dlsym: %s\n" , dlerror ());
25
+ return ;
26
+ }
27
+ }
28
+
29
+ //Load UserSettingGetInstance original
30
+ userSettingsGetInstanceOriginal = dlsym (tp1801_gui_lib , "_ZN17GlassUserSettings11getInstanceEv" );
31
+ if (userSettingsGetInstanceOriginal == NULL )
32
+ {
33
+ printf ("dlsym: %s\n" , dlerror ());
34
+ return ;
35
+ }
36
+
37
+ //Get the intance from the previous method
38
+ if (!userSettingsInstance ) userSettingsInstance = userSettingsGetInstanceOriginal ();
39
+ if (!userSettingsInstance ) {
40
+ printf ("dlsym: %s\n" , dlerror ());
41
+ return ;
42
+ }
43
+
44
+ //Do stuff
45
+ //setChannelPilotOriginal(userSettingsInstance, channelIdx, 1); //Can I pass the instance directly or need to be a function pointer?
46
+ setChannelPilotOriginal (userSettingsGetInstanceOriginal (), channelIdx , true);
47
+ }
0 commit comments