2 // **********************************************************************
3 // The Cheat - A universal game cheater for Mac OS X
4 // (C) 2003-2005 Chaz McGarvey (BrokenZipper)
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 1, or (at your option)
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #import <Cocoa/Cocoa.h>
22 #import <Foundation/foundation.h>
23 #import <SecurityFoundation/SFAuthorization.h>
24 #import <Security/AuthorizationTags.h>
26 #include <sys/types.h>
30 void authMe(char * FullPathToMe
)
32 // get authorization as root
36 // set up Authorization Item
37 AuthorizationItem myItems
[1];
38 myItems
[0].name
= kAuthorizationRightExecute
;
39 myItems
[0].valueLength
= 0;
40 myItems
[0].value
= NULL
;
43 // Set up Authorization Rights
44 AuthorizationRights myRights
;
45 myRights.count
= sizeof (myItems
) / sizeof (myItems
[0]);
46 myRights.items
= myItems
;
48 // set up Authorization Flags
49 AuthorizationFlags myFlags
;
51 kAuthorizationFlagDefaults |
52 kAuthorizationFlagInteractionAllowed |
53 kAuthorizationFlagExtendRights
;
55 // Create an Authorization Ref using Objects above. NOTE: Login bod comes up with this call.
56 AuthorizationRef myAuthorizationRef
;
57 myStatus
= AuthorizationCreate (&myRights
, kAuthorizationEmptyEnvironment
, myFlags
, &myAuthorizationRef
);
59 if (myStatus
== errAuthorizationSuccess
)
61 // prepare communication path - used to signal that process is loaded
62 FILE *myCommunicationsPipe
= NULL
;
63 char myReadBuffer
[] = " ";
65 // run this app in GOD mode by passing authorization ref and comm pipe (asynchoronous call to external application)
66 myStatus
= AuthorizationExecuteWithPrivileges(myAuthorizationRef
,FullPathToMe
,kAuthorizationFlagDefaults
,nil,&myCommunicationsPipe
);
68 // external app is running asynchronously - it will send to stdout when loaded
69 if (myStatus
== errAuthorizationSuccess
)
71 read (fileno (myCommunicationsPipe
), myReadBuffer
, sizeof (myReadBuffer
));
72 fclose(myCommunicationsPipe
);
75 // release authorization reference
76 myStatus
= AuthorizationFree (myAuthorizationRef
, kAuthorizationFlagDestroyRights
);
80 bool checkExecutablePermissions(void)
82 NSDictionary
*applicationAttributes
= [[NSFileManager defaultManager
] fileAttributesAtPath
:[[NSBundle mainBundle
] executablePath
] traverseLink
: YES
];
84 // We expect 2755 as octal (1517 as decimal, -rwxr-sr-x as extended notation)
85 return ([applicationAttributes filePosixPermissions
] == 1517 && [[applicationAttributes fileGroupOwnerAccountName
] isEqualToString
: @
"procmod"]);
91 AuthorizationRef myAuthRef
;
92 OSStatus stat
= AuthorizationCopyPrivilegedReference(&myAuthRef
,kAuthorizationFlagDefaults
);
94 return stat
== errAuthorizationSuccess ||
checkExecutablePermissions();
97 int main( int argc
, char *argv
[] )
99 NSAutoreleasePool
*pool
= [[NSAutoreleasePool alloc
] init
];
107 // PPC machines whose operating system is below leopard do not need authorization
108 SInt32 osxMajorVersion
;
109 Gestalt(gestaltSystemVersionMinor
, &osxMajorVersion
);
110 if (osxMajorVersion
< 5)
113 return NSApplicationMain(argc
, (const char **) argv
);
120 printf("Don't forget to flush! ;-) "); // signal back to close caller
125 return NSApplicationMain(argc
, (const char **) argv
);