It doesn't modify the file per say. It tricks the file system into pointing to a different file instead of the one in the system folder. Spotlight finds MDSearchWidget_Pressed, and when you open it, Preview asks the system to open the file at the path for MDSearchWidget_Pressed. ShapeShifter, using APE, has patched into OS X's open routines and intercepts the open request for MDSearchWidget_Pressed. It takes the request looks through it's cache folder for a file that matches the one the system is trying to open. If it doesn't find a matching file, it allows the system to continue loading the file it originally tried to load. If it does find a matching file in the cache directory, it tricks the application asking the file into instead loading the matching file from the ShapeShifter. In essence, Preview asked the system to load the MDSearchWidget_Pressed file, ShapeShifter intercepted the call to open MDSearchWidget_Pressed, tricked the call into opening a themed MDSearchWidget_Pressed widget instead that it keeps elsewhere on the hard drive.
So yes, ShapeShifter IS still replacing files. It is not however replacing any files on the hard drive. Instead it patches into the OS X file handling system and redirects calls to files it is interested in changing to different paths. This does mean it can use a different set of patched paths per user in since the files aren't being replaced, and no authentication is needed.
Here is demo code written in Mach_Inject and not APE. To try it, create a Cocoa Application in XCode, download Mach_Override, put both mach_override.h and mach_override.m in your project's classes, and replace the code in your Main.m with the following:
code:
#include <sys/attr.h>
#include "mach_override.h"
#import <Cocoa/Cocoa.h>
#include <Carbon/Carbon.h>
typedef OSStatus (*fsmakerefProc)(const UInt8 * path, FSRef * ref, Boolean * isDirectory);
OSStatus FSPathMakeRefOverride (const UInt8 * path, FSRef * ref, Boolean * isDirectory);
static fsmakerefProc gFSPathMakeRef;
int main(int argc, char *argv[])
{
mach_override( "_FSPathMakeRef", NULL, FSPathMakeRefOverride, (void**) &gFSPathMakeRef );
return NSApplicationMain(argc, (const char **) argv);
}
OSStatus FSPathMakeRefOverride (const UInt8 * path, FSRef * ref, Boolean * isDirectory)
{
OSStatus returnVal;
FSRef extrasRef;
gFSPathMakeRef("/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Resources/Extras.rsrc",&extrasRef,0);
returnVal=gFSPathMakeRef(path,ref,isDirectory);
if(noErr == FSCompareFSRefs (&extrasRef,ref))
{
returnVal=gFSPathMakeRef("/Extras.rsrc",ref,isDirectory);
}
return returnVal;
}
This code demos patching the file system to theme. Please note if you don't have a valid Extras.rsrc on the root level of your hard drive the application will crash. It's demo code, not crash proof code.