The MASM Forum

Microsoft 64 bit MASM => MASM64 SDK => Topic started by: hutch-- on July 11, 2016, 09:00:19 PM

Title: Please test this small console exe.
Post by: hutch-- on July 11, 2016, 09:00:19 PM
I need a favour, I have tested this exe on win7 64 and win10 64 to get the command tail and it works on both of my win7 and win10 versions. It differentiates between quoted file name and no quotes as follows.

c:\con3 command_tail
c:\"con3.exe" command tail

and if run from Explorer or Winfile it will show the full path in quotes.

If no command tail is present it will say so, if a command tail is present it will display it.

The source is below but it cannot be built yet because it uses a number of library modules and macros that have not been published yet.


; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm64\include\masm64rt.inc

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

entry_point proc

    .stack

    LOCAL tail  :QWORD

    mov tail, cmdtail()

  ; ---------------------
  ; test for command tail
  ; ---------------------
    .if BYTE PTR [rax] == 0
      stdout "No Command Line Arguments",13,10
    .else
      stdout "Command Tail = "
      stdout tail,13,10
    .endif

    void(GlobalFree,tail)       ; free memory from cmdtail

    waitkey                     ; wait for a key stroke to exit

    void(ExitProcess,0)         ; terminate process

    ret

entry_point endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end
Title: Re: Please test this small console exe.
Post by: Siekmanski on July 11, 2016, 09:20:16 PM
It works on my Win8.1
Title: Re: Please test this small console exe.
Post by: mabdelouahab on July 11, 2016, 09:47:56 PM
tested on windows 8.1 x64 entrp, it works well
Title: Re: Please test this small console exe.
Post by: Gunther on July 11, 2016, 09:57:09 PM
Works fine under Windows 7.

Gunther
Title: Re: Please test this small console exe.
Post by: hutch-- on July 12, 2016, 03:45:47 AM
Gratsie all.  :t
Title: Re: Please test this small console exe.
Post by: jj2007 on July 12, 2016, 10:19:35 AM
Win7-64:Command Tail = :\Masm64\Tmp.cpp

Is the missing drive letter by design?

On XP-32, it chokes saying "not a valid Win32 application" :(
Title: Re: Please test this small console exe.
Post by: hutch-- on July 12, 2016, 12:30:48 PM
JJ,

As a 64 bit PE executable, it will not run on a 32 bit OS version.

With the command tail, how did you call the test piece ? I have tested directly from the console, called the app with CreateProcess and run it from Explorer and Winfile. On my own win7 64 and win 10 64 the string returned from GetCommandLine() had the identical characteristics, the file name either quoted or unquoted then 2 spaces then whatever was added as command line arguments. I gather also that your OS version is an Italian win7 64.
Title: Re: Please test this small console exe.
Post by: hutch-- on July 12, 2016, 02:22:40 PM
JJ,

Give this a whirl, I changed the algorithm that gets the command tail to a safer method of left trimming the text. I am hoping this version does not truncate the first character on you language version of Win7 64.

This is the new algo to get the command tail.


; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm64\include\masm64rt.inc

    .code

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

cmd_tail proc

  ; ----------------------------------------------------------
  ; release the return value allocate memory with GlobalFree()
  ; ----------------------------------------------------------

    .stack
    LOCAL pcmd  :QWORD
    LOCAL clen  :QWORD
    LOCAL pMem  :QWORD

    mov pcmd, function(GetCommandLine)
    mov clen, len(pcmd)
    mov pMem, alloc(clen)

    void(mcopy64,pcmd,pMem,clen)

    mov r11, pcmd
    sub r11, 1

  lpst:
    add r11, 1
    cmp BYTE PTR [r11], 34              ; if lead character = "
    je stripquoted
    sub r11, 1

  notquoted:
    add r11, 1
    cmp BYTE PTR [r11], 0               ; exit on empty command tail
    je zeroexit
    cmp BYTE PTR [r11], 32              ; space
    jne notquoted
    jmp tailtrim

  stripquoted:
    add r11, 1
  @@:
    add r11, 1
    cmp BYTE PTR [r11], 0               ; exit on empty command tail
    je zeroexit
    cmp BYTE PTR [r11], 34
    jne @B
    add r11, 1

  tailtrim:
    add r11, 1
    cmp BYTE PTR [r11], 32              ; trim any spaces from front
    je tailtrim
    cmp BYTE PTR [r11], 9               ; trim any tabs from front
    je tailtrim

    mov r10, pMem                       ; load output buffer address
    xor rcx, rcx                        ; zero index
    sub rcx, 1
  copytail:
    add rcx, 1
    mov al, [r11+rcx]                   ; copy tail to output buffer
    mov [r10+rcx], al
    test al, al
    jnz copytail

    mov rax, pMem                       ; return output buffer in RAX
    ret

  zeroexit:
    mov rax, pMem
    mov BYTE PTR [rax], 0               ; zero 1st byte of pMem
    mov rax, pMem                       ; return zeroed buffer in RAX
    ret

cmd_tail endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    end
Title: Re: Please test this small console exe.
Post by: jj2007 on July 12, 2016, 06:22:29 PM
This one works correctly  :t
Title: Re: Please test this small console exe.
Post by: hutch-- on July 12, 2016, 06:35:29 PM
Gratsie  :biggrin: