Hi!, I'm trying to learn win32 assembler with FASM and I have a small problem.

This is my small app:

format PE console 4.0
entry start

include '%flatpath%\Include\win32w.inc'

section '.data' data readable writeable
  written    dd ?
  search    db 'c:\documents and settings\*.*',0
  findData  WIN32_FIND_DATA
  result    db 255 dup(0)

section '.code' code readable executable
  start:
        invoke    FindFirstFile,search,findData
        mov      cl,'a'
        mov      ,cl
  ; -=-=-= OUTPUT --=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        invoke    lstrlen,result
        mov      ebx,eax
        invoke    GetStdHandle,STD_OUTPUT_HANDLE
        mov      ecx,eax
        invoke    WriteFile,ecx,result,ebx,written,0
  ; -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  exit:
        invoke ExitProcess,0

section '.idata' import data readable writeable
  library kernel,'KERNEL32.DLL'
  import  kernel,\
          FindFirstFile,'FindFirstFile',\
          GetStdHandle,'GetStdHandle',\
          WriteFile,'WriteFile',\
          ExitProcess,'ExitProcess',\
          lstrlen,'lstrlen'



The part:

        mov      cl,'a'
        mov      ,cl

it's only for tests.

When I execute this application in the console the result is an empty line - nothing, but when I remove

  invoke    FindFirstFile,search,findData

the result is "a"

What I need to change to make this work properly?
What I'm doing wrong?

Maybe it's another way to write the result to standard output?

Thanks...
Posted on 2007-09-23 09:17:47 by Kr!z
Problem solved  :lol:
Should be "FindFirstFileA" instead of "FindFirstFile"

This is simple dir/ls like console application, maybe someone find it usefull. Any suggestion are welcome :)


format PE console 4.0
entry start

include '%flatpath%\Include\win32ax.inc'

section '.data' data readable writeable
  search    db "c:\Documents and Settings\*.*",0
  CRLF      db 0Dh,0Ah,00h
  fD        WIN32_FIND_DATA
  sHandle    dd ?

section '.code' code readable executable
  start:
        invoke  FindFirstFile,search,fD
        cmp      eax,INVALID_HANDLE_VALUE
        je      exit
        mov      ,eax
      @@:
        push    fD.cFileName
        call    WriteText
        push    CRLF
        call    WriteText
        invoke  FindNextFile,,fD
        cmp      eax,0
        jne      @b
        invoke  FindClose,
  exit:
        invoke ExitProcess,0

;-=-=-=- Write to sdtout -=-=-=-=-=-=-=-=-=-=-=-=-=-=
proc WriteText text
    local wr dd ?
        invoke    lstrlen,
        mov      ebx,eax
        invoke  GetStdHandle,STD_OUTPUT_HANDLE
        mov      ecx,eax
        invoke    WriteFile,ecx,,ebx,addr wr,0
        ret
endp ; end of WriteText

section '.idata' import data readable writeable
  library kernel,'KERNEL32.DLL'

  import  kernel,\
          GetStdHandle,'GetStdHandle',\
          WriteFile,'WriteFile',\
          ExitProcess,'ExitProcess',\
          lstrlen,'lstrlen',\
          FindFirstFile,'FindFirstFileA',\
          FindNextFile,'FindNextFileA',\
          FindClose,'FindClose' 
Posted on 2007-09-23 11:53:36 by Kr!z