Skip to content
This repository has been archived by the owner on Jan 25, 2018. It is now read-only.

Support for getters/setters #3

Open
rodionovd opened this issue Jun 23, 2014 · 1 comment
Open

Support for getters/setters #3

rodionovd opened this issue Jun 23, 2014 · 1 comment

Comments

@rodionovd
Copy link
Owner

AFAIK, setters and getters are shared between all instances of a class in Swift. They seem to have the following structure:

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;
}

So it's impossible (?) to hook a getter/setter for the only instance of a class.
Needs some research, though.

@rodionovd
Copy link
Owner Author

This could be fixed with #4:

/* Pointer to a Swift object we want to hook a getter for*/
uintptr_t target_object = ....;
/* Pointer to an original implementation of getFoo() */
int (*original_getFoo)(void*) = ...;

int hooked_getFoo(void *self)
{
    if ((uintptr_t)self == target_object) return 0xBAD; 
    return original_getFoo(self);
}

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

No branches or pull requests

1 participant