[lug] Linux syscall 19 lseek() produces unexpected output
Ted Logan
ted.logan at gmail.com
Mon Oct 29 09:47:24 MDT 2007
Do you want:
mov edx, 2 ; edx - SEEK_END
instead of:
sub edx, 2 ; edx - SEEK_END
That is, assigning edx = SEEK_END, rather than subtracting 2 from
whatever value edx held before?
On 10/29/07, Carl Hamlin <carl at eceria.com> wrote:
> -----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-----
> _______________________________________________
> Web Page: http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: lug.boulder.co.us port=6667 channel=#colug
>
--
Ted Logan
Software Engineer
ted.logan at gmail.com
http://jaeger.festing.org/
More information about the LUG
mailing list