flat assembler
Message board for the users of flat assembler.

Index > Windows > Command Line Arguments Help.

Goto page Previous  1, 2, 3  Next
Author
Thread Post new topic Reply to topic
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Tyler wrote:
vid: What's wrong with the code I posted? I didn't intend to give a full solution, if that's what you mean.

No no. Problem would be easily discovered if you tried to use that code snippet in real world: There is no CommandLineToArgvA API, only CommandLineToArgvW.
Post 25 Oct 2010, 00:42
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
Oh, that's a really big problem... Embarassed How could one use Unicode in Fasm, or is it possible?
Post 25 Oct 2010, 01:51
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
Someone maybe can write some (if possible) small example with comments please ?
Post 25 Oct 2010, 09:58
View user's profile Send private message Reply with quote
shoorick



Joined: 25 Feb 2005
Posts: 1605
Location: Ukraine
shoorick
look there:

http://board.flatassembler.net/topic.php?t=6663

it's not a small example, but command line parsing is in separate inc there
+++++++++++++++++++++++
look at simplified version in attach. try to run it with any parameters


Description:
Download
Filename: cmdl.0.0.2.1.zip
Filesize: 3.32 KB
Downloaded: 38 Time(s)



Last edited by shoorick on 25 Oct 2010, 10:26; edited 1 time in total
Post 25 Oct 2010, 10:05
View user's profile Send private message Visit poster's website Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
shoorick, thanks but thats hard for me too..... can't someone just type smallest example as posible please ? cause I dont understand when you're making macro "GeParameter" and things like that.. just only small piece of code from there so I can learn that.. Sad
Post 25 Oct 2010, 10:26
View user's profile Send private message Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 693
Location: Adelaide
sinsi
Small piece of code Smile
Code:
argc dd
argv dd
...
        invoke GetCommandLineW
        invoke CommandLineToArgvW,eax,argc
        mov [argv],eax
    

argc = count (should be at least 1)
argv = pointer to a list of pointers to each param (unicode), param0 = exe's name

Strips quote chars for each param.
Only works for NT-based OSs, not 9x.
Post 25 Oct 2010, 11:02
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
Sorry all. just was my mistake.. Smile shell32.inc doesn't import CommandLineToArgvW and added in include but had mistake, I've added this line and fixed now.. Smile
"CommandLineToArgvW,'CommandLineArgvW'" < just missed "To".. I'll try now learn things. Thanks 4 all Smile
Post 25 Oct 2010, 11:31
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
ehh.. another question.. here's my code but I dont understand nothing from here:
Code:
format PE console 4.0
include 'WIN32AX.INC'
entry main
section '.data' data readable writeable
buffer rb 20
argc dd ?
argv dd ?
section '.text' code readable executable
proc main
invoke GetCommandLine
invoke CommandLineToArgvW,eax,argc
mov [argv],eax
invoke printf,argv
invoke printf,argc
invoke ExitProcess,0
endp
section '.idata' import data readable
library kernel32,'kernel32.dll',msvcrt,'msvcrt.dll',shell32,'shell32.dll'
include 'API\KERNEL32.INC'
include 'API\SHELL32.INC'
import msvcrt,printf,'printf'    

printf shows nothing strange things.. can someone fix my code ?
Post 25 Oct 2010, 11:56
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
cinvoke for printf
Post 25 Oct 2010, 12:10
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17287
Location: In your JS exploiting you and your system
revolution
Overflowz: printf needs more than one parameter.

BTW: The first result from Google for "printf" is the place to start.
Post 25 Oct 2010, 12:17
View user's profile Send private message Visit poster's website Reply with quote
sinsi



Joined: 10 Aug 2007
Posts: 693
Location: Adelaide
sinsi
win32ax.inc will give you the ansi version of GetCommandLine, sending that to CommandLineToArgvW won't work.

Here is the original code I wrote, but it's masm syntax. Easy to convert.
Post 25 Oct 2010, 12:28
View user's profile Send private message Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
mindcooler, never mind I'm destroying stacks no point from that.
revolution, I've also tried printf,'%s',buffer.. %s %d %u %x etc etc but nothing from there was valid.
sinsi, same problem and I don't understand what's problem..
Code:
format PE console 4.0
include 'WIN32A.INC'
entry main
section '.data' data readable writeable
CR equ 0Dh
LF equ 0Ah
buffer rb 20
argc dd ?
argv dd ?
env dd ?
section '.text' code readable executable  
proc main
invoke GetCommandLine
invoke CommandLineToArgvW,eax,argc
mov [argv],eax
mov edi,eax
mov ebx,argc
invoke printf,'%s',argv,CR,LF
invoke printf,argc
invoke ExitProcess,0
endp
section '.idata' import data readable
library user32,'user32.dll',kernel32,'kernel32.dll',msvcrt,'msvcrt.dll',shell32,'shell32.dll'
include 'API\USER32.INC'
include 'API\KERNEL32.INC'
include 'API\SHELL32.INC'
import msvcrt,printf,'printf'    
Post 25 Oct 2010, 14:26
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17287
Location: In your JS exploiting you and your system
revolution
Code:
cinvoke printf,<'%d',13,10>,[argv]    
You'll need the win32ax.inc version for this shortcut with the string in the parameter.
Post 25 Oct 2010, 14:28
View user's profile Send private message Visit poster's website Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
revolution wrote:
Overflowz: printf needs more than one parameter.
Technically it doesn't Smile - but unless you like your apps crashing and/or getting exploited, you should be pretty careful about passing user-supplied input as single argument to printf Wink

(If you only want to display a single string, you should use puts(), anyway).

_________________
Image - carpe noctem
Post 25 Oct 2010, 16:06
View user's profile Send private message Visit poster's website Reply with quote
Overflowz



Joined: 03 Sep 2010
Posts: 1046
Overflowz
revolution, have you tested code ? cause I'm getting same problem. just weird simbols are displayed..
Post 25 Oct 2010, 18:19
View user's profile Send private message Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
Is printf utf-16?

CommandLineToArgvW

_________________
This is a block of text that can be added to posts you make.
Post 25 Oct 2010, 20:10
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 176
Location: section '.code' executable
semiono
sinsi wrote:
Small piece of code Smile

Hello! Please give me whole working src ?

Code:
include '%fasm%\win32wx.inc'
section '.code' code executable
start:
        invoke GetCommandLineW
        invoke CommandLineToArgW,eax,argc
               mov [argv],eax
        invoke wsprintf,z,'%s',[argv]
        invoke MessageBox,NULL,z,'',MB_OK
exit:
        invoke ExitProcess,NULL

section '.data' data readable writable

        argc dd ?
        argv dd ?
        z dd ?

section '.idata' readable

        library kernel32,'KERNEL32.DLL',user32,'USER32.DLL'
                import kernel32,ExitProcess,'ExitProcess',wsprintf,'wsprintf'
                import user32,GetCommandLineW,'GetCommandLine',\
                CommandLineToArgW,'CommandLineToArgW',MessageBox,'MessageBoxA'
    

I use WinXP. This code cry error! Rolling Eyes

_________________
Memory=8388608
Post 25 Oct 2010, 21:13
View user's profile Send private message ICQ Number Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
argc is not initialized
Post 25 Oct 2010, 21:16
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
semiono



Joined: 31 Aug 2007
Posts: 176
Location: section '.code' executable
semiono
fasm code? procedure? i not sure to understand...

Code:
proc aa
argc dd
argv dd
        invoke GetCommandLineW
        invoke CommandLineToArgW,eax,argc
               mov [argv],eax
        invoke wsprintf,z,'%s',[argv]
        invoke MessageBox,NULL,z,'',MB_OK
endp
        call [aa]
    


Confused ?
Post 25 Oct 2010, 21:22
View user's profile Send private message ICQ Number Reply with quote
mindcooler



Joined: 01 Dec 2009
Posts: 423
Location: Västerås, Sweden
mindcooler
Sorry, I was mistaken
Post 25 Oct 2010, 21:48
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.