]> Dogcows Code - chaz/thecheat/blob - main.m
The Cheat 1.2.3
[chaz/thecheat] / main.m
1
2 // **********************************************************************
3 // The Cheat - A universal game cheater for Mac OS X
4 // (C) 2003-2005 Chaz McGarvey (BrokenZipper)
5 //
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)
9 // any later version.
10 //
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.
15 //
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.
19 //
20
21 #import <Cocoa/Cocoa.h>
22 #import <Foundation/foundation.h>
23 #import <SecurityFoundation/SFAuthorization.h>
24 #import <Security/AuthorizationTags.h>
25 #include "ChazLog.h"
26
27 void authMe(char * FullPathToMe)
28 {
29 // get authorization as root
30
31 OSStatus myStatus;
32
33 // set up Authorization Item
34 AuthorizationItem myItems[1];
35 myItems[0].name = kAuthorizationRightExecute;
36 myItems[0].valueLength = 0;
37 myItems[0].value = NULL;
38 myItems[0].flags = 0;
39
40 // Set up Authorization Rights
41 AuthorizationRights myRights;
42 myRights.count = sizeof (myItems) / sizeof (myItems[0]);
43 myRights.items = myItems;
44
45 // set up Authorization Flags
46 AuthorizationFlags myFlags;
47 myFlags =
48 kAuthorizationFlagDefaults |
49 kAuthorizationFlagInteractionAllowed |
50 kAuthorizationFlagExtendRights;
51
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);
55
56 if (myStatus == errAuthorizationSuccess)
57 {
58 // prepare communication path - used to signal that process is loaded
59 FILE *myCommunicationsPipe = NULL;
60 char myReadBuffer[] = " ";
61
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);
64
65 // external app is running asynchronously - it will send to stdout when loaded
66 if (myStatus == errAuthorizationSuccess)
67 {
68 read (fileno (myCommunicationsPipe), myReadBuffer, sizeof (myReadBuffer));
69 fclose(myCommunicationsPipe);
70 }
71
72 // release authorization reference
73 myStatus = AuthorizationFree (myAuthorizationRef, kAuthorizationFlagDestroyRights);
74 }
75 }
76
77 bool amIWorthy(void)
78 {
79 // running as root?
80 AuthorizationRef myAuthRef;
81 OSStatus stat = AuthorizationCopyPrivilegedReference(&myAuthRef,kAuthorizationFlagDefaults);
82
83 return stat == errAuthorizationSuccess;
84 }
85
86 int main( int argc, char *argv[] )
87 {
88 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
89
90 ChazLogDisable();
91
92 ChazDebugSetup();
93 ChazMapLogToDebug();
94
95 [pool release];
96
97 if (amIWorthy())
98 {
99 printf("Don't forget to flush! ;-) "); // signal back to close caller
100 fflush(stdout);
101
102 return NSApplicationMain(argc, (const char **) argv);
103 }
104 else
105 {
106 authMe(argv[0]);
107 return 0;
108 }
109
110 ChazDebugCleanup();
111 }
This page took 0.032616 seconds and 4 git commands to generate.