-
Notifications
You must be signed in to change notification settings - Fork 968
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
Hooked function is called only once #36
Comments
Did you make your GitHub account just to report this bug? Either way, great username. I can see why this would happen with lazy binding. Also not sure if it's a bug, but it's definitely confusing. Here's two potential workarounds:
Do either of those help for you? |
ok Thanks, will know.
Doesn't work. Option A Simple call dlopen/dlsym/original function
Code is below:
Call of func looks like this:
And $rax is original address of function:
Code from framework still contains stubs for lazy binding, those operations don't trigger the binding. Option B More complex way: dlopen/dlsym but call upper function from framework which will call required function. Those must trigger binding mechanism. Unfortunately upper function is not exported, so can't force trigger binding mechanism for required function. |
Sorry, I meant |
Do not really understand. In other words, if I postpone installing hook for 10 seconds, than all work as expected. Unfortunately, this is bad case for me, because I lose some important information in that 10 seconds. I guess, you mean that I should load framework, and this would lead to call original function... but loaded framework doesn't call this function. This functionality linked with browsing webpage inside UIWebview component, and requires interaction from user side. Only in that way is posible to trigger this function. |
My understanding is that
You can then hook the functions after |
Usual case of using hook functionalityWe have target library which functions have to be hooked.
This is fine for us, because lazy symbols inside our App (or 3-rd party library) still contain correct link on our hooked function. Not obvious caseNow, another case, and it's more interesting (not obvious). Now imagine that one function could be present in many frameworks. How it's posible? Well, some frameworks could be based on the same component, as in my case. For example WebCore component (with some functions set) is built with WebKit and also with WebKitLegacy frameworks. My caseNow imagine that one function could be present in many frameworks. How it's posible? Well, some frameworks could be based on the same component, as in my case. For example WebCore component (with some functions set) is built with WebKit and also with WebKitLegacy frameworks. @grp SummaryI know the root cause of bug, but still don't know how to fix it in appropriate way. I can again install hook after first call of original function but this requires additional logic in code. Looks like the best way it's reading Apple documentation to understand how to force bind lazy symbols and only after that install hook. |
I've found solution. I take original pointer from dlsym instead of result from rebind_symbols, and that solves my issue.
Call of dlsym provides direct address of function, and that's all. Conclusion |
…e if it hasn't been bound already facebook/fishhook#36 Fixes #48
I wonder if fishhook could improve the situation here checking the GOT entry it's replacing to see if it's |
First of all I want to say thank you for this library! It's really interesting thing.
Now, about a bug. Sorry in advance, if I use wrong terminology.
Short description
I've seen situation when hook function was called only once. 'Some magic' restores the original address of function.
Explanation is simple: 'fishkook' is patching a lazy binded symbol at the moment when original symbols was not yet resolved.
My hook calls original function and this restores original function. This call looks like this:
Assembler code of original call (from debugger) is here:
As you can see, code calls original function from $rcx register. Lets take a look what is this:
This is stub for unresolved symbols. So, we will call stub_helper wich will resovle (actually restore) original address of function.
Conclusion
When my hook function calls original function then this leads to restore (unhook) original addrress of symbol, and my hook will be never called again.
Environment
Simulator iPhone 6s Plus 10.0
Platform: x64
Hooked function: WebCore::SQLiteStatement::bindBlob() == _ZN7WebCore15SQLiteStatement8bindBlobEiRKN3WTF6StringE
Project works with UIWebView.
Question
Is this the bug or expected behavior?
The text was updated successfully, but these errors were encountered: