[lug] Linux syscall 19 lseek() produces unexpected output
Carl Hamlin
carl at eceria.com
Mon Oct 29 09:06:21 MDT 2007
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Folks, I am *really* stumped. Here's the code:
section .data
fd1 dd 0
testd db 'Generic Text'
testsz equ $ - testd
section .text
global _start
_start:
pop ebx ; ebx - argc
pop ebx ; ebx - argv
pop ebx ; ebx - filename to write to
mov eax, 8 ; eax - syscall_creat
mov ecx, 00664Q ; ecx - read/write
int 80h ; syscall_creat
mov [fd1], eax ; eax - file descriptor
mov eax, 19 ; eax - syscall_lseek
mov ebx, [fd1] ; ebx - file descriptor
sub ecx, ecx ; ecx - offset 0
sub edx, 2 ; edx - SEEK_END
int 80h ; syscall_lseek
mov eax, 4 ; eax - syscall_write
mov ebx, [fd1] ; ebx - file descriptor
mov ecx, testd ; ecx - pointer to data to be
; written
mov edx, testsz ; edx - number of bytes to be
; written
int 80h ; syscall_write
mov eax, 1 ; eax - syscall_exit
sub ebx, ebx ; ebx - errorcode 0
int 80h ; syscall_exit
This code *should* write 'Generic Text' at the end of a file specified
on the command line.
What it does instead is to overwrite the file, if it exists. I've tried
using open() instead of creat() with no luck. There is *very* little
documentation on this on the internet, and believe me, if there is
something that specifically referenced lseek(), I've seen it. This is my
third day trying to figure this out.
Can anyone tell me what gives here?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFHJfbahnZ133XoNC8RAkonAJ967lou8BRgp8w5j4UGayHWF2//XgCaAggM
ec34snK9u4YsMZ3e/Uxoto0=
=K0Ja
-----END PGP SIGNATURE-----
More information about the LUG
mailing list