flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Windows > list files of a folder

Author
Thread Post new topic Reply to topic
username



Joined: 30 Jun 2017
Posts: 11
list files of a folder
I need to get all files names of a folder but without the use of FindFirst and FindNext file APIs
Is there any way?
Maybe other API or a workaround?
(windows 7 or newer)
Post 18 Sep 2017, 15:17
View user's profile Send private message Reply with quote
Walter



Joined: 26 Jan 2013
Posts: 120

Code:

;*****************
;* Directory.asm *
;*****************

format pe console
entry start

include 'win32ax.inc'

section '.code' code readable executable

start:

    cinvoke system,"Dir /B C:\Fasm"
    cinvoke system,"Pause"
    invoke  ExitProcess,0
         
section '.idata' import data readable

    library kernel32,'KERNEL32.DLL',\
            msvcrt,'MSVCRT.DLL'
         
    import kernel32,\
           ExitProcess,'ExitProcess'

    import msvcrt,\
           system,'system'


Post 18 Sep 2017, 19:36
View user's profile Send private message Reply with quote
username



Joined: 30 Jun 2017
Posts: 11
Thank you!
And how do I read the output in a buffer in my program (which is pe gui)?
Also, is it possible not to show the console window?
Appreciate the help!
Post 19 Sep 2017, 06:15
View user's profile Send private message Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 827
Use CreateProcess to "cmd.exe" and send its stdout to a pipe that you read from your program. Pass the "dir" command above to cmd.exe's command line in CreateProcess.

Basically use CreatePipe, make the output to be cmd.exe's stdout and the input you read with ReadFile. There's guides out there on how to use pipes etc.

Yeah, it's pretty convoluted, because of your weird requirements of not using Find*File APIs.
Post 19 Sep 2017, 16:58
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15171
Location: GW170817
cmd.exe will just use those same APIs anyway. Not sure why the OP can't use them, but calling an external program to call them for you is going to be more work.
Post 19 Sep 2017, 19:49
View user's profile Send private message Visit poster's website Reply with quote
username



Joined: 30 Jun 2017
Posts: 11
All right
So are there any other API or anything else that don't use the 2 APIs? Something low level maybe?
Is it possible to get access to HDD sectors and read from there the files and their contents? I don't know how the files are managed and stored by windows os "under the hood"
Post 22 Sep 2017, 08:25
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15171
Location: GW170817

username wrote:
Something low level maybe?
Is it possible to get access to HDD sectors and read from there the files and their contents?

Yes. You can use the \\.\PhysicalDriveX (where X is the drive number) filename to read the raw sectors. But you will have to parse the partition table and the file system data yourself. That would be a significant undertaking though.

username wrote:
I don't know how the files are managed and stored by windows os "under the hood"

FAT and NTFS are the two main file systems used. But others like UDF will come up also depending upon the media you are reading.
Post 22 Sep 2017, 08:57
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1203
Location: Athens, Greece
Hi, here's a workaround that uses pipes.


Code:

    format PE gui 4.0
    entry start

    include "..\include\win32ax.inc"

section ".data" data readable writeable

    pipe dd 0
    hMem dd 0
    lpBuffer dd 0
    cmd db "Dir /B C:\Fasm"

section ".code" code readable executable
start:

    cinvoke _popenaddr cmd"rt"
    test eaxeax
    jz .exit

    mov dword [pipe], eax

    cinvoke malloc8192
    test eaxeax
    jz .exit

    mov dword [hMem], eax
    add eaxMAX_PATH
    mov dword [lpBuffer], eax

    cinvoke memsetdword [hMem], 08192

    .loop:
    cinvoke fgetsdword [hMem], MAX_PATHdword [pipe]
    test eaxeax
    jz .close
    cinvoke strcatdword [lpBuffer], dword [hMem]
    jmp .loop

    .close:
    cinvoke _pclosedword [pipe]

    invoke MessageBoxHWND_DESKTOPdword [lpBuffer], addr cmdMB_OK

    cinvoke freedword [hMem]

    .exit:
    invoke ExitProcess0

section ".idata" import data readable writeable

    library\
    kernel32,"kernel32.dll",\
    user32,"user32.dll",\
    msvcrt,"msvcrt.dll"

import kernel32,\
    ExitProcess,'ExitProcess'

import user32,\
    MessageBox,"MessageBoxA"

import msvcrt,\
    fgets,"fgets",\
    free,"free",\
    malloc,"malloc",\
    memset,"memset",\
    _popen,"_popen",\
    _pclose,"_pclose",\
    strcat,"strcat"




Image
Post 22 Sep 2017, 11:42
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 174
https://stackoverflow.com/questions/44658284/what-is-the-fastest-way-to-get-only-directory-list/44659843#44659843

NtQueryDirectoryFile

This is probably related. Looks like quite a mindfuck though.
Post 29 Sep 2017, 13:29
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.