]> Dogcows Code - chaz/thecheat/blobdiff - Process.m
update contact information and project URL
[chaz/thecheat] / Process.m
index 3fe3a69d161c0e477a8b25369e6204a070d92dc9..1fd82da89919181611b2b15e8636bc0ff7902075 100644 (file)
--- a/Process.m
+++ b/Process.m
@@ -1,25 +1,20 @@
 
-// **********************************************************************
-// The Cheat - A universal game cheater for Mac OS X
-// (C) 2003-2005 Chaz McGarvey (BrokenZipper)
-// 
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 1, or (at your option)
-// any later version.
-// 
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
-// 
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-// 
+/*
+ * The Cheat - The legendary universal game trainer for Mac OS X.
+ * http://www.brokenzipper.com/trac/wiki/TheCheat
+ *
+ * Copyright (c) 2003-2011, Charles McGarvey et al.
+ *
+ * Distributable under the terms and conditions of the 2-clause BSD
+ * license; see the file COPYING for the legal text of the license.
+ */
 
 #import "Process.h"
 
+#if defined(__i386__) || defined(__x86_64__)
+       #import <sys/types.h>
+       #import <sys/sysctl.h>
+#endif
 
 @interface Process ( PrivateAPI )
 
        return NO;
 }
 
-- (unsigned)hash
+#if MAC_OS_X_VERSION_10_5 <= MAC_OS_X_VERSION_MAX_ALLOWED
+- (NSUInteger)hash
+#else
+- (unsigned int)hash
+#endif
 {
        return [[NSString stringWithFormat:@"%@%@%u", _name, _version, _pid] hash];
 }
        return NO;
 }
 
+#pragma mark Detecting Emulation
+
+#if defined(__i386__) || defined(__x86_64__)
+// http://developer.apple.com/documentation/MacOSX/Conceptual/universal_binary/universal_binary_exec_a/universal_binary_exec_a.html
+static int sysctlbyname_with_pid (const char *name, pid_t pid,
+                                                                 void *oldp, size_t *oldlenp,
+                                                                 void *newp, size_t newlen)
+{
+    if (pid == 0) {
+        if (sysctlbyname(name, oldp, oldlenp, newp, newlen) == -1)  {
+            fprintf(stderr, "sysctlbyname_with_pid(0): sysctlbyname  failed:"
+                                       "%s\n", strerror(errno));
+            return -1;
+        }
+    } else {
+        int mib[CTL_MAXNAME+1];
+        size_t len = CTL_MAXNAME;
+        if (sysctlnametomib(name, mib, &len) == -1) {
+            fprintf(stderr, "sysctlbyname_with_pid: sysctlnametomib  failed:"
+                                       "%s\n", strerror(errno));
+            return -1;
+        }
+        mib[len] = pid;
+        len++;
+        if (sysctl(mib, len, oldp, oldlenp, newp, newlen) == -1)  {
+            fprintf(stderr, "sysctlbyname_with_pid: sysctl  failed:"
+                    "%s\n", strerror(errno));
+            return -1;
+        }
+    }
+    return 0;
+}
+
+// http://developer.apple.com/documentation/MacOSX/Conceptual/universal_binary/universal_binary_exec_a/universal_binary_exec_a.html
+static int is_pid_native (pid_t pid)
+{
+    int ret = 0;
+    size_t sz = sizeof(ret);
+       
+    if (sysctlbyname_with_pid("sysctl.proc_native", pid,
+                                                         &ret, &sz, NULL, 0) == -1) {
+               if (errno == ENOENT) {
+            return 1;
+        }
+        fprintf(stderr, "is_pid_native: sysctlbyname_with_pid  failed:"
+                "%s\n", strerror(errno));
+        return -1;
+    }
+    return ret;
+}
+#endif
+
+- (BOOL)isEmulated
+{
+       BOOL isEmulated = NO;
+#if defined(__i386__) || defined(__x86_64__)
+       if (is_pid_native(_pid) == 0)
+       {
+               isEmulated = YES;
+       }
+#endif
+       
+       return isEmulated;
+}
 
 #pragma mark Accessors
 
This page took 0.021877 seconds and 4 git commands to generate.