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>
27 void authMe(char * FullPathToMe
)
29 // get authorization as root
33 // set up Authorization Item
34 AuthorizationItem myItems
[1];
35 myItems
[0].name
= kAuthorizationRightExecute
;
36 myItems
[0].valueLength
= 0;
37 myItems
[0].value
= NULL
;
40 // Set up Authorization Rights
41 AuthorizationRights myRights
;
42 myRights.count
= sizeof (myItems
) / sizeof (myItems
[0]);
43 myRights.items
= myItems
;
45 // set up Authorization Flags
46 AuthorizationFlags myFlags
;
48 kAuthorizationFlagDefaults |
49 kAuthorizationFlagInteractionAllowed |
50 kAuthorizationFlagExtendRights
;
52 // Create an Authorization Ref using Objects above. NOTE: Login bod comes up with this call.
53 AuthorizationRef myAuthorizationRef
;
54 myStatus
= AuthorizationCreate (&myRights
, kAuthorizationEmptyEnvironment
, myFlags
, &myAuthorizationRef
);
56 if (myStatus
== errAuthorizationSuccess
)
58 // prepare communication path - used to signal that process is loaded
59 FILE *myCommunicationsPipe
= NULL
;
60 char myReadBuffer
[] = " ";
62 // run this app in GOD mode by passing authorization ref and comm pipe (asynchoronous call to external application)
63 myStatus
= AuthorizationExecuteWithPrivileges(myAuthorizationRef
,FullPathToMe
,kAuthorizationFlagDefaults
,nil,&myCommunicationsPipe
);
65 // external app is running asynchronously - it will send to stdout when loaded
66 if (myStatus
== errAuthorizationSuccess
)
68 read (fileno (myCommunicationsPipe
), myReadBuffer
, sizeof (myReadBuffer
));
69 fclose(myCommunicationsPipe
);
72 // release authorization reference
73 myStatus
= AuthorizationFree (myAuthorizationRef
, kAuthorizationFlagDestroyRights
);
80 AuthorizationRef myAuthRef
;
81 OSStatus stat
= AuthorizationCopyPrivilegedReference(&myAuthRef
,kAuthorizationFlagDefaults
);
83 return stat
== errAuthorizationSuccess
;
86 int main( int argc
, char *argv
[] )
88 NSAutoreleasePool
*pool
= [[NSAutoreleasePool alloc
] init
];
99 printf("Don't forget to flush! ;-) "); // signal back to close caller
102 return NSApplicationMain(argc
, (const char **) argv
);