[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Substitute classes
From: |
David Chisnall |
Subject: |
Re: Substitute classes |
Date: |
Thu, 17 Mar 2011 14:21:11 +0000 |
On 17 Mar 2011, at 14:12, Gregory Casamento wrote:
> There used to be a method on NSObject called "poseAsClass:" but it was
> deprecated in 10.5 (this method still exists in GNUstep, by the way
> guys...).
>
> I believe it was removed because it is a *significant* security risk.
> There might be some things you can do directly with the runtime, but
> I believe that these functions were also removed. The only
> alternative I can see is directly manipulating the Objective-C data
> structure which associates class names to the classes themselves. I
> have never done that before, so I'm not sure how it could be achieved.
Class posing is gone because it is impossible to do safely in conjunction with
non-fragile ivars. The posing class must have EXACTLY the same ivar layout as
the posed class. This can not be guaranteed with a non-fragile ABI (ours or
Apple's), and there are other complications for subclasses of the posed class.
It was always a very fragile mechanism.
You can do the same thing with method swizzling but, again, you must be very
careful that the class receiving the method has exactly the same ivar layout
that the method expects. Just taking a method from a GNUstep class and tacking
it on to Apple's equivalent is a good way of corrupting your heap.
David
-- Sent from my Difference Engine