flat assembler
Message board for the users of flat assembler.
Index
> Windows > Command line parser |
Author |
|
Vortex 16 Sep 2004, 16:51
Hi friends,
Based on an algo coded by Jibz, here is a command line parser. It can handle literal double quote inside an argument. The only parameter buffer should point a "buffer" of 512 bytes (=2*256) You are free to change this value. Code: proc ParseCmdLine,buffer push esi push edi invoke GetCommandLine @@: lea edx,[eax-1] xor eax,eax mov esi,[buffer] lea edi,[esi+256] mov ch,32 scan: inc edx mov cl,byte [edx] or cl,cl jz finish cmp cl,32 je scan inc eax mov [esi],edi add esi,4 restart: mov cl,byte [edx] or cl,cl jz finish cmp cl,ch je end_of_line cmp cl,34 jne @f xor ch,32 jmp next_char @@: mov byte [edi],cl inc edi next_char: inc edx jmp restart end_of_line: mov byte [edi],0 inc edi jmp scan finish: pop edi pop esi return endp
_________________ Code it... That's all... |
|||||||||||
16 Sep 2004, 16:51 |
|
Vortex 16 Sep 2004, 18:25
Hi Decard,
Thanks for your kind words. Did you check my example application "test.exe" in the attachment? This algo is designed to handle command line parameters typed in a console box, so it doesn't check for CR+LF or tab spaces. _________________ Code it... That's all... |
|||
16 Sep 2004, 18:25 |
|
decard 16 Sep 2004, 19:03
Hi,
I didn't downloaded your code then (done it right now). So, what you have written means that generally in Windows I don't need to check for CR+LF, or there could be a situation when a command line can end with this bytes? |
|||
16 Sep 2004, 19:03 |
|
Vortex 16 Sep 2004, 19:37
Hi Decard,
Just as you said, there is no need to check for CR+LF as you use the function GetCommandLine to get the parameters: Quote:
The value returned by GetCommandLine always points a NULL terminated string, so there is no reason to check CR+LF and tab spaces. _________________ Code it... That's all... |
|||
16 Sep 2004, 19:37 |
|
vbVeryBeginner 18 Sep 2004, 14:08
i just thinking to write my own piece and i saw ur parser here,
just downloaded it, haven't play with it :p sincerely, vbVeryBeginner |
|||
18 Sep 2004, 14:08 |
|
Vortex 19 Sep 2004, 08:26
Hi vbVeryBeginner,
It's a good idea to write your own parser as it's a good programming exercise. Have a look also at the other asm forums, you can find various command line parser algos. _________________ Code it... That's all... |
|||
19 Sep 2004, 08:26 |
|
vbVeryBeginner 20 Sep 2004, 17:08
Code: ; +------------+ ; | DATA GROUP | ; +------------+ ; cmdP = pointer for args address storage ; cmdArgExpect = expected argument count ; cmdArg = counter for marked args ; cmdLen = receive or allow number of char from arg ; cmdBuf = buffer area for argument to be copied from GetCommandLine *should be enough ; ; cmdf1 to cmdf3 = (D) debug wsprintf string ; cmdDbgBuf = (D) buffer area to store output debug message ; _cmdArg = coz those call in debug will modify our register, so we need to use variable ; _cmdPlus = add 4 per times for each looping ; _cmdCount = to specify which argument for user ; ; +---------------------+ ; | IMPORT GROUP | ; +---------------------+ ; KERNEL32 GetCommandLine ; (D) lstrlen ; proc cmd_parse push esi ;preserve push edi ;preserve mov ebx,cmdP ;ebx have the address for cmdP mov edx,[cmdArgExpect] ;edx have the value for cmdArgExpect invoke GetCommandLine parse_copy_start: mov esi,eax ;esi have the address from GetCommandLine mov edi,cmdBuf ;edi have the address for cmdBuf xor ecx,ecx ;clear ecx parse_copy_run: mov al,[esi] ;al have the byte value of esi inc esi ;increase esi address cmp al,0 ;cmp al with 0 je parse_copy_end ;assume last char found and end proc cmp al,0x20 ;cmp with spacebar jne @f ;if not, skip the marking process parse_mark: cmp [cmdArg],edx ;cmp cmdArgExpect with current marked cmdArg je parse_copy_end ;if equal that means our job finish inc edi mov [ebx],edi ;copy esi address to cmdP dec edi add ebx,4 ;increase ebx for next store mark address inc [cmdArg] ;increase marked cmdArg mov al,0 ;turn spacebar into zero for string usage later jmp @f @@: mov [edi],al ;cmdBuf fill with char from esi inc edi ;prepare edi for next store char address inc ecx ;our char counter jmp parse_copy_run ;run again until we find char = 0 parse_copy_end: mov [cmdLen],ecx ;store ecx counter value to cmdLen pop esi ;pop them so that they as as what pop edi ;when we got them return endp proc cmd_debug cinvoke wsprintf,cmdDbgBuf,cmdf1,[cmdLen] stdcall stdout,cmdDbgBuf cinvoke wsprintf,cmdDbgBuf,cmdf2,[cmdArg] stdcall stdout,cmdDbgBuf mov eax,[cmdArg] mov [_cmdArg],eax @@: cmp [_cmdArg],0 je @f mov eax,cmdP add eax,[_cmdPlus] cinvoke wsprintf,cmdDbgBuf,cmdf3,[_cmdCount],eax,[eax] stdcall stdout,cmdDbgBuf dec [_cmdArg] inc [_cmdCount] add [_cmdPlus],4 jmp @b @@: return endp hopefully it could be another reference for people, try download the file and play with it :p
Last edited by vbVeryBeginner on 21 Sep 2004, 03:56; edited 2 times in total |
|||||||||||
20 Sep 2004, 17:08 |
|
vbVeryBeginner 20 Sep 2004, 17:12
i don't know if there is any resemble code outthere,
but i swear (do i need that) this is 100% from my mind :p not good enough, i should be able to skip the dec inc sincerely, vbVeryBeginner d(zz`)b |
|||
20 Sep 2004, 17:12 |
|
Vortex 20 Sep 2004, 17:49
No problem vbVeryBeginner, keep going on.
_________________ Code it... That's all... |
|||
20 Sep 2004, 17:49 |
|
vbVeryBeginner 21 Sep 2004, 03:48
Code: proc cmd_argv_count,argvP,argvSend mov eax,[argvP] ;eax contained our arg address @@: xor ebx,ebx ;clear ebx coz we need to use bl only mov bl,[eax] ;store a byte from eax cmp bl,0 ;compare the byte with zero je @f ;job finish add [cmdArgv],ebx ;add to our cmdArgv inc eax ;for next byte jmp @b @@: call [argvSend] return endp this proc will enable the parser to support switch eg. urconsole.exe -h myfile.txt :p hope all enjoy :p and i just updated the version to 0.0.2, which u can download from the above link http://board.flatassembler.net/download.php?id=1072 |
|||
21 Sep 2004, 03:48 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.