]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
anti-debugging experiment
authorRudolf Polzer <divverent@alientrap.org>
Mon, 4 Jun 2012 08:05:00 +0000 (10:05 +0200)
committerRudolf Polzer <divverent@alientrap.org>
Mon, 4 Jun 2012 08:05:00 +0000 (10:05 +0200)
sys_linux.c

index 0b954301e6c0d92927cfcecad7a17cac0df4f86d..4db3811c813eacf18307c8d97b5c0c8262581ad1 100644 (file)
@@ -146,8 +146,67 @@ void Sys_InitConsole (void)
 {
 }
 
+#ifdef ANTICHEAT
+# ifndef WIN32
+#  include <sys/ptrace.h>
+#  include <sys/wait.h>
+#  include <errno.h>
+# endif
+#endif
+static void anticheat_init(void)
+{
+#ifdef ANTICHEAT
+#define FAIL exit(42)
+
+       // anti ptrace; also, make a forked process copy to detach from debuggers
+# ifndef WIN32
+       pid_t pid = fork();
+       if(pid < 0)
+               FAIL;
+       if(pid == 0)
+       {
+               // nothing to do here
+       }
+       else
+       {
+               // parent
+               int status;
+               if(ptrace(PTRACE_ATTACH, pid, NULL, NULL) < 0)
+               {
+                       kill(pid, SIGKILL);
+                       FAIL;
+               }
+               for(;;)
+               {
+                       if(waitpid(pid, &status, 0) == (pid_t) -1)
+                       {
+                               if(errno == ECHILD) // process no longer exists
+                                       FAIL;
+                       }
+                       if(WIFEXITED(status))
+                       {
+                               exit(WEXITSTATUS(status));
+                       }
+                       if(WIFSTOPPED(status))
+                       {
+                               printf("ptrace: continue... (signal: %d)\n", (int) WSTOPSIG(status));
+                               if(ptrace(PTRACE_CONT, pid, (void *) WSTOPSIG(status), NULL) < 0)
+                               {
+                                       perror("okay.png");
+                               }
+                       }
+               }
+               // never gonna get to here
+       }
+# endif
+
+#endif
+}
+
 int main (int argc, char **argv)
 {
+       anticheat_init();
+
        signal(SIGFPE, SIG_IGN);
 
        com_argc = argc;