flat assembler
Message board for the users of flat assembler.

Index > Linux > Command line

Author
Thread Post new topic Reply to topic
a16b03



Joined: 24 Jan 2006
Posts: 43
Location: Riga, Latvia
a16b03
Can someone please explain how to get the lenght of last
command line argument. Yes I did look at Fasm source, but
still i don't get it.
Post 04 Jun 2006, 22:13
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Feryno



Joined: 23 Mar 2005
Posts: 449
Location: Czech republic, Slovak republic
Feryno
i386
sample:
./executable hoho zzzzzz
dword [esp+4*0] = argc = number of arguments = 3 in above sample
dword [esp+4*1] = address of param0, points to string './executable',0 somewhere in the stack space
dword [esp+4*2] = address of param1, points to string 'hoho',0 somewhere in the stack space
dword [esp+4*3] = address of param2, points to string 'zzzzzz',0 somewhere in the stack space
dword [esp+4*4] = 0 end of arguments
dword [esp+4*5] = pointer to first 0-termintated string of environment
dword [esp+4*6] = pointer to second ...
dword [esp+4*...] = 0 end of environment

start:
pop ecx ; number of arguments, is never 0, because at least arg0 = name of executable
mov edi,dword [esp+ecx*4]
; now we have address of string pointing to the last argument with 0-terminator
mov edx,0FFFFFFFEh
mov ecx,0FFFFFFFFh ; large enough, string is everytime shorter
mov al,0 ; find 0-terminator
cld
repnz scasb
sub edx,ecx
; edx = size of string

AMD64 is similar
dword [rsp+8*0] = argc
qword [rsp+8*1] = argv
...
qword [rsp+8*(argc+1)]=0 end of arguments
qword [rsp+8*(argc+2)] address of first 0-terminated string of environment
qword [rsp+8*...] = 0 end of environment
mov ecx,dword [rsp]
mov rdi,qword [rsp+8+rcx*8]
mov rdx,-2
mov rcx,-1
mov al,0
cld
repnz scasb
sub rdx,rcx


Last edited by Feryno on 05 Jun 2006, 12:22; edited 1 time in total
Post 05 Jun 2006, 07:52
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
a16b03



Joined: 24 Jan 2006
Posts: 43
Location: Riga, Latvia
a16b03
Yes that was just what i suspected.

But it didn't worked.
I gues I have bun in code,

Tanks, for info.
Now I'm 100% shore.
Post 05 Jun 2006, 09:29
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.