flat assembler
Message board for the users of flat assembler.

Index > Windows > Command Line Arguments Help.

Goto page 1, 2, 3  Next
Author
Thread Post new topic Reply to topic
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 24 Oct 2010, 14:03
Hello everyone! I'm trying to make command line program but I don't know how to do that fine.. and with WinAPI functions not from msvcrt.. I tried GetCommandLine but I dont know how to check arguments and load it in program.. can someone write example like this structure:
Parameters should be 2 only if not jmp error.
load parameters into registers so I can read what arguments are there.
then try to messagebox, 1st argument = Text 2nd argument=Title.

Can someone write example of this ? Smile Thanks.
Post 24 Oct 2010, 14:03
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 24 Oct 2010, 14:10
Overflowz,

You may import CommandLineToArgvW() from Shell32.DLL and use its result in familiar C style (I suppose).
Code:
        format  PE
        include "Win32WX.Inc"
        include "Win32X+.Inc"

        .code
        invoke  shell32::CommandLineToArgvW, <invoke GetCommandLine>, argc
        mov     esi, eax
        cinvoke MSVCRT::wprintf, _argc, [argc]
        cinvoke _putws, _banner
        .repeat
          cinvoke MSVCRT::_putws, dword[esi]
          add     esi, 4
          dec     [argc]
        .until  ZERO?
        ret

        .data
_argc   TCHAR   "argc: %u", 10, 0
_banner TCHAR   "argv[]:", 0
        align   4
argc    rd      1

        .end    
Post 24 Oct 2010, 14:10
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 24 Oct 2010, 15:03
baldr: (nitpick) why do you use "TCHAR" for what is widechar buffer (nonportable to ANSI)?
Post 24 Oct 2010, 15:03
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1405
Location: Piraeus, Greece
Picnic 24 Oct 2010, 15:43
Vortex old example should do for your simple needs. Search board Overflowz.
Code:
            invoke LocalAlloc, LMEM_ZEROINIT, MAX_PATH
            mov ebx, eax
            mov esi, eax
            invoke GetCommandLine
            lea edx, [eax-1]
            xor eax, eax
            lea edi, [ebx+32]
            mov ch, 32
.CL0:       inc edx
            mov cl, [edx]
            test cl, cl
            jz .CL4
            cmp cl, 32
            jz .CL0
            inc eax
            mov [ebx], edi
            add ebx, 4
.CL1:       mov cl, [edx]
            test cl, cl
            jz .CL4
            cmp cl, ch
            jz  .CL3
            cmp cl, 34
            jnz @F
            xor ch, 32
            jmp .CL2
@@:         mov [edi], cl
            inc edi
.CL2:       inc edx
            jmp .CL1
.CL3:       mov byte [edi], 0
            inc edi
            jmp .CL0
.CL4:       cmp eax, 3   ;parameters should be 2 only
            jz @F

            ;error parameters

@@:         ;dword [esi+4] = Parameter 1
            ;dword [esi+8] = Parameter 2
    
Post 24 Oct 2010, 15:43
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 24 Oct 2010, 15:55
vid,

Reference to wcstombs() probably will confuse respondent. That's kinda elements of a good style, to use tools provided. Wink
Post 24 Oct 2010, 15:55
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 24 Oct 2010, 16:04
baldr, thanks I'll try to learn that.
Picnic, searched but didn't found any "good example for me" thats hard for me and long Razz
Post 24 Oct 2010, 16:04
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 24 Oct 2010, 16:22
Quote:
Reference to wcstombs() probably will confuse respondent. That's kinda elements of a good style, to use tools provided.

I meant to make it simpler, not more complicated: keeping it widechar-only, and using "du" instead of TCHAR. That ANSI/Unicode portability doesn't work in Asm anyway without writing lot of extra code, and I still don't understand who was the genius that introduced TCHAR to Asm.
Post 24 Oct 2010, 16:22
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 24 Oct 2010, 16:30
Picnic,

Paraphrasing what my mother said once, "never use 32 or 0x20 instead of ' ' when you do mean latter exactly, unless you're going to confuse reader or you don't have the choice". Wink
Post 24 Oct 2010, 16:30
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 24 Oct 2010, 18:38
I'll write code and someone fix my code please. Just for me to learn cause those sources is difficult for me.. here's mine:
Code:
format PE console
include 'WIN32AX.INC'
entry main
section '.data' data readable writeable
argv dd ?
argc dd ?
env dd ?
buffer rb 10
section '.text' code readable executable
proc main
invoke GetCommandLine
invoke CommandLineToArgvW,eax,argc
invoke printf,argv
invoke ExitProcess,0
endp
section '.idata' import data readable
library user32,'user32.dll',kernel32,'kernel32.dll',shell32,'shell32.dll',msvcrt,'msvcrt.dll'
include 'API\USER32.INC'
include 'API\KERNEL32.INC'
include 'API\SHELL32.INC'
import msvcrt,printf,'printf'    

and I have some questions.
#1 how to compare how many arguments are passed ?
#2 how to print 1st, 2nd, 3nd.. etc arguments ?

P.S this code doesn't work..
Post 24 Oct 2010, 18:38
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 24 Oct 2010, 19:06
Overflowz,

How do you expect argv to be filled?
Post 24 Oct 2010, 19:06
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 24 Oct 2010, 19:26
I dont know nothing about this just some working example.. I'm just guessing what I'm doing.. but this code is easy to understand for me but I dont need msvcrt support and putws and TCHAR things. I dont know em..
Post 24 Oct 2010, 19:26
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 24 Oct 2010, 19:50
Command Line Parameters example on the examples page.
Post 24 Oct 2010, 19:50
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 24 Oct 2010, 20:09
Right.. can you just CUT main code of using command line things ? cause I dont understand alooot of there.. for example:
where the code checks how much arguments there..
how argv1 argv2 ... moves into messagebox
and alot of things.. just type main and little example please ? Smile
Post 24 Oct 2010, 20:09
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 24 Oct 2010, 21:01
Code:
int argc;
char **argv;
argv = CommandLineToArgvA(GetCommandLineA(), &argc);
    

It's that easy.
Post 24 Oct 2010, 21:01
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 24 Oct 2010, 21:25
Tyler: No, it's not. Next time please test your code first Razz
Post 24 Oct 2010, 21:25
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 24 Oct 2010, 21:39
dude, please read first post what I'm trying to do.
Quote:
example like this structure:
Parameters should be 2 only if not jmp error.
load parameters into registers so I can read what arguments are there.
then try to messagebox, 1st argument = Text 2nd argument=Title.

just LITTLE example..
Post 24 Oct 2010, 21:39
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 24 Oct 2010, 21:44
baldr gave you example, just instead of using MessageBox he displayed all parameters in loop to console.
Post 24 Oct 2010, 21:44
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 24 Oct 2010, 21:49
Overflowz wrote:
dude, please read first post what I'm trying to do.
Quote:
example like this structure:
Parameters should be 2 only if not jmp error.
load parameters into registers so I can read what arguments are there.
then try to messagebox, 1st argument = Text 2nd argument=Title.

just LITTLE example..
I read the first post, but what good does it do anyone for me, or anyone else, to do it for you. There's 2 basic reasons you're doing it, for fun, or for an assignment. If for fun, what fun is it to have it done for you? And if for an assignment, I don't do assignments for people. I'm assuming for fun, since it's really simple.

What exactly can't you do? After you've got the args in argc/v form, everything else is, or at least should be, trivial.

vid: What's wrong with the code I posted? I didn't intend to give a full solution, if that's what you mean.


Last edited by Tyler on 24 Oct 2010, 21:55; edited 1 time in total
Post 24 Oct 2010, 21:49
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz 24 Oct 2010, 21:49
Yes but I don't understand where it compares how many arguments there and without using C library..
Post 24 Oct 2010, 21:49
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 24 Oct 2010, 22:01
Overflowz wrote:
Yes but I don't understand where it compares how many arguments there and without using C library..

Me wrote:

Code:
int argc;
char **argv;
argv = argv = CommandLineToArgvA(GetCommandLineA(), &argc);
    


Um... it's passed by reference into the argc... which was passed by reference. Why else would it require a reference to an int, which I named argc to emphasise it's purpose?
Post 24 Oct 2010, 22:01
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2, 3  Next

< 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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.