- #1
- 15
- 0
Finding "Shared" Directories in Assembly
For my next project, I am making a program which searches for all of the shared directories on a computer. My idea is if the directory contains the string "share", then it must be shared.
For this, I wrote a function to convert the directory name to upper-case letters. After this, the program checks character-by-character for "SHARE". I have no errors in this code when compiled by itself. Once I introduce my directory-search function, I errors. Please look at my code and let me know what I have done wrong.
I am using TASM 5.0 and TLINK32 to compile.
Thanks in advance!
For my next project, I am making a program which searches for all of the shared directories on a computer. My idea is if the directory contains the string "share", then it must be shared.
For this, I wrote a function to convert the directory name to upper-case letters. After this, the program checks character-by-character for "SHARE". I have no errors in this code when compiled by itself. Once I introduce my directory-search function, I errors. Please look at my code and let me know what I have done wrong.
Code:
.386
.MODEL FLAT
EXTRN FindFirstFileA :PROC
EXTRN MessageBoxA :PROC
EXTRN FindNextFileA :PROC
EXTRN FindClose :PROC
EXTRN SetCurrentDirectoryA :PROC
EXTRN lstrcpyA :PROC
MAX_PATH equ 256
FILE_ATTRIBUTE_DIRECTORY equ 00000010h
WIN32_FIND_DATA STRUC
dwFileAttributes dd ?
ftCreationTime dq ?
ftLastAccessTime dq ?
ftLastWriteTime dq ?
nFileSizeHigh dd ?
nFileSizeLow dd ?
Reserved0 dd ?
Reserved1 dd ?
cFileName db MAX_PATH dup(?)
cAlternateFileName db 14 dup(?)
WIN32_FIND_DATA ENDS
.DATA
hFind dd ?
szMask db "*.*", 0
szBackDir db "..", 0
szDirectory db MAX_PATH dup(?)
win32FindData WIN32_FIND_DATA <?>
szDrive db "C:\", 0
.CODE
MAIN:
push offset szDrive
call SetCurrentDirectoryA
findFirstFile:
push offset win32FindData
push offset szMask
call FindFirstFileA ; find first file in C:\ drive
mov [hFind], eax
checkType:
cmp eax, 0 ; no files?
je downDirectory
cmp byte ptr [win32FindData.cFileName], "."
je findNextFile
cmp [win32FindData.dwFileAttributes], 10h
je upDirectory
cmp [win32FindData.dwFileAttributes], 30h
je upDirectory
findNextFile:
push offset win32FindData
push [hFind]
call FindNextFileA
jmp checkType
upDirectory:
push offset win32FindData.cFileName
push offset szDirectory
call lstrcpyA
mov eax, offset szDirectory
cmp byte ptr [eax], 90 ; already uppercase? (90 = Z)
jle toUpperCase
xor byte ptr [eax], 32 ; convert
toUpperCase:
inc eax
cmp byte ptr [eax], 0 ; at end of string?
je endOfString
cmp byte ptr [eax], 90 ; already uppercase?
jle toUpperCase
xor byte ptr [eax], 32 ; convert
jmp toUpperCase
endOfString:
mov eax, 0
mov eax, offset szDirectory
searchShare:
inc eax
cmp byte ptr [eax], 0 ; end of string?
jne noShare
cmp byte ptr [eax], "S" ; check for S
jne searchShare
cmp byte ptr [eax + 1], "H" ; check for H
jne searchShare
cmp byte ptr [eax + 2], "A" ;
jne searchShare
cmp byte ptr [eax + 3], "R" ;
jne searchShare
cmp byte ptr [eax + 4], "E" ;
jne searchShare
push 0
push offset szDirectory
push offset szDirectory
push 0
call MessageBoxA ; display directory
noShare:
push offset szDirectory
call SetCurrentDirectoryA
cmp eax, 0
je findNextFile
push hFind
jmp findFirstFile
downDirectory:
push offset szBackDir
call SetCurrentDirectoryA
push [hFind]
call FindClose
pop [hFind]
cmp [hFind], 0
jne findNextFile
theEnd:
ret
END MAIN
Thanks in advance!