Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hooking variadic functions causes an EXC_BAD_ACCESS #35

Open
KiranPanesar opened this issue Apr 16, 2015 · 6 comments
Open

Hooking variadic functions causes an EXC_BAD_ACCESS #35

KiranPanesar opened this issue Apr 16, 2015 · 6 comments

Comments

@KiranPanesar
Copy link

I created a demo iOS app. Pretty much the only thing it does is call [NSString stringWithFormat:@"asd"];. When I set up a custom tracer to hook into this method, the app crashes when called.

I've run it through Xcode, put down Exception Breakpoints and grabbed the backtrace using LLDB. Here's the trace of the crashing thread. As you can see, it results in an EXC_BAD_ACCESS.

Upon further testing it appears that this is only occurring for methods with variadic parameters. If I hook +stringWithString: and create a sample app which uses that method, the tracer works fine and all the data I ask is logged.

Has anyone else run into this?

@radj
Copy link

radj commented Apr 16, 2015

My guess is incorrect handling of the variadic parameters. You can try isolating by creating an app with code that only receives variadic parameters and passes it to the variadic +stringWithString: method and experiment around it. If you get that right, then follow that pattern when you pass the variadic hook parameters to %orig(). If I'm wrong, then at least you've learned how to manage variadic parameters :)

@KiranPanesar
Copy link
Author

Tried taking this approach: https://gist.github.com/KiranPanesar/e9e2c33dc083df0ad779. Fairly sure that will work.

Now the unfortunate thing is that it won't compile because it simply does not recognise variadic parameter syntax.

@KiranPanesar
Copy link
Author

Judging by my continued research, this appears to be a bug in Introspy.

Is there someone who is specifically maintaining this project?

@nabla-c0d3
Copy link
Member

I don't think you can use Logos (%hook etc) to hook variadic functions. You need to directly use the Cydia Substrate API. I wrote a quick poc here: https://gist.github.com/nabla-c0d3/f952c6fcc1e9d359dbfe

@kirilldobr
Copy link

Your example shows a C variadic function. But what if I need an Objective-C one?
NSString’s

+(instancetype)stringWithFormat:(NSString *)format, ...

can't be hooked that way...right?

@nabla-c0d3
Copy link
Member

It can but you would have to use MSHookMessageEx()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants