Difference between revisions of "Libhide"

From iPhone Development Wiki
Jump to: navigation, search
Line 65: Line 65:
  
 
* '''libhide''' is opensource and you can grab it from [https://github.com/big-boss/Libhide Github]
 
* '''libhide''' is opensource and you can grab it from [https://github.com/big-boss/Libhide Github]
 +
* [http://moreinfo.thebigboss.org/moreinfo/depiction.php?file=libhideDp Libhide Package]
  
 
{{Navbox Library}}
 
{{Navbox Library}}
 
 
 
[[Category:Directories in /Library]]
 
[[Category:Directories in /Library]]

Revision as of 21:53, 14 April 2014

Libhide
Cydia Package
Developer BigBoss
Package ID libhide
Latest Version 2.4.1-1


What is libhide?

libhide is a library which allows you to hide / unhide icons on SpringBoard. If for example you are loading a Preference Bundle into your Application, you can hide the SpringBoard Icon, or let the user decide wether to hide it or not because you still have the Application Bundle in your Preferences app.

Dynamic Loader

In order to load the library and to execute its functions you can use the implementations of the dynamic linking loader: dlopen(), dlsym(), dlclose() and dlerror().

  • dlerror() returns a human readable error message of an error for dlopen and dlsym or NULL if there is no error.
  • dlopen() loads the dynamic library using the null terminated path given as the parameter. the second parameter expects a flag on how to load the library
  • dlsym() takes a 'handle' returned by dlopen and a symbol name to lookup. It returns either the address of the symbol or NULL if it was not found.

Some Code

We first declare our static functions which will initialize from the dynamic library

#import <dlcfn.h>

static void *libhide;
static BOOL (*IsIconHiddenForDisplayID)(NSString *displayID); //a method to determine if the icon is already hidden or not
static BOOL (*HideIconViaDisplayID)(NSString *displayID); //hides the icon for the display identifier
static BOOL (*UnHideIconViaDisplayID)(NSString *displayID); //unhides the icon
static NSString *appDisplayID = @"com.yourcompany.appdisplayid"; //our bundle identifier

Next we will initialize our functions so we are able to call them.

libhide = dlopen("/usr/lib/hide.dylib", RTLD_LAZY);

The flag RTLD_LAZY performs lazy binding, which means it only resolves symbols as the code that references them is executed. If the symbol is never referenced, it is never resolved. Lazy binding is only performed for functions, variables are bound when the library is loaded.

IsIconHiddenForDisplayID = reinterprete_cast<BOOL (*)(NSString *)>
                                                     (dlsym(libhide,"IsIconHiddenDisplayId"));
HideIconViaDisplayID = reinterprete_cast<BOOL (*)(NSString *)>
                                                     (dlsym(libhide,"HideIconViaDisplayId"));
UnHideIconViaDisplayID = reinterprete_cast<BOOL (*)(NSString *)>
                                                     (dlsym(libhide,"UnHideIconViaDisplayId"));

Now we are able to simply call those three functions as normal functions. Like so:

if (IsIconHiddenForDisplayID(appDisplayID)) {
       UnHideIconViaDisplayID(appDisplayID);
} else {
      HideIconViaDisplayID(appDisplayID);
}

This is almost all about libhide. You can easily hide the Icon for your Application.

External Links