forked from big-boss/Libhide
-
Notifications
You must be signed in to change notification settings - Fork 2
/
hide-sample.c
executable file
·151 lines (128 loc) · 5.27 KB
/
hide-sample.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// PlistPath is the full path to the app's Info.plist file for example:
// /Applications/MobileSafari.app/Info.plist
//
// There are exceptions allowed for camera and photos. You should use these:
// /Applications/Camera.app/Info.plist
// /Applications/Photos.app/Info.plist
//
//*************************************************************************************************
// IsIconHidden - Determines if the icon passed in is already hidden or not.
// PlistPath is the full path to the Info.plist for the app.
//*************************************************************************************************
BOOL IsIconHidden(NSString* PlistPath)
{
BOOL Hidden = NO;
void* libHandle = dlopen("/usr/lib/hide.dylib", RTLD_LAZY);
if(libHandle != NULL)
{
BOOL (*IsIconHidden)(NSString* Plist) = dlsym(libHandle, "IsIconHidden");
if(IsIconHidden != NULL)
{
Hidden = IsIconHidden(PlistPath);
}
dlclose(libHandle);
}
return Hidden;
}
//*************************************************************************************************
// IsIconHidden - Determines if the icon passed in is already hidden or not via the display identifier
// BundleId is the bundle identifier out of the Info.plist for the app.
//*************************************************************************************************
BOOL IsIconHiddenDisplay(NSString* BundleId)
{
BOOL Hidden = NO;
void* libHandle = dlopen("/usr/lib/hide.dylib", RTLD_LAZY);
if(libHandle != NULL)
{
BOOL (*IsIconHiddenDisplayId)(NSString* Plist) = dlsym(libHandle, "IsIconHiddenDisplayId");
if(IsIconHiddenDisplayId != NULL)
{
Hidden = IsIconHiddenDisplayId(BundleId);
}
dlclose(libHandle);
}
return Hidden;
}
//*************************************************************************************************
// HideIcon - Hides the icon at the path passed in.
// PlistPath is the full path to the Info.plist for the app.
//*************************************************************************************************
BOOL HideIcon(NSString* PlistPath)
{
NSLog(@"Hiding %@\n", PlistPath);
void* libHandle = dlopen("/usr/lib/hide.dylib", RTLD_LAZY);
BOOL DeletedSomething = NO;
if(libHandle != NULL)
{
BOOL (*LibHideIcon)(NSString* Plist) = dlsym(libHandle, "HideIcon");
if(LibHideIcon != NULL)
{
// PlistPath is the full path to the plist like "/Applications/BossPrefs.app/Info.plist"
DeletedSomething = LibHideIcon(PlistPath);
}
dlclose(libHandle);
}
return DeletedSomething;
}
//*************************************************************************************************
// HideIconViaDisplayId - Hides the icon using the bundle ID passed in.
// BundleId is the bundle identifier out of the Info.plist for the app.
//*************************************************************************************************
BOOL HideIconViaDisplayId(NSString* BundleId)
{
void* libHandle = dlopen("/usr/lib/hide.dylib", RTLD_LAZY);
BOOL DeletedSomething = NO;
if(libHandle != NULL)
{
BOOL (*LibHideIcon)(NSString* Plist) = dlsym(libHandle, "HideIconViaDisplayId");
if(LibHideIcon != NULL)
{
DeletedSomething = LibHideIcon(BundleId);
}
dlclose(libHandle);
}
return DeletedSomething;
}
//*************************************************************************************************
// UnHideIcon - Removes a hidden icon from the plist. Returns TRUE if something was done, FALSE ir not.
// PlistPath is the full path to the Info.plist for the app.
//*************************************************************************************************
BOOL UnHideIcon(NSString* Path)
{
BOOL SomethingDone = NO;
void* libHandle = dlopen("/usr/lib/hide.dylib", RTLD_LAZY);
if(libHandle != NULL)
{
BOOL (* LibUnHideIcon)(NSString* Plist) = dlsym(libHandle, "UnHideIcon");
if(LibUnHideIcon != NULL)
{
SomethingDone = LibUnHideIcon(Path);
}
dlclose(libHandle);
}
return SomethingDone;
}
//*************************************************************************************************
// UnHideIconViaDisplayId - Removes a hidden icon from the plist. Returns TRUE if something was done, FALSE ir not.
// BundleId is the bundle identifier out of the Info.plist for the app.
//*************************************************************************************************
BOOL UnHideIconViaDisplayId(NSString* BundleId)
{
BOOL SomethingDone = NO;
void* libHandle = dlopen("/usr/lib/hide.dylib", RTLD_LAZY);
if(libHandle != NULL)
{
BOOL (* LibUnHideIcon)(NSString* BundleId) = dlsym(libHandle, "UnHideIconViaDisplayId");
if(LibUnHideIcon != NULL)
{
SomethingDone = LibUnHideIcon(BundleId);
}
dlclose(libHandle);
}
return SomethingDone;
}
//*************************************************************************************************
// Cause changes to take effect without respring (v2.0.6 or newer only)
// just issue notify_post (may need to #include <notify.h>
// notify_post("com.libhide.hiddeniconschanged);
//*************************************************************************************************