flat assembler
Message board for the users of flat assembler.

flat assembler > Windows > list files of a folder

Author
Thread Post new topic Reply to topic
username



Joined: 30 Jun 2017
Posts: 11
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: 132
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: 1266
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: 16057
Location: 112 Ocean Avenue, Amityville
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: 16057
Location: 112 Ocean Avenue, Amityville
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: 1255
Location: Underwater
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 _popen, addr cmd, "rt"
    test eax, eax
    jz .exit

    mov dword [pipe], eax

    cinvoke malloc, 8192
    test eax, eax
    jz .exit

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

    cinvoke memset, dword [hMem], 0, 8192

    .loop:
    cinvoke fgets, dword [hMem], MAX_PATH, dword [pipe]
    test eax, eax
    jz .close
    cinvoke strcat, dword [lpBuffer], dword [hMem]
    jmp .loop

    .close:
    cinvoke _pclose, dword [pipe]

    invoke MessageBox, HWND_DESKTOP, dword [lpBuffer], addr cmd, MB_OK

    cinvoke free, dword [hMem]

    .exit:
    invoke ExitProcess, 0

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: 487
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


Copyright © 1999-2018, Tomasz Grysztar.

Powered by rwasa.