Assembler: finding shared directories problem

Thread Starter

maple23

Joined Apr 23, 2008
6
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.

Program Breakdown:

  1. change directory to C:\ drive
  2. find first directory
  3. convert directory name to upper-case
  4. compare upper-case directory character-by-character for the string "SHARE"
  5. if the string is found, display the directory name (with a message box)
  6. if the string is not found, goto step 2
  7. if there are no more directories on the C:\ drive, exit

Each one of these functions works on their own (converting to upper-case, looking for "SHARE", enumerating all directories on the C:\ drive). When I put them all together, I get errors. The program executes fine until it finds a shared directory, then it fails.

Any idea what's wrong with my code?

Rich (BB 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

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
I am using TASM 5.0 and TLINK32 to compile.

Thanks in advance!
 

Mark44

Joined Nov 26, 2007
628
I don't see anything obviously wrong with your code, and you say that the individual sections of code are working, so it sounds like you're pretty close to what you want.

If you're not using the debugger, TDEBUG.exe (at least what it used to be when I had Turbo C++ years ago), you should be. In the debugger let your program run at normal speed to a breakpoint you set just before you get to a directory with "SHARE" in its name. From then on, single step through your code looking at registers and memory to make sure that what you think should be in those places is actually what's there. You should be able to see what's going wrong pretty easily.
Mark
 
Top