3 * The Cheat - The legendary universal game trainer for Mac OS X.
4 * http://www.brokenzipper.com/trac/wiki/TheCheat
6 * Copyright (c) 2003-2011, Charles McGarvey et al.
8 * Distributable under the terms and conditions of the 2-clause BSD
9 * license; see the file COPYING for the legal text of the license.
12 #import <Cocoa/Cocoa.h>
13 #import <Foundation/foundation.h>
14 #import <SecurityFoundation/SFAuthorization.h>
15 #import <Security/AuthorizationTags.h>
17 #include <sys/types.h>
23 * I think this function was ripped from the iHaxGamez project, so it
24 * remains licensed under the GPL.
26 void authMe(char * FullPathToMe
)
28 // get authorization as root
32 // set up Authorization Item
33 AuthorizationItem myItems
[1];
34 myItems
[0].name
= kAuthorizationRightExecute
;
35 myItems
[0].valueLength
= 0;
36 myItems
[0].value
= NULL
;
39 // Set up Authorization Rights
40 AuthorizationRights myRights
;
41 myRights.count
= sizeof (myItems
) / sizeof (myItems
[0]);
42 myRights.items
= myItems
;
44 // set up Authorization Flags
45 AuthorizationFlags myFlags
;
47 kAuthorizationFlagDefaults |
48 kAuthorizationFlagInteractionAllowed |
49 kAuthorizationFlagExtendRights
;
51 // Create an Authorization Ref using Objects above. NOTE: Login bod comes up with this call.
52 AuthorizationRef myAuthorizationRef
;
53 myStatus
= AuthorizationCreate (&myRights
, kAuthorizationEmptyEnvironment
, myFlags
, &myAuthorizationRef
);
55 if (myStatus
== errAuthorizationSuccess
)
57 // prepare communication path - used to signal that process is loaded
58 FILE *myCommunicationsPipe
= NULL
;
59 char myReadBuffer
[] = " ";
61 // run this app in GOD mode by passing authorization ref and comm pipe (asynchoronous call to external application)
62 myStatus
= AuthorizationExecuteWithPrivileges(myAuthorizationRef
,FullPathToMe
,kAuthorizationFlagDefaults
,nil,&myCommunicationsPipe
);
64 // external app is running asynchronously - it will send to stdout when loaded
65 if (myStatus
== errAuthorizationSuccess
)
67 read (fileno (myCommunicationsPipe
), myReadBuffer
, sizeof (myReadBuffer
));
68 fclose(myCommunicationsPipe
);
71 // release authorization reference
72 myStatus
= AuthorizationFree (myAuthorizationRef
, kAuthorizationFlagDestroyRights
);
77 * I think this function was ripped from the iHaxGamez project, so it
78 * remains licensed under the GPL.
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"]);
89 * I think this function was ripped from the iHaxGamez project, so it
90 * remains licensed under the GPL.
95 AuthorizationRef myAuthRef
;
96 OSStatus stat
= AuthorizationCopyPrivilegedReference(&myAuthRef
,kAuthorizationFlagDefaults
);
98 return stat
== errAuthorizationSuccess ||
checkExecutablePermissions();
101 int main( int argc
, char *argv
[] )
103 NSAutoreleasePool
*pool
= [[NSAutoreleasePool alloc
] init
];
113 printf("Don't forget to flush! ;-) "); // signal back to close caller
118 return NSApplicationMain(argc
, (const char **) argv
);