jailbreak - iOS 6.1 Dynamic Library build and link -
i trying create dynamic library ios , load @ runtime. after taking @ this question , this answer, have been doing using iosopendev , deploying on iphone. xcode project dylib called kdylibtwo , files modiefied are:
kdylibtwo.h
#import <foundation/foundation.h> @interface kdylibtwo : nsobject -(void)run; @end
kdylibtwo.m
#import "kdylibtwo.h" @implementation kdylibtwo -(id)init { if ((self = [super init])) { } return self; } -(void)run{ nslog(@"kdylibtwo loadded."); } @end
in order test if library works, after building profiling (the way iosopendev deploys on iphone), can find stored on device @ /usr/lib/libkdylibtwo.dylib
, built tweak (again using iosopendev), hooking springboard follows:
#include <dlfcn.h> %hook sbapplicationicon -(void)launch{ nslog(@"\n\n\n\n\n\n\nsbhook libkdylibtwo.dylib"); void* dyliblink = dlopen("/usr/lib/libkdylibtwo.dylib", rtld_now); if(dyliblink == null) { nslog(@"loading failed."); } else { nslog(@"dylib loaded."); void (*function)(void); *(void **)(&function) = dlsym(dyliblink, "run"); if (function) { nslog(@"function found."); (*function)(); } else { nslog(@"function not found"); } } nslog(@"end of code"); %log; %orig; } %end
after installing tweak on device , tapping on icon (that fire hooked code), console output looks like:
aug 28 13:03:35 pudge springboard[18254] <warning>: sbhook libkdylibtwo.dylib aug 28 13:03:35 pudge springboard[18254] <warning>: dylib loaded. aug 28 13:03:35 pudge springboard[18254] <warning>: function not found aug 28 13:03:35 pudge springboard[18254] <warning>: end of code aug 28 13:03:35 pudge springboard[18254] <warning>: -[<sbapplicationicon: 0x1d5008c0> launch]
my question doing wrong , the library's function not called or executed! think should clarify talking jailbroken devices , not app store development, please don't go ahead posting cannot done!
thank in advance,
panagiotis.
as victor ronin pointed out, "dlsym" c symbols. obtain objective-c class dylib linked @ runtime can use objc runtime functions. in case:
void* dyliblink = dlopen("/usr/lib/libkdylibtwo.dylib", rtld_now); id kdylibtwo = [[objc_getclass("kdylibtwo") alloc] init]; [kdylibtwo run];
first line linking library @ runtime. required in order use code inside of it.
second line creates instance of class kdylibtwo
. objc_getclass
function returns class object can later use create instances of class objective-c class - using alloc
, init
methods. once obtained class object objc_getclass
can work him nothing happend. @ point can forget dynamically linked library @ runtime.
third line calling run
method. can see, it's normal objective-c syntax. nothing changed because linked library @ runtime. can call method want.
Comments
Post a Comment