[PA-CVS] paranoidandroid/Sources/APE PatchFunctions.c,1.1.1.1,1.2 PatchFunctions.h,1.1.1.1,1.2 Patch
Brought to you by:
smeger
From: Jason H. <sm...@us...> - 2006-02-21 22:16:40
|
Update of /cvsroot/paranoidandroid/paranoidandroid/Sources/APE In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7974/Sources/APE Modified Files: PatchFunctions.c PatchFunctions.h Patches.c UserNotifications.cpp UserNotifications.h main.cpp Log Message: Updated to 1.3. PA now notifies you when attempting to open a file using an application other than the default. Index: main.cpp =================================================================== RCS file: /cvsroot/paranoidandroid/paranoidandroid/Sources/APE/main.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** main.cpp 27 May 2004 11:33:57 -0000 1.1.1.1 --- main.cpp 21 Feb 2006 22:16:32 -0000 1.2 *************** *** 18,21 **** --- 18,23 ---- CFBundleRef gParanoidAndroidAppBundle = NULL; CFArrayRef gWhitelistedSchemes = NULL; + bool gWatchSchemes = false; + bool gWatchRemapping = false; // if this changes, change it in PrefPane/ParanoidAndroidController.h, too *************** *** 29,33 **** static void ! LoadWhitelistedSchemes () { if ( gWhitelistedSchemes ) --- 31,35 ---- static void ! ReadPrefs () { if ( gWhitelistedSchemes ) *************** *** 46,49 **** --- 48,62 ---- if ( ! gWhitelistedSchemes ) throw 1; + + CFBooleanRef watchSchemes = (CFBooleanRef)CFPreferencesCopyAppValue(kPA_PREF_WatchSchemes, kPA_ParanoidAndroidIdentifier); + gWatchSchemes = true; + if ( watchSchemes && CFGetTypeID(watchSchemes) == CFBooleanGetTypeID() ) + gWatchSchemes = CFBooleanGetValue(watchSchemes); + + CFBooleanRef watchRemapping = (CFBooleanRef)CFPreferencesCopyAppValue(kPA_PREF_WatchRemapping, kPA_ParanoidAndroidIdentifier); + gWatchRemapping = true; + if ( watchRemapping && CFGetTypeID(watchRemapping) == CFBooleanGetTypeID() ) + gWatchRemapping = CFBooleanGetValue(watchRemapping); + } *************** *** 72,76 **** if ( ! PatchFunctions() ) { throw 1; } ! LoadWhitelistedSchemes(); // We've loaded sucessfully! --- 85,89 ---- if ( ! PatchFunctions() ) { throw 1; } ! ReadPrefs(); // We've loaded sucessfully! *************** *** 97,101 **** if ( kCFCompareEqualTo == CFStringCompare(message, kPA_MSG_PrefsChanged, 0) ) { ! LoadWhitelistedSchemes (); } } --- 110,114 ---- if ( kCFCompareEqualTo == CFStringCompare(message, kPA_MSG_PrefsChanged, 0) ) { ! ReadPrefs (); } } Index: PatchFunctions.c =================================================================== RCS file: /cvsroot/paranoidandroid/paranoidandroid/Sources/APE/PatchFunctions.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** PatchFunctions.c 27 May 2004 11:33:57 -0000 1.1.1.1 --- PatchFunctions.c 21 Feb 2006 22:16:32 -0000 1.2 *************** *** 15,19 **** --- 15,27 ---- char const * const kParAnd_LaunchServicesFramework = "./LaunchServices"; + MMC_LSOpenFromRefSpec_FuncPtr gMMC_LSOpenFromRefSpec = NULL; MMC_LSOpenFromURLSpec_FuncPtr gMMC_LSOpenFromURLSpec = NULL; /*MMC__LSRegisterNode_FuncPtr gMMC__LSRegisterNode = NULL; MMC_FSNodeCopyURL_FuncPtr gMMC_FSNodeCopyURL = NULL; */ + + /* ********************************************** + * CarbonCore.framework + * *********************************************/ + char const * const kParAnd_CarbonCoreFramework = "./CarbonCore"; + + MMC_RMGetResourceByFileRef_FuncPtr gMMC_RMGetResourceByFileRef = NULL; Index: Patches.c =================================================================== RCS file: /cvsroot/paranoidandroid/paranoidandroid/Sources/APE/Patches.c,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Patches.c 27 May 2004 11:33:57 -0000 1.1.1.1 --- Patches.c 21 Feb 2006 22:16:32 -0000 1.2 *************** *** 13,19 **** --- 13,23 ---- #include "APEExtras.h" #include <ApplicationEnhancer/ApplicationEnhancer.h> + #include <pthread.h> extern bool gParanoidAndroidShouldPatch; + static pthread_mutex_t gLock; + static bool gFileIsBeingOpened = false; + static CFURLRef gCurrentURL = NULL; bool *************** *** 22,25 **** --- 26,31 ---- struct mach_header* header; + pthread_mutex_init(&gLock, NULL); + // LaunchServices.framework header = APEGetImageHeader(kParAnd_LaunchServicesFramework); *************** *** 28,31 **** --- 34,44 ---- RequiredPatch( header, + "_LSOpenFromRefSpec", + gMMC_LSOpenFromRefSpec, + MMC_LSOpenFromRefSpec_FuncPtr, + MMC_My_LSOpenFromRefSpec + ); + RequiredPatch( + header, "_LSOpenFromURLSpec", gMMC_LSOpenFromURLSpec, *************** *** 49,52 **** --- 62,77 ---- ); */ + // CarbonCore.framework + header = APEGetImageHeader(kParAnd_CarbonCoreFramework); + if (!header) return false; + + RequiredPatch( + header, + "_RMGetResourceByFileRef", + gMMC_RMGetResourceByFileRef, + MMC_RMGetResourceByFileRef_FuncPtr, + MMC_My_RMGetResourceByFileRef + ); + return true; } *************** *** 54,57 **** --- 79,119 ---- OSStatus + MMC_My_LSOpenFromRefSpec + ( const LSLaunchFSRefSpec *inLaunchSpec, + FSRef *outLaunchedRef ) + { + if ( gParanoidAndroidShouldPatch && inLaunchSpec && inLaunchSpec->numDocs && inLaunchSpec->itemRefs ) + { + bool canProceed; + + pthread_mutex_lock(&gLock); + canProceed = ! gFileIsBeingOpened; + pthread_mutex_unlock(&gLock); + + if ( canProceed ) + { + pthread_mutex_lock(&gLock); + gFileIsBeingOpened = true; + pthread_mutex_unlock(&gLock); + + // what if we have multiple FSRefs? Who knows... + CFURLRef currentURL = CFURLCreateFromFSRef(kCFAllocatorDefault, inLaunchSpec->itemRefs); + gCurrentURL = currentURL; + OSStatus result = gMMC_LSOpenFromRefSpec(inLaunchSpec, outLaunchedRef); + CFRelease(currentURL); + + pthread_mutex_lock(&gLock); + gFileIsBeingOpened = false; + pthread_mutex_unlock(&gLock); + + return result; + } + } + + return gMMC_LSOpenFromRefSpec(inLaunchSpec, outLaunchedRef); + } + + + OSStatus MMC_My_LSOpenFromURLSpec ( const LSLaunchURLSpec *inLaunchSpec, *************** *** 71,75 **** } } ! } return gMMC_LSOpenFromURLSpec( inLaunchSpec, outLaunchedURL ); } --- 133,159 ---- } } ! ! bool canProceed; ! pthread_mutex_lock(&gLock); ! canProceed = ! gFileIsBeingOpened; ! pthread_mutex_unlock(&gLock); ! ! if ( canProceed ) ! { ! pthread_mutex_lock(&gLock); ! gFileIsBeingOpened = true; ! pthread_mutex_unlock(&gLock); ! ! // what if we have multiple FSRefs? Who knows... ! gCurrentURL = CFArrayGetValueAtIndex(inLaunchSpec->itemURLs, 0); ! OSStatus result = gMMC_LSOpenFromURLSpec(inLaunchSpec, outLaunchedURL); ! ! pthread_mutex_lock(&gLock); ! gFileIsBeingOpened = false; ! pthread_mutex_unlock(&gLock); ! ! return result; ! } ! } return gMMC_LSOpenFromURLSpec( inLaunchSpec, outLaunchedURL ); } *************** *** 94,96 **** } return gMMC__LSRegisterNode( inNode, flags ); ! } */ \ No newline at end of file --- 178,219 ---- } return gMMC__LSRegisterNode( inNode, flags ); ! } */ ! ! ! OSStatus ! MMC_My_RMGetResourceByFileRef ! ( void *inFileRef, ! OSType inResourceType, ! long inResourceID, ! Handle *outHandle ) ! { ! if ( gParanoidAndroidShouldPatch && 'usro' == inResourceType && 0 == inResourceID && outHandle ) ! { ! bool canProceed; ! ! pthread_mutex_lock(&gLock); ! canProceed = gFileIsBeingOpened; ! pthread_mutex_unlock(&gLock); ! ! if ( canProceed ) ! { ! OSStatus result = gMMC_RMGetResourceByFileRef(inFileRef, inResourceType, inResourceID, outHandle); ! if ( noErr == result ) ! { ! if ( *outHandle && 1028 == GetHandleSize(*outHandle) && **(long **)*outHandle <= 1024 ) ! { ! char const *path = (char const *) &(((long *)**outHandle)[1]); ! if ( ! ShouldPermitRemapping(gCurrentURL, path) ) ! { ! // let the handle leak rather than calling private API to close it ! *outHandle = NULL; ! return resNotFound; ! } ! } ! return noErr; ! } ! } ! } ! ! return gMMC_RMGetResourceByFileRef(inFileRef, inResourceType, inResourceID, outHandle); ! } Index: PatchFunctions.h =================================================================== RCS file: /cvsroot/paranoidandroid/paranoidandroid/Sources/APE/PatchFunctions.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** PatchFunctions.h 27 May 2004 11:33:57 -0000 1.1.1.1 --- PatchFunctions.h 21 Feb 2006 22:16:32 -0000 1.2 *************** *** 21,30 **** extern char const * const kParAnd_LaunchServicesFramework; // _LSOpenFromURLSpec typedef OSStatus (*MMC_LSOpenFromURLSpec_FuncPtr) ( const LSLaunchURLSpec *inLaunchSpec, ! CFURLRef *outLaunchedURL ); extern MMC_LSOpenFromURLSpec_FuncPtr gMMC_LSOpenFromURLSpec; OSStatus MMC_My_LSOpenFromURLSpec ( const LSLaunchURLSpec *inLaunchSpec, ! CFURLRef *outLaunchedURL ); /* // __LSRegisterNode --- 21,37 ---- extern char const * const kParAnd_LaunchServicesFramework; + // LSOpenFromRefSpec + typedef OSStatus (*MMC_LSOpenFromRefSpec_FuncPtr) ( const LSLaunchFSRefSpec *inLaunchSpec, + FSRef *outLaunchedRef ); + extern MMC_LSOpenFromRefSpec_FuncPtr gMMC_LSOpenFromRefSpec; + OSStatus MMC_My_LSOpenFromRefSpec ( const LSLaunchFSRefSpec *inLaunchSpec, + FSRef *outLaunchedRef ); + // _LSOpenFromURLSpec typedef OSStatus (*MMC_LSOpenFromURLSpec_FuncPtr) ( const LSLaunchURLSpec *inLaunchSpec, ! CFURLRef *outLaunchedURL ); extern MMC_LSOpenFromURLSpec_FuncPtr gMMC_LSOpenFromURLSpec; OSStatus MMC_My_LSOpenFromURLSpec ( const LSLaunchURLSpec *inLaunchSpec, ! CFURLRef *outLaunchedURL ); /* // __LSRegisterNode *************** *** 41,44 **** --- 48,67 ---- */ + /* ********************************************** + * CarbonCore.framework + * *********************************************/ + extern char const * const kParAnd_CarbonCoreFramework; + + // RMGetResourceByFileRef + typedef OSStatus (*MMC_RMGetResourceByFileRef_FuncPtr) ( void *inFileRef, + OSType inResourceType, + long inResourceID, + Handle *outHandle ); + extern MMC_RMGetResourceByFileRef_FuncPtr gMMC_RMGetResourceByFileRef; + OSStatus MMC_My_RMGetResourceByFileRef ( void *inFileRef, + OSType inResourceType, + long inResourceID, + Handle *outHandle ); + #ifdef __cplusplus } Index: UserNotifications.h =================================================================== RCS file: /cvsroot/paranoidandroid/paranoidandroid/Sources/APE/UserNotifications.h,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** UserNotifications.h 27 May 2004 11:33:57 -0000 1.1.1.1 --- UserNotifications.h 21 Feb 2006 22:16:32 -0000 1.2 *************** *** 16,19 **** --- 16,20 ---- bool ShouldPermitURL ( CFURLRef url ); + bool ShouldPermitRemapping ( CFURLRef inFileURL, const char *appPath ); // bool ShouldPermitURLRegistration ( CFURLRef url ); Index: UserNotifications.cpp =================================================================== RCS file: /cvsroot/paranoidandroid/paranoidandroid/Sources/APE/UserNotifications.cpp,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** UserNotifications.cpp 27 May 2004 11:33:57 -0000 1.1.1.1 --- UserNotifications.cpp 21 Feb 2006 22:16:32 -0000 1.2 *************** *** 16,19 **** --- 16,21 ---- extern CFBundleRef gParanoidAndroidAppBundle; extern CFArrayRef gWhitelistedSchemes; + extern bool gWatchSchemes; + extern bool gWatchRemapping; *************** *** 136,139 **** --- 138,143 ---- ShouldPermitURL ( CFURLRef url ) { + if ( ! gWatchSchemes ) + return true; CFStringRef scheme = CFURLCopyScheme( url ); if ( ! scheme ) *************** *** 239,240 **** --- 243,285 ---- return permit; } */ + + + bool + ShouldPermitRemapping + ( CFURLRef inFileURL, + const char *appPath ) + { + if ( ! gWatchRemapping ) + return true; + + CFURLRef iconURL = CFBundleCopyResourceURL(gParanoidAndroidBundle, CFSTR("ParanoidAndroid"), CFSTR("icns"), NULL); + + CFStringRef appName = CopyApplicationName(); + if ( ! appName ) + appName = CFBundleCopyLocalizedString(gParanoidAndroidBundle, CFSTR("unknownApp"), NULL, NULL); + + CFStringRef destAppName = CFStringCreateWithCString(kCFAllocatorDefault, appPath, kCFStringEncodingUTF8); + if ( ! destAppName ) + destAppName = CFBundleCopyLocalizedString(gParanoidAndroidBundle, CFSTR("unknownApp"), NULL, NULL); + + CFStringRef header = CFBundleCopyLocalizedString( gParanoidAndroidBundle, CFSTR("allowRemappingHeader"), NULL, NULL ); + + CFStringRef descriptionFormat = CFBundleCopyLocalizedString(gParanoidAndroidBundle, CFSTR("allowRemappingDescription"), NULL, NULL); + CFStringRef description = CFStringCreateWithFormat( kCFAllocatorDefault, NULL, descriptionFormat, appName, inFileURL, destAppName ); + + CFStringRef yes = CFBundleCopyLocalizedString(gParanoidAndroidBundle, CFSTR("continue"), NULL, NULL); + CFStringRef no = CFBundleCopyLocalizedString(gParanoidAndroidBundle, CFSTR("useDefault"), NULL, NULL); + + CFOptionFlags responseFlags; + CFUserNotificationDisplayAlert(0, kCFUserNotificationStopAlertLevel, iconURL, NULL, NULL, header, description, yes, no, NULL, &responseFlags); + if (iconURL) CFRelease(iconURL); + if (appName) CFRelease(appName); + if (destAppName) CFRelease(destAppName); + if (header) CFRelease(header); + if (descriptionFormat) CFRelease(descriptionFormat); + if (description) CFRelease(description); + if (yes) CFRelease(yes); + if (no) CFRelease(no); + + return responseFlags == kCFUserNotificationDefaultResponse; + } |