News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Please test this small console exe.

Started by hutch--, July 11, 2016, 09:00:19 PM

Previous topic - Next topic

hutch--

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

Siekmanski

Creative coders use backward thinking techniques as a strategy.

mabdelouahab

tested on windows 8.1 x64 entrp, it works well

Gunther

You have to know the facts before you can distort them.

hutch--


jj2007

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" :(

hutch--

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.

hutch--

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

jj2007


hutch--