flat assembler
Message board for the users of flat assembler.
Index
> Windows > Get command line args on Windows |
Author |
|
revolution 15 Feb 2022, 14:36
Code: invoke GetCommandLineA
invoke GetCommandLineW
;or
invoke GetCommandLine |
|||
15 Feb 2022, 14:36 |
|
macomics 15 Feb 2022, 19:38
+ CommandLineToArgvW
|
|||
15 Feb 2022, 19:38 |
|
FlierMate 16 Feb 2022, 05:04
There is an example "Command line parameters" (Handling the command line parameters in Windows)
https://flatassembler.net/examples.php |
|||
16 Feb 2022, 05:04 |
|
Walter 16 Feb 2022, 17:22
Not anything better than those already mentioned but just an example of an additional way to do it.
Code: ;************ ;* Args.asm * ;************ format PE CONSOLE entry start include 'win32ax.inc' section '.text' code readable executable start: cinvoke __getmainargs,argc,argv,env,0,NULL cinvoke printf,<"Argc count is %d",13,10>,[argc] mov eax,[argv] cinvoke printf,<"Program name is %s",13,10>,dword [eax] mov ebx,1 .while ebx < [argc] add [argv],4 mov eax,[argv] cinvoke printf,<"argv[%d] = %s",13,10>,ebx,dword [eax] inc ebx .endw invoke ExitProcess,0 section '.data' data readable writeable argc dd ? argv dd ? env dd ? section '.idata' import data readable writeable library kernel32,'kernel32.dll',\ msvcrt,'msvcrt.dll' import kernel32,\ ExitProcess,'ExitProcess' import msvcrt,\ __getmainargs,'__getmainargs',\ printf,'printf' |
|||
16 Feb 2022, 17:22 |
|
Tomasz Grysztar 16 Feb 2022, 19:35
OK, then we are missing an example using CommandLineToArgvW, so let me try:
Code: format PE GUI 4.0 include 'win32w.inc' ID_DIALOG = 100 ID_LIST = 101 section '.text' code readable executable entry $ invoke GetModuleHandle,0 invoke DialogBoxParam,eax,ID_DIALOG,HWND_DESKTOP,DialogProc,0 invoke ExitProcess,0 proc DialogProc uses ebx esi, hwnd,msg,wparam,lparam locals num dd ? endl push ebx esi edi cmp [msg],WM_INITDIALOG je .wminitdialog cmp [msg],WM_COMMAND je .wmcommand cmp [msg],WM_CLOSE je .close xor eax,eax jmp .finish .wminitdialog: invoke GetDlgItem,[hwnd],ID_LIST mov ebx,eax invoke GetCommandLine lea edx,[num] invoke CommandLineToArgv,eax,edx test eax,eax jz .close mov esi,eax .add: lodsd invoke SendMessage,ebx,LB_ADDSTRING,0,eax dec [num] jnz .add jmp .processed .wmcommand: cmp [wparam],BN_CLICKED shl 16 + IDCANCEL jne .processed .close: invoke EndDialog,[hwnd],0 .processed: mov eax,1 .finish: pop edi esi ebx ret endp section '.idata' import data readable writeable library kernel,'KERNEL32.DLL',\ user,'USER32.DLL',\ shell,'SHELL32.DLL' import kernel,\ GetModuleHandle,'GetModuleHandleW',\ GetCommandLine,'GetCommandLineW',\ ExitProcess,'ExitProcess' import user,\ DialogBoxParam,'DialogBoxParamW',\ GetDlgItem,'GetDlgItem',\ SendMessage,'SendMessageW',\ EndDialog,'EndDialog' import shell,\ CommandLineToArgv,'CommandLineToArgvW' section '.rsrc' resource data readable directory RT_DIALOG,dialogs resource dialogs,\ ID_DIALOG,LANG_ENGLISH+SUBLANG_DEFAULT,main dialog main,'Argv',80,80,220,200,WS_CAPTION+WS_POPUP+WS_SYSMENU+DS_MODALFRAME dialogitem 'LISTBOX','',ID_LIST,10,10,200,180,WS_VISIBLE+WS_VSCROLL+LBS_DISABLENOSCROLL enddialog |
|||
16 Feb 2022, 19:35 |
|
Walter 16 Feb 2022, 22:47
Very eloquent example!
That should make for some good choices for the OP. |
|||
16 Feb 2022, 22:47 |
|
macomics 17 Feb 2022, 10:12
I got alternative algorithms from my library to parse the command line. The main function transfers the text to the stack and clearing the memory can be done by simply loading the saved stack top when exiting the calling function. The archive contains versions for 32 and 64 bit sources, as well as versions of functions for ANSI and Unicode. I also cleaned the code from my macros, so it no longer requires any additional include files.
Code: section 'text' code readable executable entry $ push rbp mov rbp, rsp sub rsp, 32 call [GetCommandLineA] mov rsp, rbp call CmdLine2ArgvA ; return rax = rsp = argv mov r8, rax ; word [rax + 0] = offset argv[0] = argc * 2 ; word [rax + 2] = offset argv[1] ; . . . ; word [rax + 2 * N] = offset argv[argc - 1] ; byte [rax + 2 * N + 2] = copy GetCommandLineA call CmdLineCount ; return rax = argc; call main mov ecx, eax lea rsp, [rbp - 32] call [ExitProcess] main: ; rax = argc, r8 = argv push rbp mov rbp, rsp mov rax, r8 mov edx, 1 call CmdLineIndex ; return rax = argv[1] or CPU_FL_CF mov rax, r8 xor edx, edx call CmdLineRmov ; remove argv[0] . . . xor eax, eax mov rsp, rbp pop rbp retn include 'WinCmdLn\x64.ASM'
|
|||||||||||
17 Feb 2022, 10:12 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.