views:

512

answers:

3

Hi there.

I am working on mobilesubstrate plugins on a JB iPhone. i have created a dylib in xcode for my iphone which builds fine for Device, but when i try to build it for Simulator, it gives me an error "_MSHOOKMESSAGE reference from: blah blah". I have placed all the headers in proper locations. I got libsubstrate from device but that is i think the problem. The libsubstrate from device is not gonna work for Simulator. So my question is how to create a libsubstrate for Simulator?

+1  A: 

If you simply need to use MSHookMessageEx (which superseded MSHookMessage), you can

#define MSHookMessageEx(class, selector, replacement, result) \
 (*(result) = method_setImplementation(class_getInstanceMethod((class), (selector)), (replacement)))

Of course, MSHookMessageEx in Mobile Substrate is more complex than this, but for testing purpose this is usually enough.

KennyTM
ohh thanks for the reply.Can you please help me in using this too? I mean how to use it if i m hooking to SBApplicationIcon?Currently i have this code`Class _$SBAppIcon = objc_getClass("SBApplicationIcon");`MSHookMessage(_$SBAppIcon,@selector(launch), (IMP) `i got this code from some forum, and trying to learn that.
raziiq
@raziiq: Yes. But the 4th argument should be a pointer to an `IMP` to receive the original launch method.
KennyTM
oh yes , nil should be replaced by something like "__Original_Method", right?I am using the above mentioned code, but as i described in my question, i am getting that error of _MSHookMessage. So in order to use the method you just described, how can i change my code to the one you just described?
raziiq
@raziiq: Yes, you should use `MSHookMessageEx`. (Don't insert this macro on the actual device though, as `libsubstrate` does provide the actual implementation.)
KennyTM
A: 

Thanks for the reply KennyTM. I have changed my code to his after your advice.

#define MSHookMessageEx(class, selector,replacement,result) \
(*(result) = method_setImplementation(class_getInstanceMethod((class), (selector)), (replacement)))

static IMP original_Launch;

static void __$AnotherCheck_AppIcon_Launch(SBApplicationIcon *_SBApplicationIcon) 
{
    UIAlertView* __launchView = [[UIAlertView alloc] init];
    __launchView.title = @"No way muchacho";
    __launchView.message = @"You can't touch dis!";
    [__launchView addButtonWithTitle:@"Dismiss"];
    [__launchView show];

}

extern "C" void AnotherCheckInitialize() 
{   
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 
    // Get the SBApplicationIcon class
    Class _$SBAppIcon = objc_getClass("SBApplicationIcon");


    MSHookMessageEx(_$SBAppIcon, @selector(launch), __$AnotherCheck_AppIcon_Launch, (IMP *) &original_Launch);


    [pool release];
}

But i m getting these 2 errors at MSHookMessageEx line

error: invalid conversion from 'void ()(SBApplicationIcon)' to 'objc_object* (*)(objc_object*, objc_selector*, ...)'

error: initializing argument 2 of 'objc_object* (* method_setImplementation(objc_method*, objc_object* (*)(objc_object*, objc_selector*, ...)))(objc_object*, objc_selector*, ...)'

Any advice on these please?

raziiq
Seems like you're compiling in C++. Anyway, cast `__$AnotherCheck_AppIcon_Launch` into an `IMP` on that line.
KennyTM
no no, i am compiling in xcode, but still its giving me the errors
raziiq
A: 

http://www.ipodtouchfans.com/forums/showthread.php?t=103558 May be this can help you. Good luck.