johnno1962 / injectionforxcode

Runtime Code Injection for Objective-C & Swift
MIT License
6.56k stars 565 forks source link

Code injected wasn't executed #43

Closed haxpor closed 9 years ago

haxpor commented 9 years ago

I test this on real device. Patched the project first, then add CCLOG("added line"); into the following code.

- (void)applicationWillResignActive:(UIApplication *)application {
    /*
     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
     */
    cocos2d::CCDirector::sharedDirector()->pause();

    CCLOG("added line");

    CCLOG("-- Application will resign active --");
    ...

That means whenever the application goes to background, then added line should be shown on console.

What I got in console is

(lldb) p (void)[[NSBundle bundleWithPath:@"/Users/haxpor/Library/Application Support/Developer/Shared/Xcode/Plug-ins/InjectionPlugin.xcplugin/Contents/Resources/InjectionLoader.bundle"] load]
(lldb) c
Process 509 resuming
c
Cocos2d: -- Application will resign active --

Any idea of why the added code wasn't executed?

johnno1962 commented 9 years ago

You need to “patch” your project for it to inject on a device (Product//Patch Project for Injectinion>)

Niue commented 9 years ago

Is there a detailed tutorial, such as the screenshot.

haxpor commented 9 years ago

From above, I already patched the project.

Niue commented 9 years ago

This unhide.sh script is how to do

johnno1962 commented 9 years ago

Oops, well it’s not connecting then. Check the list of IP addresses in the project’s main.m. If it is a Swift project or doesn’t have a main.m you’ll need to add one so it can be patched.

haxpor commented 9 years ago

I have main.m, and I can see it modified the file.

johnno1962 commented 9 years ago

have you #defined DEBUG in your project build settings. You should be getting messages on your console telling you what is happening.

haxpor commented 9 years ago

Thank you Johnno, your support is amazing.

I don't have time right now, might be a few days to a week. I will get back to this as soon as possible. The fact is I've changed to work with AppCode instead of XCode now, and although I faced a new issue in AppCode but I will get back to this.