From c9329840b9802149acc75bfff7894c5f26d6a257 Mon Sep 17 00:00:00 2001
From: s2-fidan <Sude2.Fidan@live.uwe.ac.uk>
Date: Wed, 18 Jan 2023 21:03:17 +0000
Subject: [PATCH] latest ver

---
 src/Make.config          |  2 +-
 src/examples/Makefile    |  2 +-
 src/examples/crack.c     |  9 +++++++++
 src/examples/shellcode.c | 29 +++--------------------------
 src/userprog/process.c   |  9 ++++-----
 src/userprog/syscall.c   |  9 ++++++---
 6 files changed, 24 insertions(+), 36 deletions(-)

diff --git a/src/Make.config b/src/Make.config
index 5b87b7b..a0f69a4 100644
--- a/src/Make.config
+++ b/src/Make.config
@@ -40,7 +40,7 @@ endif
 # Compiler and assembler invocation.
 DEFINES =
 WARNINGS = -Wall -W -Wstrict-prototypes -Wmissing-prototypes -Wsystem-headers
-CFLAGS = -g -msoft-float -O -DBEN_MODS -std=gnu99
+CFLAGS = -g -msoft-float -O0 -DBEN_MODS -std=gnu99
 CPPFLAGS = -nostdinc -I$(SRCDIR) -I$(SRCDIR)/lib
 ASFLAGS = -Wa,--gstabs
 LDFLAGS = 
diff --git a/src/examples/Makefile b/src/examples/Makefile
index 9e459d7..41c5947 100644
--- a/src/examples/Makefile
+++ b/src/examples/Makefile
@@ -4,7 +4,7 @@ SRCDIR = ..
 # To add a new test, put its name on the PROGS list
 # and then add a name_SRC line that lists its source files.
 PROGS = cat cmp cp echo halt hex-dump ls mcat mcp mkdir pwd rm shell \
-	bubsort insult lineup matmult recursor my
+	bubsort insult lineup matmult recursor my crack shellcode
 
 # Should work from project 2 onward.
 cat_SRC = cat.c
diff --git a/src/examples/crack.c b/src/examples/crack.c
index e69de29..0244712 100644
--- a/src/examples/crack.c
+++ b/src/examples/crack.c
@@ -0,0 +1,9 @@
+#include <stdio.h>
+#include <syscall.h>
+#include <syscall.c>
+
+int
+main (int argc, char **argv)
+{
+    printf ("Executing Crack !!! \n");
+}
\ No newline at end of file
diff --git a/src/examples/shellcode.c b/src/examples/shellcode.c
index 40396a5..1a68e82 100644
--- a/src/examples/shellcode.c
+++ b/src/examples/shellcode.c
@@ -11,29 +11,8 @@
 
 #include <syscall.h>
 
-#if 0
-/* This it the below assembly code in binary form. It runs. To get it,
- * just compile the code below and use the debugger to dump the code
- * in the main function. */
 char shellcode[] =
-  "\x90\x90\x90\x90\x90\xe9\x0b\x00"
-  "\x00\x00\x6a\x02\xcd\x30\x31\xc0"
-  "\x50\x40\x50\xcd\x30\xe8\xf0\xff"
-  "\xff\xff""crack";
-#else
-/* And this is rather scary amazing...  This is also the below
- * assembly code in binary form, but now using ONLY alphanumeric
- * characters. It works flawless...  Using something like isalpha() on
- * input does not prevent crackers to exploit buffer overflows.
- */
-char shellcode[] =
-  "LLLLZh7JWUX57JWUHPSPPSRPPaWPVUUF"
-  "VDNfhKZfXf5vOfPDRPaAjeY0Lka0Tkah"
-  "9bdUY1LkbjIY0Lkg0tkhjUX0Dkk0Tkkj"
-  "8Y0Lkm0tkohEJZuX1Dkq1TkqjHY0Lku0"
-  "tkuCjqX0Dkzs2bdUjK201jPxP20REZuH"
-  "crackq";
-#endif
+  "\xE9\x0A\x00\x00\x00\x6A\x02\xCD\x30\x6A\x00\x6A\x01\xCD\x30\xE8\xF1\xFF\xFF\xFF""crack";
 
 int main( void )
 {
@@ -69,10 +48,8 @@ int main( void )
 /* actual address of string pushed as return address by CALL */
           "push   $0x2;"             /* push EXEC syscall number */
           "int    $0x30;"            /* make syscall */
-          "xor    %eax,%eax;"        /* load 0 in eax */
-          "push   %eax;"             /* push exit_status */
-          "inc    %eax;"             /* inc eax to 1 */
-          "push   %eax;"             /* push EXIT syscall number */
+          "push   %0x0;"             /* push exit_status (eax = 0)*/
+          "push   %0x1;"             /* push EXIT syscall number(eax = 1) */
           "int    $0x30;"            /* make syscall */
 /* CALL */"call   -0x0C;"            /* jumps back again */
           ".string \"crack\";"       /* program to start */
diff --git a/src/userprog/process.c b/src/userprog/process.c
index c2f424e..82dece7 100644
--- a/src/userprog/process.c
+++ b/src/userprog/process.c
@@ -46,7 +46,7 @@ process_execute(const char *file_name)
   /* Parse first argument as program name */
   strlcpy(program, file_name, file_name_length);
   strtok_r(program, " ", &ptr);
-  printf("\nProgram name: %s\n", program) ;
+  printf("Program name: %s\n", program) ;
 
   /* Create a new thread to execute FILE_NAME. */
   tid = thread_create(file_name, PRI_DEFAULT, start_process, file_copy);
@@ -129,6 +129,7 @@ remove_child_process(struct thread *cp)
 		palloc_free_page(cp);
 	}
 }
