Hi,
this following, works and I modified myself, but sure will look at yours.
I would give answers not questions! (...) that's when things start to be fun...(and somehow useful)
There were many problems:
- the filehandler needs to be assigned as mov [infile],eax and used as such where is needed, to assigned at the address of the infile.
- set BUFFLEN on "read"
and
mov edx,[size] on "write" after mov [size],eax on "read"
The availability of a filehandle from I/O ops is a minimal requirement to subsequent hubs between files and the basis to link to mmap like operations.
Next I will translate also the mmap example from Wrox book, and put here.
Yes, me again.... As I told, I do not intend to use C libs before being able to know myself how to do it or could do it (for quite large things) in native assembly / NASM / Intel mnemonics.
Ending the party when it could/should begin is not a clever idea, and because I am full time for a while on this, probably will be here frequently.
section .bss ; Section containing uninitialised data
BUFFLEN equ 100
Buffer: resb BUFFLEN ; Buffer to read to
infile: resb 4 ; Input file filehandle
outfile: resb 4 ; Ouput file filehandle
size resb 4
section .data ; Section containing initialised data
section .text ; Section containing code
global _start ; Linker needs this to find the entry point
_start:
nop ; This no-op keeps gdb happy
mov ebp,esp
mov eax,5 ; Specify open sys_call
mov ebx,[ebp+8] ; first argument
mov ecx,00
mov edx,0444
int 80h ; Make kernel call
test eax,eax
js BadFile
; Issue here in setting the filehandle
mov dword [infile],eax
; Open output file second argument
mov eax,5
mov ebx,[ebp+12] ; Second argument
mov ecx,01101
mov edx,0644
int 80h
test eax,eax
js BadFile
mov dword [outfile],eax
Read:
mov eax,3
mov ebx,[infile]
mov ecx,Buffer
mov edx,BUFFLEN
int 80h
test eax,eax
jz Done
js BadFile
mov [size],eax
; Write the file
mov eax,4
mov ebx,[outfile]
mov ecx,Buffer
mov edx,[size]
int 80h
test eax,eax
js BadFile
jmp Read
Done:
mov eax,6 ; Specify close sys_call
mov ebx,[outfile]
int 80h
mov eax,6
mov ebx,[infile]
int 80h
BadFile:
mov ebx,eax
mov eax,1
int 80h
; Exit
mov eax,1
mov ebx,0
int 80h