Administrator
Group: Admins
Posts: 2308
Member No.: 1
Joined: 12-May 04
|
This is a command line parser that extracts the command line parameters. It is written in pure assembler.
CODE | ParseCommandLine Proc Uses EDI ESI lpCommandLine:LPSTR
MOV ESI,lpCommandLine CMP BYTE PTR [ESI],'"' JNE @F ;**************************************************** InQuotes: ADD ESI,1 CMP BYTE PTR [ESI],'"' JNE InQuotes JMP Strip ;**************************************************** @@: ADD ESI,1 CMP BYTE PTR [ESI],0 JE Ex CMP BYTE PTR [ESI]," " JNE @B ;Ok, the exe name is behind us ;**************************************************** ;Let us strip spaces Strip: ADD ESI,1 MOV AL,BYTE PTR [ESI] CMP AL,0 JE Ex;No arguments follow CMP AL," " JE Strip ;**************************************************** ;Let's see if the following ;argument starts with quotes XOR ECX,ECX CMP BYTE PTR [ESI],'"' JNE @F �;NO ADD ESI,1 MOV ECX,TRUE;YES ;**************************************************** ;Let's find the end of this argument @@: ;Store the start of this argument in EDI MOV EDI,ESI SUB ESI,1 Arg: ADD ESI,1 MOV AL,BYTE PTR [ESI]
CMP AL,0 JE ArgFound CMP ECX,0;Are we looking for a matching quote? JE @F;No CMP AL,'"';Yes JNE Arg;Matching quote NOT found, try next byte JMP ArgFound @@: CMP AL," " JNE Arg ;ESI points to the end of this argument ;**************************************************** ArgFound: PUSH EAX;Let's store BYTE PTR [ESI] MOV BYTE PTR [ESI],0 ;************************************* ;OK we have the argument from EDI to ESI ;Do what ever you want to the argument ;*************************************
IsLast: POP EAX;Lets remind ourselves of BYTE PTR [ESI] CMP AL,0;Was it a 0 ? JNE Strip;No, so command line end not reached, continue parsing ;**************************************************** Ex:
RET ParseCommandLine EndP |
|