gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r23145 - monkey/branches/MonkeyBacktracking/monkey/src/path


From: gnunet
Subject: [GNUnet-SVN] r23145 - monkey/branches/MonkeyBacktracking/monkey/src/pathologist
Date: Tue, 7 Aug 2012 12:54:18 +0200

Author: safey
Date: 2012-08-07 12:54:18 +0200 (Tue, 07 Aug 2012)
New Revision: 23145

Modified:
   monkey/branches/MonkeyBacktracking/monkey/src/pathologist/pathologist.c
Log:
Check if binary is an ELF

Modified: 
monkey/branches/MonkeyBacktracking/monkey/src/pathologist/pathologist.c
===================================================================
--- monkey/branches/MonkeyBacktracking/monkey/src/pathologist/pathologist.c     
2012-08-06 23:43:59 UTC (rev 23144)
+++ monkey/branches/MonkeyBacktracking/monkey/src/pathologist/pathologist.c     
2012-08-07 10:54:18 UTC (rev 23145)
@@ -45,6 +45,27 @@
 static int reverseExecutionAllowed = MONKEY_NO;
 static int ret = 0;
 
+static int checkELF(const char *binaryPath) {
+       int ch;
+       const char ELF[5] = {0x7f, 'E', 'L', 'F', '\0'}; // ELF magic number
+       char inputArr[5];
+       FILE *filePtr;
+       filePtr = fopen(binaryPath, "r");
+       int i;
+
+       for (i = 0; i < 4; i++) {
+               ch = fgetc(filePtr);
+               if (EOF == ch) {
+                       return MONKEY_NO;
+               }
+               inputArr[i] = ch;
+       }
+       inputArr[4] = '\0';
+       if (strcmp(ELF, inputArr) == 0) {
+               return MONKEY_YES;
+       }
+       return MONKEY_NO;
+}
 /**
  * Main function that will launch Pathologist's action api.
 */
@@ -53,6 +74,35 @@
   int result;
   struct MONKEY_ACTION_Context *cntxt;
 
+  /* Check if the target program is and ELF binary */
+  if (MONKEY_NO == checkELF(binaryName)) {
+         FILE* targetProgramPipe;
+         char *command = NULL;
+         char buffer[128];
+         ret = 1;
+
+         fprintf(stderr, "Target program is not an ELF. Pathologist will not 
debug the program.\n");
+         fprintf(stderr, "Pathologist will attempt to run the program 
normally.\n");
+
+         if (NULL != binaryArgs) {
+                 MONKEY_asprintf(&command, "%s %s", binaryName, binaryArgs);
+         } else {
+                 command = binaryName;
+         }
+         targetProgramPipe = popen(command, "r");
+         if (NULL == targetProgramPipe) {
+                 fprintf(stderr, "Target is not a binary.\n");
+                 return;
+         }
+         while(!feof(targetProgramPipe)) {
+                 if (NULL != fgets(buffer, 128, targetProgramPipe)) {
+                         fputs(buffer, stderr);
+                 }
+         }
+         pclose(targetProgramPipe);
+         return;
+  }
+
   if (NULL == edbFilePath)
     {
       /* lookup a file named test.db in the working directory */




reply via email to

[Prev in Thread] Current Thread [Next in Thread]