Commits

lokkju committed 286e62b

more methods

Comments (0)

Files changed (4)

+lib_override_volume_sensitivity_check.dylib
+
 CS5_INSTALLER_PATH=/Volumes/CS5_5\ Mstr\ Coll/Adobe\ CS5_5\ Master\ Collection/Install.app/Contents/MacOS/Install
 
 lib_override_volume_sensitivity_check.dylib: src/override_volume_sensitivity_check.c 
-	gcc -DDEBUG -ggdb -arch i386 -arch x86_64 -Wall -o lib_override_volume_sensitivity_check.dylib -dynamiclib src/override_volume_sensitivity_check.c
+	gcc -DDEBUG -ggdb -arch i386 -arch x86_64 -Wall -framework CoreServices -o lib_override_volume_sensitivity_check.dylib -dynamiclib src/override_volume_sensitivity_check.c
 
 .PHONY: clean run
 
 	rm -rf ./*.dylib* *~ core
 
 run:
-	DYLD_PRINT_LIBRARIES=1 DYLD_FORCE_FLAT_NAMESPACE=1 DYLD_INSERT_LIBRARIES=$(shell pwd)/lib_override_volume_sensitivity_check.dylib $(CS5_INSTALLER_PATH)
+	DYLD_PRINT_LIBRARIES=1 DYLD_INSERT_LIBRARIES=$(shell pwd)/lib_override_volume_sensitivity_check.dylib $(CS5_INSTALLER_PATH)

src/dyld-interposing.h

+#if !defined(_DYLD_INTERPOSING_H_)
+#define _DYLD_INTERPOSING_H_
+
+/*
+ *  Example:
+ *
+ *  static
+ *  int
+ *  my_open(const char* path, int flags, mode_t mode)
+ *  {
+ *    int value;
+ *    // do stuff before open (including changing the arguments)
+ *    value = open(path, flags, mode);
+ *    // do stuff after open (including changing the return value(s))
+ *    return value;
+ *  }
+ *  DYLD_INTERPOSE(my_open, open)
+ */
+
+typedef void (*void_function_t)(void);
+
+#define DYLD_INTERPOSE(_replacment,_replacee) \
+   __attribute__((used)) static struct{ const void* replacment; const void* replacee; } _interpose_##_replacee \
+            __attribute__ ((section ("__DATA,__interpose"))) = { (const void*)(unsigned long)&_replacment, (const void*)(unsigned long)&_replacee };
+#endif

src/override_volume_sensitivity_check.c

 #include <stdio.h>
 #include <unistd.h>
 #include <dlfcn.h>
+#include "dyld-interposing.h"
 #include <CoreServices/CoreServices.h>
 
-OSStatus (*original_FSGetVolumeParms) (FSVolumeRefNum, GetVolParmsInfoBuffer *, ByteCount) = NULL;
-OSStatus FSGetVolumeParms (FSVolumeRefNum volume, GetVolParmsInfoBuffer *buffer, ByteCount bufferSize) {
-    if(!original_FSGetVolumeParms) {
-        void *handle = dlopen("/System/Library/Frameworks/CoreServices.framework/Frameworks/CarbonCore.framework/CarbonCore", RTLD_LOCAL | RTLD_LAZY);
-        if(!handle) {
-            printf("== FSGetVolumeParms: ERROR - could not dlopen CarbonCore.  dying.\n");
-            exit(1);
-        }
-        original_FSGetVolumeParms = dlsym(handle, "FSGetVolumeParms");
-        if(!original_FSGetVolumeParms) {
-            printf("== ERROR: could not get the original FSGetVolumeParms.  dying.\n");
-            exit(1);
-        }
-    }
-    OSStatus status = original_FSGetVolumeParms(volume,buffer,bufferSize);
+static
+int
+my_open(const char* path, int flags, mode_t mode)
+{
+  int value;
+  // do stuff before open (including changing the arguments)
+  value = open(path, flags, mode);
+  // do stuff after open (including changing the return value(s))
+  return value;
+}
+DYLD_INTERPOSE(my_open, open)
+
+static OSStatus my_FSGetVolumeParms (FSVolumeRefNum volume, GetVolParmsInfoBuffer *buffer, ByteCount bufferSize) {
+    OSStatus status = FSGetVolumeParms(volume,buffer,bufferSize);
     int isCaseSensitive = !!(buffer->vMExtendedAttributes & (1 << bIsCaseSensitive));
     if(isCaseSensitive) {
         printf("== FSGetVolumeParms - lying and saying the volume is case insensitive, though it is case sensitive. ==\n");
     printf("== FSGetVolumeParms::bIsCaseSensitive = %i ==\n",!!(buffer->vMExtendedAttributes & (1 << bIsCaseSensitive)));
     return status;
 }
+
+DYLD_INTERPOSE(my_FSGetVolumeParms, FSGetVolumeParms);
+