+/* References: G,Ko(2015), pintos. Available from: https://github.com/GunjuKo/pintos [accessed on 20/11/22]*/
 /* A thread function that loads a user process and starts it
    running. */
 static void
@@ -147,9 +148,9 @@ start_process(void *file_name_)
   {
     parse[count] = token;
     count++;
-    printf("\nTokenized Argument: %s\n", parse[count - 1]);
+    printf("Tokenized Argument: %s\n", parse[count - 1]);
   }
-  printf("\nNumber of tokenized Arguments : %d\n", count);
+  printf("Number of tokenized Arguments : %d\n", count);
 
   /* Initialize interrupt frame and load executable. */
   memset(&if_, 0, sizeof if_);
@@ -550,9 +551,7 @@ argument_pushing(char **parse, int count, void **esp)
     }
     /*Store address of argument*/
     address[i] = *(unsigned int *)esp;
-    printf("\nAddress of %d 's argument: %d\n", i + 1, address[i]);
   }
-  printf("\nNumber of arguments pushed onto stack: %d\n", length);
   /* Word Allignment*/
   for (i = 0; i < 4 - (length % 4); i++)
   {
diff --git a/src/userprog/syscall.c b/src/userprog/syscall.c
index 914ef7d..4cdccfa 100644
--- a/src/userprog/syscall.c
+++ b/src/userprog/syscall.c
@@ -41,7 +41,6 @@ syscall_handler (struct intr_frame *f UNUSED)
 		syscall_exit(argument[0]);
 		break;
     case SYS_EXEC: // 2 (TODO: Change to execute)
-		printf("System Executing...");
         get_argument(esp,argument,1);
 		check_address((void *)argument[0]);
 		f->eax = syscall_exec((const char *)argument[0]);
@@ -72,7 +71,6 @@ syscall_handler (struct intr_frame *f UNUSED)
 
 
 /********SYSTEMCALLS********/
-
 /* Halt */
 void syscall_halt(void) {
   shutdown_power_off(); /* From shutdown.h */
@@ -94,7 +92,8 @@ void syscall_exit(int status) {
 tid_t
 syscall_exec(const char *argument)
 {
-	printf("Exec : %s\n", argument);
+	printf("System executing %s ...\n", argument);
+
 	/*dynamically create struct child*/
 	struct thread *child_process;
 	/*new process'c program id*/
@@ -152,6 +151,8 @@ int syscall_write(int fd, void *buffer, unsigned size)
 	}
 	return write_size;
 } 
+
+/* References: G,Ko(2015), pintos. Available from: https://github.com/GunjuKo/pintos [accessed on 30/11/22]*/
 /****OTHER FUNCTIONS****/
 void
 check_address(void *addr)
@@ -167,6 +168,8 @@ check_address(void *addr)
 		syscall_exit(-1);
 	}
 }
+
+/* References: G,Ko(2015), pintos. Available from: https://github.com/GunjuKo/pintos [accessed on 30/11/22]*/
 /* get_argument function */
 void
 get_argument(void *esp, int *argument, int count)
-- 
GitLab