flat assembler
Message board for the users of flat assembler.
Index
> Windows > Search haddrive for specific files |
Author |
|
seth0x2b 03 Dec 2006, 12:54
Hey guys.
Nice to see an assembler forum that has alot of visitors. I just started learning ASM about 1 week ago, and all I can say is that "IT's GREAT!" . Ok..so here's my problem...I'm trying for the past week to find(or do) a program to search the entire harddrive(all physical drives/partitions) for a file with a specific extension. In the end I'd like to write the result to a log file but that part I think I could write with no problem All I came up with(actually found on this forum here http://board.flatassembler.net/topic.php?t=4434 and then simplified a bit) is a routine to search for a specific file extension inside a given folder. All I need now is a way to get the routine to run with a recursive search on all folders. Code: format PE GUI 4.0 entry BeginCode include '%finc%\win32a.inc' section '.code' executable readable writeable BeginCode: invoke FindFirstFileA,filemask,wfd mov [search_handle],eax @@: invoke CreateFileA,wfd.cFileName,(GENERIC_READ+GENERIC_WRITE),0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0 mov [file_handle],eax jmp FoundOne FindNext: invoke FindNextFileA,[search_handle],wfd cmp eax,0 je AllDone jmp @B AllDone: ret FoundOne: invoke MessageBox,0,wfd.cFileName,NULL,0 jmp FindNext section '.data' data readable writeable wfd FINDDATA filemask db 'C:\WINDOWS\*.bmp',0 search_handle dd ? file_handle dd ? section '.idata' import data readable writeable library kernel32,'KERNEL32.DLL',\ user,'USER32.DLL' import kernel32,\ FindFirstFileA,'FindFirstFileA',\ FindNextFileA,'FindNextFileA',\ CreateFileA,'CreateFileA' import user,\ MessageBox,'MessageBoxA' I would apreciate any help and/or code Thanks alot |
|||
03 Dec 2006, 12:54 |
|
seth0x2b 03 Dec 2006, 16:02
Not the best answer in the world but I can accept a little criticism.
I know I should not skip steps in the process of learning...but every newbie starts up with code snippets and then learns what everything does...At least this is my way of learning and it has served me good in the past. I am not a newbie programmer..I'm just a newbie at ASM. Thanks for your reply.. Still waiting for someone with a more constructive answer... Cheers |
|||
03 Dec 2006, 16:02 |
|
Remy Vincent 03 Dec 2006, 17:16
Code: {----- CONTROL Parameter 1 : File exists ? } GI_FilePath1 := ParamStr(1); IF GI_FilePath1 <> '' THEN BEGIN {----- Disk files access } FindFirst ( GI_FilePath1 , AnyFile , G_SearchRec ); G_FileExistsQ := ( DosError = 0 ); {----- File found ? } IF G_FileExistsQ = False THEN BEGIN WriteLn ( 'ERROR: ' , 'FilePath1 not found ( Parameter 1 ).' ); HALT ( 1 ); END; END ELSE BEGIN WriteLn ( 'ERROR: ' , 'FilePath1 expected ( Parameter 1 ).' ); HALT ( 1 ); END; This code is about searching files, and this code is really hard to use, because we often use a single FILEEXISTS() function instead of coding more lines, but using more usual calls... Yeah,... because FINDFIRST is very close from the interrupt call used by assembler programmers with DOS INTERRUPT 21 I would not be able to code this in FAMS, without "forgetting" all my currents projects!! _________________ Groups lower your IQ |
|||
03 Dec 2006, 17:16 |
|
rugxulo 03 Dec 2006, 18:25
ls.asm (NASM, Linux)
Quote:
|
|||
03 Dec 2006, 18:25 |
|
seth0x2b 03 Dec 2006, 19:15
Wow that's much code ...I'll have a look at it..
I've made some progress towards my goal..Ive written a program that probes for all drive letters and displays the ones that are fixed(harddrives).Easily changeable to any type of drive.. I'll post it since someone else would probably need something like this sometime .... Code: format PE GUI 4.0 entry start include '%finc%\win32a.inc' section '.data' data readable writeable drive db '?:\',0 ;drive name "template" letter dd ? ;to hold the current drive letter ;========= DRIVE TYPES ==========; UNKNOWN = 0 ; the drive type is unknown DOES_NOT_EXIST = 1 ; the drive does not exist DRIVE_REMOVABLE = 2 ; floppy DRIVE_FIXED = 3 ; harddrives DRIVE_REMOTE = 4 ; USB? DRIVE_CDROM = 5 ; cdrom units DRIVE_RAMDISK = 6 ; ramdisks section '.code' code readable executable start: mov [letter],'A' theLoop: ;loop through letters mov ecx, [letter] mov [drive], cl ;add current letter to drive name (example: 'A:\') call get ;get info for current drive letter inc [letter] ;next letter cmp [letter],'Z' ;compare the current letter to 'Z'... jg exit ;... and jump if current letter is greater than 'Z' jmp theLoop ;from the top exit: invoke ExitProcess,0 ret get: invoke GetDriveType,drive cmp eax, DRIVE_FIXED ;compare jz foundONE ;jump if the result from GetDriveType equals DRIVE_FIXED ret foundONE: invoke MessageBox,0,drive,0,0 ;display drive name ret section '.idata' import data readable writeable library kernel32,'KERNEL32.DLL',user32,'USER32.DLL' include '%finc%\apia\kernel32.inc' include '%finc%\apia\user32.inc' Cheers |
|||
03 Dec 2006, 19:15 |
|
Remy Vincent 03 Dec 2006, 21:35
seth0x2b wrote: ... ... I'm sorry but all my drives letters are not displayed, so I've added some lines, and now all my drives letters are displayed, even USB "flash drives", the four (4) lines I've added are commented with ; A D D E D... Code: format PE GUI 4.0 entry start include 'MyPathTo \Fasm167\FasmW\INCLUDE\win32a.inc' section '.data' data readable writeable drive db '?:\',0 ;drive name "template" letter dd ? ;to hold the current drive letter ;========= DRIVE TYPES ==========; UNKNOWN = 0 ; the drive type is unknown DOES_NOT_EXIST = 1 ; the drive does not exist DRIVE_REMOVABLE = 2 ; floppy DRIVE_FIXED = 3 ; harddrives DRIVE_REMOTE = 4 ; USB? DRIVE_CDROM = 5 ; cdrom units DRIVE_RAMDISK = 6 ; ramdisks section '.code' code readable executable start: mov [letter],'A' theLoop: ;loop through letters mov ecx, [letter] mov [drive], cl ;add current letter to drive name (example: 'A:\') call get ;get info for current drive letter inc [letter] ;next letter cmp [letter],'Z' ;compare the current letter to 'Z'... jg exit ;... and jump if current letter is greater than 'Z' jmp theLoop ;from the top exit: invoke ExitProcess,0 ret get: invoke GetDriveType,drive cmp eax, DRIVE_FIXED ;compare jz foundONE ;jump if the result from GetDriveType equals DRIVE_FIXED cmp eax, DRIVE_CDROM ; A D D E D jz foundONE ; A D D E D cmp eax, DRIVE_REMOVABLE ; A D D E D jz foundONE ; A D D E D ret foundONE: invoke MessageBox,0,drive,0,0 ;display drive name ret section '.idata' import data readable writeable library kernel32,'KERNEL32.DLL',user32,'USER32.DLL' include 'MyPathTo \Fasm167\FasmW\api\kernel32.inc' include 'MyPathTo \Fasm167\FasmW\INCLUDE\api\user32.inc' Do you fill it usefull?????? |
|||
03 Dec 2006, 21:35 |
|
seth0x2b 03 Dec 2006, 21:55
I've specified that it finds only fixed drives...I initially designed the program to show all drives found...but since I am looking only for fixed drives, I posted the coresponding code.
Thanks for showing interest though Still waiting/learning/searching for info on the recursion part... Cheers Last edited by seth0x2b on 03 Dec 2006, 21:59; edited 1 time in total |
|||
03 Dec 2006, 21:55 |
|
LocoDelAssembly 03 Dec 2006, 21:58
@Remmy,
Quote:
Quote:
@Both, look at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/getlogicaldrives.asp , possible this function can make the program faster (a speedup probably unneded of course...) |
|||
03 Dec 2006, 21:58 |
|
seth0x2b 03 Dec 2006, 22:05
LocoDelAssembly wrote:
Actually I've used "GetLogicalDrives" in the Delphi version of the program that I want to achieve right now... Maybe it speeds stuff up, but I don't think it's that noticeable.. [EDIT] Made a little mistake...I use "GetLogicalDriveStrings" http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/getlogicaldrivestrings.asp Cheers |
|||
03 Dec 2006, 22:05 |
|
LocoDelAssembly 03 Dec 2006, 22:30
Quote:
I saw that function but I think that the function that returns a bitmap is better, is easy to process and needs less resources. Code: drive db "A"-1,":\",0 . . . invoke GetLogicalDrives mov esi, eax .loop: inc byte[drive] shr esi, 1 jnc .loop jz .exit invoke GetDriveType, drive cmp eax, DRIVE_FIXED jnz .loop ; **** Here process the fixed drive jmp .loop |
|||
03 Dec 2006, 22:30 |
|
donkey7 04 Dec 2006, 12:00
many years ago, when i was 14 or 15 i started wiriting html editor (i've stopped development when i tried to do syntax highlighting - richedit doesn't have such feature and i was too lazy to learn and make own control).
here it is: http://asembler.republika.pl/bin/klop.zip one of the features it had is adding all files from specified folders (and all subfolders). the code looks as follows: Code: DodajPlikiDoProjektu proc LOCAL szukaj:HANDLE invoke PathAppend,addr bufor,addr gwiazdka invoke FindFirstFile,addr bufor,addr dane_pliku .IF eax==INVALID_HANDLE_VALUE ShowLastError ret .ELSE mov szukaj,eax .ENDIF szukej: mov eax,dane_pliku.dwFileAttributes and eax,FILE_ATTRIBUTE_DIRECTORY jz kuper mov eax,offset dane_pliku.cFileName cmp BYTE PTR [eax],'.' jnz fglak cmp BYTE PTR [eax+1],0 jz nicnierobJ cmp BYTE PTR [eax+1],'.' jnz fglak cmp BYTE PTR [eax+2],0 jz nicnierobJ fglak: invoke PathRemoveFileSpec,addr bufor invoke PathAppend,addr bufor,addr dane_pliku.cFileName call DodajPlikiDoProjektu invoke PathRemoveFileSpec,addr bufor invoke PathRemoveFileSpec,addr bufor invoke PathAppend,addr bufor,addr gwiazdka nicnierobJ: jmp nicnierob kuper: invoke lstrcpy,addr BuforNaText,addr bufor invoke PathRemoveFileSpec,addr BuforNaText invoke PathAppend,addr BuforNaText,addr dane_pliku.cFileName mov tvitem.imask,TVIF_PARAM m2m tvitem.hItem,aktualnyDokumentProjektu mSend hPanelProjektyDrzewo,TVM_GETITEM,0,addr tvitem mov eax,tvitem.lParam cmp (PROJEKT ptr [eax]).ileDokumentow,-1 jz nicnierob invoke DodajDokumentP,addr BuforNaText nicnierob: invoke FindNextFile,szukaj,addr dane_pliku or eax,eax jnz szukej invoke FindClose,szukaj ret DodajPlikiDoProjektu endp i know it's very ugly and written in masm, but i was relatively new to assembler (maybe few months of learning asm) and i didn't know fasm then. i hope it will give you some hints about how to do such procedure yourself. |
|||
04 Dec 2006, 12:00 |
|
LocoDelAssembly 04 Dec 2006, 13:57
Quote:
Oh my god... |
|||
04 Dec 2006, 13:57 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.