[PA-CVS] paranoidandroid/Sources/APE PatchFunctions.c,1.2,1.3 PatchFunctions.h,1.2,1.3 Patches.c,1.2
Brought to you by:
smeger
From: Jason H. <sm...@us...> - 2006-02-22 00:51:20
|
Update of /cvsroot/paranoidandroid/paranoidandroid/Sources/APE In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28798/Sources/APE Modified Files: PatchFunctions.c PatchFunctions.h Patches.c Log Message: The path of the custom app might not be null-terminated. Index: Patches.c =================================================================== RCS file: /cvsroot/paranoidandroid/paranoidandroid/Sources/APE/Patches.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Patches.c 21 Feb 2006 22:16:32 -0000 1.2 --- Patches.c 22 Feb 2006 00:51:15 -0000 1.3 *************** *** 34,37 **** --- 34,44 ---- RequiredPatch( header, + "_LSGetApplicationForItem", + gMMC_LSGetApplicationForItem, + MMC_LSGetApplicationForItem_FuncPtr, + MMC_My_LSGetApplicationForItem + ); + RequiredPatch( + header, "_LSOpenFromRefSpec", gMMC_LSOpenFromRefSpec, *************** *** 79,82 **** --- 86,128 ---- OSStatus + MMC_My_LSGetApplicationForItem + ( const FSRef *inItemRef, + LSRolesMask inRoleMask, + FSRef *outAppRef, + CFURLRef *outAppURL ) + { + if ( gParanoidAndroidShouldPatch && inItemRef ) + { + 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, inItemRef); + gCurrentURL = currentURL; + OSStatus result = gMMC_LSGetApplicationForItem(inItemRef, inRoleMask, outAppRef, outAppURL); + CFRelease(currentURL); + + pthread_mutex_lock(&gLock); + gFileIsBeingOpened = false; + pthread_mutex_unlock(&gLock); + + return result; + } + } + + return gMMC_LSGetApplicationForItem(inItemRef, inRoleMask, outAppRef, outAppURL); + } + + + OSStatus MMC_My_LSOpenFromRefSpec ( const LSLaunchFSRefSpec *inLaunchSpec, *************** *** 201,216 **** 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; ! } } } --- 247,270 ---- if ( noErr == result ) { ! if ( *outHandle && 1028 == GetHandleSize(*outHandle) ) { ! size_t pathLength = **(long **)*outHandle; ! if ( pathLength > 0 && pathLength <= 1024 ) { ! char const *path = (char const *) &(((long *)**outHandle)[1]); ! char *_path = malloc(pathLength); ! memcpy(_path, path, pathLength); ! bool shouldPermit = ShouldPermitRemapping(gCurrentURL, _path); ! free(_path); ! if ( ! shouldPermit ) ! { ! // let the handle leak rather than calling private API to close it ! *outHandle = NULL; ! return resNotFound; ! } } + return noErr; } ! } } } Index: PatchFunctions.c =================================================================== RCS file: /cvsroot/paranoidandroid/paranoidandroid/Sources/APE/PatchFunctions.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PatchFunctions.c 21 Feb 2006 22:16:32 -0000 1.2 --- PatchFunctions.c 22 Feb 2006 00:51:15 -0000 1.3 *************** *** 15,18 **** --- 15,19 ---- char const * const kParAnd_LaunchServicesFramework = "./LaunchServices"; + MMC_LSGetApplicationForItem_FuncPtr gMMC_LSGetApplicationForItem = NULL; MMC_LSOpenFromRefSpec_FuncPtr gMMC_LSOpenFromRefSpec = NULL; MMC_LSOpenFromURLSpec_FuncPtr gMMC_LSOpenFromURLSpec = NULL; Index: PatchFunctions.h =================================================================== RCS file: /cvsroot/paranoidandroid/paranoidandroid/Sources/APE/PatchFunctions.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PatchFunctions.h 21 Feb 2006 22:16:32 -0000 1.2 --- PatchFunctions.h 22 Feb 2006 00:51:15 -0000 1.3 *************** *** 21,24 **** --- 21,35 ---- extern char const * const kParAnd_LaunchServicesFramework; + // LSGetApplicationForItem + typedef OSStatus (*MMC_LSGetApplicationForItem_FuncPtr) ( const FSRef *inItemRef, + LSRolesMask inRoleMask, + FSRef *outAppRef, + CFURLRef *outAppURL ); + extern MMC_LSGetApplicationForItem_FuncPtr gMMC_LSGetApplicationForItem; + OSStatus MMC_My_LSGetApplicationForItem ( const FSRef *inItemRef, + LSRolesMask inRoleMask, + FSRef *outAppRef, + CFURLRef *outAppURL ); + // LSOpenFromRefSpec typedef OSStatus (*MMC_LSOpenFromRefSpec_FuncPtr) ( const LSLaunchFSRefSpec *inLaunchSpec, *************** *** 28,32 **** FSRef *outLaunchedRef ); ! // _LSOpenFromURLSpec typedef OSStatus (*MMC_LSOpenFromURLSpec_FuncPtr) ( const LSLaunchURLSpec *inLaunchSpec, CFURLRef *outLaunchedURL ); --- 39,43 ---- FSRef *outLaunchedRef ); ! // _LSOpenFromURLSpec typedef OSStatus (*MMC_LSOpenFromURLSpec_FuncPtr) ( const LSLaunchURLSpec *inLaunchSpec, CFURLRef *outLaunchedURL ); |