#include #import "DualityStrings.h" #import "DCPatcher.h" #include #include #include #include #include "DCLog.h" int main (int argc, const char * argv[]) { DCSetLogMode(2); DCLogCriticalMessage(DCLongVersion); DCLogCriticalMessage(DCStartingString); DCLogMessage(DCCheckingSystemPolicyString); /* First we need to check the system's policy on allowing us to touch other processes. Under Mac OS X 10.4 for Intel, three modes are enforced for controlling who can and can't much with processes. The current mode is set in kern.tfp.policy. The modes are: KERN_TFP_POLICY_DENY - No one can mess with any other processes. KERN_TFP_POLICY_PERMISSIVE - Everyone can touch other processes. KERN_TFP_POLICY_RESTRICTED - Only programs that are owned by the procmod group can mess with other processes. By default, OS X has kern.tfp.policy set to KERN_TFP_POLICY_RESTRICTED, so all we really need to do in most cases is make sure this executable is owned by procmod. We still need to alert the user though in case the default setting has been changed, or perhaps the default setting is KERN_TFP_POLICY_DENY in a future version of Mac OS X. Mac OS X on PowerPC does not currently enforce these modes, but this is expected to change in a future version of OS X for PowerPC. */ int mib[3]; size_t len; int kp; mib[0]=CTL_KERN; mib[1]=KERN_TFP; mib[2]=KERN_TFP_POLICY; len = sizeof(kp); sysctl(mib, 3, &kp, &len, NULL, 0); if(kp>KERN_TFP_POLICY_DENY) DCLogMessage(DCPassedString); else { DCLogMessage(DCFailedString); DCLogCriticalMessage(DCKernelPolicyFailedExplanation); DCLogCriticalMessage(DCStoppedString); return 0; } //Make sure we're part of procmod group. Unless we're part of procmod, we're not //allowed to mess with other processes. //Exception is made if the system's policy is to allow any process to touch //other processes DCLogMessage(DCCheckingPrivilegesString); struct stat selfInfo; stat(argv[0], &selfInfo); if(kp=KERN_TFP_POLICY_PERMISSIVE||(selfInfo.st_gid==9)) { DCLogMessage(DCPassedString); }else { DCLogMessage(DCFailedString); DCLogCriticalMessage(DCStoppedString); return 0; } //Subscribe to application launch/terminate notifications DCLogMessage(DCSubscribingToEventsString); DCRegisterForLaunchNotifications(); DCLogMessage(DCPassedString); //Start the event loop DCLogMessage(DCStartingEventLoopString); RunApplicationEventLoop (); DCLogCriticalMessage(DCStoppedString); return 0; }