IOS uses dynamic libraries (DYLIB) and dynamically loads the framework

Source: Internet
Author: User

Many of the dylib files that use dynamic libraries on the iphone are available using the standard Dlopen method. The same can be dynamically loaded using the framework file as a dynamic library, so you can use the Apple private framework more freely.

Dlopen is to open the library file

Dlsym is the Get function address

Dlclose is off.

Of course, there are obvious drawbacks to using this approach, which is that you will not be able to continue unless you know the function name and parameters.

The private library header file can be exported using class dump, which requires Google in detail.

Here are two examples of use

1: This is using coretelephony.framework to get IMSI

#define Private_path "/system/library/privateframeworks/coretelephony.framework/coretelephony"

Implement Viewdidload to does additional setup after loading the view, typically from a nib.
-(void) Viewdidload {
[Super Viewdidload];
#if! Target_iphone_simulator
void *kit = Dlopen (Private_path,rtld_lazy);
NSString *imsi = nil;
Int (*ctsimsupportcopymobilesubscriberidentity) () = Dlsym (Kit, "ctsimsupportcopymobilesubscriberidentity");
IMSI = (nsstring*) ctsimsupportcopymobilesubscriberidentity (nil);
Dlclose (Kit);

Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "IMSI"
Message:imsi
Delegate:self
cancelbuttontitle:@ "OK"
Otherbuttontitles:nil];
[Alert show];
[Alert release];
#endif
}

2: This is the use of springboardservices.framework to set the flight mode switch

#ifdef SUPPORTS_UNDOCUMENTED_API
#define Sbservpath "/system/library/privateframeworks/springboardservices.framework/springboardservices"
#define Uikitpath "/system/library/framework/uikit.framework/uikit"

Don ' t use this code in real life, boys and girls. It's not App Store friendly.
It's, however, really nice for testing callbacks
+ (void) Setairplanemode: (BOOL) status;
{
mach_port_t *theport;
void *uikit = Dlopen (Uikitpath, Rtld_lazy);
Int (*sbsspringboardserverport) () = Dlsym (Uikit, "Sbsspringboardserverport");
Theport = (mach_port_t *) Sbsspringboardserverport ();
Dlclose (Uikit);

Link to Sbsetairplanemodeenabled
void *sbserv = Dlopen (Sbservpath, Rtld_lazy);
Int (*setapmode) (mach_port_t* port, BOOL status) = Dlsym (Sbserv, "sbsetairplanemodeenabled");
Setapmode (Theport, status);
Dlclose (Sbserv);
}
#endif

iphone Sprintboard Partial Private API Summary

This article describes some of the private APIs for the iOS Srpintboard framework, including:

    • Get bundle IDs for all apps that are currently running on iOS (whether the current program is in the foreground or in the background)
    • Gets the bundle ID of the app running in the current foreground on iOS (whether the current program is available in the foreground or in the background)
    • Get the app name and icon based on the bundle ID of your iOS app (whether it's available in the foreground or in the background)
    • Run the app directly from the bundle ID of the app, without using URL scheme (only if the program is running in the foreground, if the app can run other apps in the background, it's invincible @[email protected])

(1) initialization

void * Uikit = Dlopen ("/system/library/framework/uikit.framework/uikit", Rtld_lazy);

Int (*sbsspringboardserverport) () =

Dlsym (Uikit, "Sbsspringboardserverport");

p = (mach_port_t *) Sbsspringboardserverport ();

Dlclose (Uikit);

Sbserv = Dlopen (Sbservpath, Rtld_lazy);

(2) Get a list of bundle IDs for all running apps on iphone

nsarray* (*sbscopyapplicationdisplayidentifiers) (mach_port_t* port, BOOL runningapps,bool debuggablet) =

Dlsym (Sbserv, "sbscopyapplicationdisplayidentifiers");

Nsarray *currentrunningappbundleidarray= sbscopyapplicationdisplayidentifiers (P,NO,YES);

(3) The bundle ID of the app that got the iphone foreground running

void* (*sbfrontmostapplicationdisplayidentifier) (mach_port_t* Port,char * result) = Dlsym (Sbserv, " Sbfrontmostapplicationdisplayidentifier ");

Char topapp[256];

Sbfrontmostapplicationdisplayidentifier (P,topapp);

currenttopappbundleid=[nsstringstringwithformat:@ "%s", Topapp];

(4) Get the app name based on the bundle ID of the iphone app

NSString * (*sbscopylocalizedapplicationnamefordisplayidentifier) (nsstring*) = Dlsym (Sbserv, " Sbscopylocalizedapplicationnamefordisplayidentifier ");

NSString *strappname = Sbscopylocalizedapplicationnamefordisplayidentifier (Strbundleid);

(5) Get its icon based on the bundle ID of the iphone app

nsdata* (*sbscopyiconimagepngdatafordisplayidentifier) (NSString * Bundleid) =

Dlsym (Sbserv, "sbscopyiconimagepngdatafordisplayidentifier");

UIImage *icon = nil;

NSData *icondata = Sbscopyiconimagepngdatafordisplayidentifier (Bundleid);

if (icondata! = nil) {

icon = [UIImage imagewithdata:icondata];

}

return icon;

(6) Run the app directly from the bundle ID of the app

In iOS, one app usually uses a URL scheme to adjust another app, but with this private app, you can run any app without a URL scheme.

-(void) Openappbybundleid: (nsstring*) Bundleid

{

void* sbservices = Dlopen ("/system/library/privateframeworks/springboardservices.framework/springboardservices", Rtld_lazy);

Int (*sbslaunchapplicationwithidentifier) (cfstringref identifier, Boolean suspended) = Dlsym (Sbservices, " Sbslaunchapplicationwithidentifier ");

const char *strbundleid = [Bundleid cstringusingencoding:nsutf8stringencoding];

int result = Sbslaunchapplicationwithidentifier ((__bridge cfstringref) Bundleid, NO);

Dlclose (sbservices);

}

IOS uses dynamic libraries (DYLIB) and dynamically loads the framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.