Aspects icon indicating copy to clipboard operation
Aspects copied to clipboard

Support for Multiple Hooks into Methods in Class Hierarchy

Open ashfurrow opened this issue 11 years ago • 4 comments

Currently the first hook to a class wins, so if B subclasses A, and both implement foo, we can either hook foo in A or in B, but not in both classes.

ashfurrow avatar May 07 '14 08:05 ashfurrow

This is related to #2. The basic problem is that once we have an NSInvocation, there's no way to check the underlying IMP location to detect if it points to self or super... so hooks can only safely be added to the topmost class.

Currently I opted to block this, but it's by far not the best solution. We can also collect and apply this in alloc-time. Downside: Hooks might be called whose method is not (you might wanna omit super, but the hook for the parent would still be called - also the timing would be different)

Alternatively we could fix the underlying problem, but it requires custom jump tables ala https://github.com/OliverLetterer/SPLMessageLogger/blob/master/SPLMessageLogger/spl_forwarding_trampoline_armv7.s#L14-L18 (or maybe libffi)

steipete avatar May 07 '14 08:05 steipete

@steipete It seems that this applies not only to subclasses, but to any class with common base classes? Is that right?

For example, if I have two classes derived from NSObject, and each implements a function called "someFunction", this situation also applies. Or, in a more realistic case, if I have two UIViewControllers, each which implements the same protocol, I can't seem hook that protocol method in both places.

pj4533 avatar May 07 '14 18:05 pj4533

I think i fixed this and relative issues, but i don't know how to submit, send email to me ([email protected])

aa3000 avatar Mar 28 '16 11:03 aa3000

@pj4533 I just met the same issue as you mentioned.I was trying to hook a table view delegate method in different classes, but the error log says:

"tableView:didSelectRowAtIndexPath: already hooked in YIDSignUpViewController. A method can only be hooked once per class hierarchy."

The strange thing is, in fact, I didn't hook any table view delegate methods in YIDSignUpViewController class and I didn't implement any table view delegate methods in that class .

ShannonChenCHN avatar Jan 18 '17 09:01 ShannonChenCHN