ASM 120: Files (55 pts)

What You Need

Purpose

To practice file input and output using x86 assembly code.

Writing to a File

Create this "write.asm" file:
section  .text
global   _start

_start:

    mov  eax, 8           ; 8 = sys_creat
    mov  ebx, filename
    mov  ecx, 700o        ; Permissions: 700 octal (rwx------)
    int  0x80

    mov [fd], eax         ; file descriptor

    mov  eax, 4           ; 4 = sys_write
    mov  ebx, [fd]
    mov  ecx, msg
    mov  edx, len
    int  0x80

    mov  eax, 6           ; 6 = sys_close
    mov  ebx, [fd]
    int  0x80

    mov  eax, 1           ; 1 = sys_exit
    int  0x80

section  .data
filename db   "write.txt", 0
msg      db   "Hello World!"
len      equ  $ - msg
fd       db   0, 0, 0, 0
Execute these commands to compile, link, and run the program, and see the results:
nasm -f elf32 write.asm
ld -m elf_i386 -o write write.o
./write
ls -l w*
cat write.txt
The program runs, creating a "write.txt" file, as shown below.

ASM 120.1: File Length (5 pts)

In the shell, execute these commands:
sudo apt update
sudo apt install wget -y
wget https://samsclass.info/127/proj/ASM120
Write a program that reads every byte in that file and counts them. The flag is the length of the file in hexadecimal.

Useful References

ASM 120.2: Skip Bytes (10 pts)

Use the same ASM120 file.

Skip the first 230 bytes. Print out the next six bytes to see the flag.

ASM 120.3: Third N (10 pts)

Use the same ASM120 file.

Find the third capital N. Read five more letters to complete the flag.

ASM 120.4: Fifth (10 pts)

Use the same ASM120 file.

Print every fifth character to see the flag.

ASM 120.5: Nth (20 pts)

Use the same ASM120 file.

Gather every Nth character to see the flag. You don't know Nn.

Sources

System calls in the Linux kernel. Part 1.
X86 Assembly/Interfacing with Linux
Linux System Call Table (32-bit)
List of Linux/i386 system calls
Assembly Programming Tutorial
NASM Assembly Language Tutorials - asmtutor.com


Posted 7-16-2020
Hint added to ASM 100.18 7-17-2020