From f37c53c85dcd75920b1aa22aba6311fa426dfe1e Mon Sep 17 00:00:00 2001 From: teoberi Date: Thu, 23 May 2024 09:25:03 +0300 Subject: [PATCH] Change test files for Fortify --- tests/binaries/{helloworld.c => fszero.c} | 2 ++ tests/binaries/hello.S | 18 ------------------ tests/binaries/main.c | 7 ------- tests/binaries/nolibc.asm | 23 +++++++++++++++++++++++ tests/binaries/nolibc32.asm | 23 +++++++++++++++++++++++ tests/binaries/start.S | 5 ----- 6 files changed, 48 insertions(+), 30 deletions(-) rename tests/binaries/{helloworld.c => fszero.c} (69%) delete mode 100644 tests/binaries/hello.S delete mode 100644 tests/binaries/main.c create mode 100644 tests/binaries/nolibc.asm create mode 100644 tests/binaries/nolibc32.asm delete mode 100644 tests/binaries/start.S diff --git a/tests/binaries/helloworld.c b/tests/binaries/fszero.c similarity index 69% rename from tests/binaries/helloworld.c rename to tests/binaries/fszero.c index c3ce445..fc88b61 100644 --- a/tests/binaries/helloworld.c +++ b/tests/binaries/fszero.c @@ -1,7 +1,9 @@ #include +#include int main() { printf("Hello World\n"); + sleep(2); return 0; } diff --git a/tests/binaries/hello.S b/tests/binaries/hello.S deleted file mode 100644 index 5b5e727..0000000 --- a/tests/binaries/hello.S +++ /dev/null @@ -1,18 +0,0 @@ -.section .text -.global hello -hello: - movl $len,%edx # third argument: message length - movl $msg,%ecx # second argument: pointer to message to write - movl $1,%ebx # first argument: file handle (stdout) - movl $4,%eax # system call number (sys_write) - int $0x80 # call kernel - - # and exit - - movl $0,%ebx # first argument: exit code - movl $1,%eax # system call number (sys_exit) - int $0x80 # call kernel -.section .data - msg: - .ascii "Hello, world!\n" # our dear string - len = . - msg # length of our dear string diff --git a/tests/binaries/main.c b/tests/binaries/main.c deleted file mode 100644 index 21618b8..0000000 --- a/tests/binaries/main.c +++ /dev/null @@ -1,7 +0,0 @@ -extern void hello(); - -int main() -{ - hello(); - return 0; -} diff --git a/tests/binaries/nolibc.asm b/tests/binaries/nolibc.asm new file mode 100644 index 0000000..c51ea17 --- /dev/null +++ b/tests/binaries/nolibc.asm @@ -0,0 +1,23 @@ +section .data + msg db 'Hello, World!', 0ah ;note the newline (Line Feed-LF) at the end (hex:0ah; decimal:10) + len equ $ - msg ;calculate the length of the message + delay dq 2, 100000000 ;define delay with Timespec structure members tv_sec, tv_nsec (qwords, 64-bit integer values) + +section .text + global _start ;must be declared for linker (ld) + +_start: ;tells linker entry point + mov rax, 1 ;system call for write (sys_write 1) + mov rdi, 1 ;file descriptor (1 is stdout) + mov rsi, msg ;address of string to output + mov rdx, len ;message length + syscall ;invoke operating system to do the write + + mov rax, 35 ;system call for nanosleep (sys_nanosleep 35) + mov rdi, delay ;load the pointer to our delay + mov rsi, 0 ;exit code 0 + syscall ;invoke operating system to do the delay + + mov rax, 60 ;system call for exit (sys_exit 60) + xor rdi, rdi ;exit code 0 + syscall ;invoke operating system to exit diff --git a/tests/binaries/nolibc32.asm b/tests/binaries/nolibc32.asm new file mode 100644 index 0000000..c016d93 --- /dev/null +++ b/tests/binaries/nolibc32.asm @@ -0,0 +1,23 @@ +section .data + msg db "Hello, world!", 0xa ;note the newline (Line Feed-LF) at the end (hex:0ah; decimal:10) + len equ $ - msg ;calculate the length of the message + delay dd 2, 100000000 ;define delay with Timespec structure members tv_sec, tv_nsec (dwords, 32-bit integer values) + +section .text + global _start ;must be declared for linker (ld) + +_start: ;tells linker entry point + mov eax,4 ;system call for write (sys_write 4) + mov ebx,1 ;file descriptor (1 is stdout) + mov ecx,msg ;address of string to output + mov edx,len ;message length + int 0x80 ;invoke operating system to do the write + + mov eax, 162 ;system call for nanosleep (sys_nanosleep 162) + mov ebx, delay ;load the pointer to our delay + mov ecx, 0 ;exit code 0 + int 0x80 ;invoke operating system to do the delay + + mov eax,1 ;system call for exit (sys_exit 1) + xor ebx, ebx ;exit code 0 + int 0x80 ;invoke operating system to exit diff --git a/tests/binaries/start.S b/tests/binaries/start.S deleted file mode 100644 index 2981576..0000000 --- a/tests/binaries/start.S +++ /dev/null @@ -1,5 +0,0 @@ -.globl _start -_start:call main - movl $1, %eax - xorl %ebx, %ebx - int $0x80