From 452ad7813ddd6f95166ecc151db2f12b10745ab2 Mon Sep 17 00:00:00 2001 From: Sascha Tommasone Date: Sat, 8 Jun 2024 18:12:30 +0200 Subject: [PATCH] [Assignment-5] added solution task 3 (syscalling) --- .../syscalling/code.asm | 53 ++++++++++++++++--- 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/Assignment 5 - Software Security - Teil 1/syscalling/code.asm b/Assignment 5 - Software Security - Teil 1/syscalling/code.asm index 6152f8d..374be3e 100644 --- a/Assignment 5 - Software Security - Teil 1/syscalling/code.asm +++ b/Assignment 5 - Software Security - Teil 1/syscalling/code.asm @@ -5,15 +5,54 @@ %define O_CREAT 00000100o %define O_TRUNC 00001000o %define S_IRUSR 00000400o -%define S_IWUSR 00000200o +%define S_IWUSR 00000200o + section .data -path: db "/home/user/nachricht", 0 -greeting: db "hidad!", 0 + path: db "/home/user/nachricht", 0 + greeting: db "hidad!", 0 + ; https://stackoverflow.com/a/45386640 + length equ $ - greeting ; Length of greeting message + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; https://chromium.googlesource.com/chromiumos/docs/+/master/constants/syscalls.md#x86-32_bit; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; section .text -global _start +global _start _start: - ;---------------------------------- - nop ; - ; ------------ End of file ------------ + call _open ; open file + call _write ; write to file + call _close ; close file + call _exit ; exit without errors + +; https://www.man7.org/linux/man-pages/man2/open.2.html +_open: + mov eax, 0x05 ; syscall number for 'open' + mov ebx, path ; pointer to the path string + mov ecx, O_CREAT ; open the file if it doesn't exist + xor ecx, O_WRONLY ; open the file in write-only mode + mov edx, S_IRUSR ; permissions for the file + int 0x80 ; call kernel + +; https://man7.org/linux/man-pages/man2/write.2.html +_write: + mov ebx, eax ; file descriptor returned by 'open' + mov eax, 0x04 ; syscall number for 'write' + mov ecx, greeting ; pointer to the greeting message + mov edx, length ; length of the greeting message + sub edx, 0x01 ; length of the greeting message without null byte + int 0x80 ; call kernel + +; https://man7.org/linux/man-pages/man2/close.2.html +_close: + mov eax, 0x06 ; syscall number for 'close' + int 0x80 ; call kernel + +; https://man7.org/linux/man-pages/man2/exit.2.html +_exit: + mov eax, 1 ; syscall number for 'exit' + mov ebx, 0 ; exit status + int 0x80 ; call kernel +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;