rodionovd / rd_route

Function hooking for macOS
MIT License
184 stars 26 forks source link

Swift property routing support? #4

Closed delebedev closed 10 years ago

delebedev commented 10 years ago

In obj-c properties are syntactic sugar over setFoo: getFoo methods, but in Swift they are closer to ivars (at least from my knowledge). Is there any way to route them as well?

rodionovd commented 10 years ago

@garnett Well… actually, setters and getters are shared between all instances of a class in Swift. They look like:

const int foo_offset = 0x48;

int getFoo(void *self)
{
    return *(uinptr_t *)(self + foo_offset);
}

void setFoo(int new_value, void *self)
{
    // there will be release/retain for non-scalar types 
    // ...
   *(uintptr_t *)(self + foo_offset) = new_value;
}

I don't know how can we hook setters/getters for only instance of the class… So far I only have a way to obtain a shared setter/getter address, but it kinda useless.

rodionovd commented 10 years ago

I've reopened this issue as https://github.com/rodionovd/SWRoute/issues/3, because it's not about rd_route itself, but SWRoute.