The tutorial for today is a simple one.
I will show you how to delete the file created with in the last tutorial.
Let’s create a new file named delete_file.fasm and used to delete the new_file.txt.
1 2 3 4 5 6 7 8 9 10 11 | [mythcat@desk ~]$ cd fasm/ [mythcat@desk fasm]$ vim delete_file.fasm [mythcat@desk fasm]$ ./fasm.x64 delete_file.fasm flat assembler version 1.73.16 (16384 kilobytes memory, x64) 2 passes, 170 bytes. [mythcat@desk fasm]$ ls new_file.txt new_file.txt [mythcat@desk fasm]$ ./delete_file [mythcat@desk fasm]$ ls new_file.txt ls: cannot access 'new_file.txt': No such file or directory [mythcat@desk fasm]$ |
In the file delete_file.fasm I used the int 0x80 and mov rax, 10.
The kernel is accessed using int 80h with delete function set with mov rax, 10.
Also, 64-bit x86 uses syscall instead of interrupt 0x80, see this webpage.
Let’s see the source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | format ELF64 executable entry _start filename db "new_file.txt", 0 _start: mov rax, 10 mov rbx, filename int 0x80 call exit exit: mov rax, 1 mov rbx, 0 int 0x80 |