Assembler: finding shared directories problem

Discussion in 'Programmer's Corner' started by maple23, May 7, 2008.

  1. maple23

    Thread Starter New Member

    Apr 23, 2008
    6
    0
    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?

    Code ( (Unknown Language)):
    1. .386
    2. .MODEL FLAT
    3.  
    4. EXTRN    FindFirstFileA        :PROC
    5. EXTRN    MessageBoxA        :PROC
    6. EXTRN    FindNextFileA        :PROC
    7. EXTRN    FindClose        :PROC
    8. EXTRN    SetCurrentDirectoryA    :PROC
    9. EXTRN    lstrcpyA        :PROC
    10.  
    11. MAX_PATH            equ    256
    12.  
    13. WIN32_FIND_DATA STRUC
    14.     dwFileAttributes    dd ?
    15.     ftCreationTime        dq ?
    16.     ftLastAccessTime    dq ?
    17.     ftLastWriteTime        dq ?
    18.     nFileSizeHigh        dd ?
    19.     nFileSizeLow        dd ?
    20.     Reserved0        dd ?
    21.     Reserved1        dd ?
    22.     cFileName        db MAX_PATH dup(?)
    23.     cAlternateFileName    db 14 dup(?)
    24. WIN32_FIND_DATA ENDS
    25.  
    26. .DATA
    27.     hFind        dd ?
    28.     szMask        db "*.*", 0
    29.     szBackDir    db "..", 0
    30.     szDirectory    db MAX_PATH dup(?)
    31.     win32FindData    WIN32_FIND_DATA <?>
    32.     szDrive        db "C:\", 0
    33.  
    34. .CODE
    35. MAIN:
    36.     push    offset szDrive
    37.     call    SetCurrentDirectoryA
    38.  
    39. findFirstFile:
    40.     push    offset win32FindData
    41.     push    offset szMask
    42.     call    FindFirstFileA                ; find first file in C:\ drive
    43.     mov    [hFind], eax
    44.  
    45. checkType:
    46.     cmp    eax, 0                    ; no files?
    47.     je    downDirectory
    48.     cmp    byte ptr [win32FindData.cFileName], "."
    49.     je    findNextFile
    50.     cmp    [win32FindData.dwFileAttributes], 10h
    51.     je    upDirectory
    52.     cmp    [win32FindData.dwFileAttributes], 30h
    53.     je    upDirectory
    54.  
    55. findNextFile:
    56.     push    offset win32FindData
    57.     push    [hFind]
    58.     call    FindNextFileA
    59.     jmp    checkType
    60.  
    61. upDirectory:
    62.     push    offset win32FindData.cFileName
    63.     push    offset szDirectory
    64.     call    lstrcpyA
    65.  
    66.     mov    eax, offset szDirectory
    67.  
    68.     cmp    byte ptr [eax], 90                ; already uppercase? (90 = Z)
    69.     jle    toUpperCase
    70.     xor    byte ptr [eax], 32                ; convert
    71.  
    72. toUpperCase:
    73.     inc    eax
    74.     cmp    byte ptr [eax], 0                ; at end of string?
    75.     je    endOfString
    76.     cmp    byte ptr [eax], 90                ; already uppercase?
    77.     jle    toUpperCase
    78.     xor    byte ptr [eax], 32                ; convert
    79.     jmp    toUpperCase
    80.  
    81. endOfString:
    82.     mov    eax, 0
    83.     mov    eax, offset szDirectory
    84.  
    85. searchShare:
    86.     inc    eax
    87.     cmp    byte ptr [eax], 0                ; end of string?
    88.     jne    noShare
    89.     cmp    byte ptr [eax], "S"                ; check for S
    90.     jne    searchShare
    91.     cmp    byte ptr [eax + 1], "H"                ; check for H
    92.     jne    searchShare
    93.     cmp    byte ptr [eax + 2], "A"                ;
    94.     jne    searchShare
    95.     cmp    byte ptr [eax + 3], "R"                ;
    96.     jne    searchShare
    97.     cmp    byte ptr [eax + 4], "E"                ;
    98.     jne    searchShare
    99.  
    100.     push    0
    101.     push    offset szDirectory
    102.     push    offset szDirectory
    103.     push    0
    104.     call    MessageBoxA                    ; display directory
    105.  
    106. noShare:
    107.     push    offset szDirectory
    108.     call    SetCurrentDirectoryA
    109.     cmp    eax, 0
    110.     je    findNextFile
    111.  
    112.     push    hFind
    113.     jmp    findFirstFile
    114.  
    115. downDirectory:
    116.     push    offset szBackDir
    117.     call    SetCurrentDirectoryA
    118.     push    [hFind]
    119.     call    FindClose
    120.     pop    [hFind]
    121.     cmp    [hFind], 0
    122.     jne    findNextFile
    123.  
    124. theEnd:
    125.     ret
    126.     END    MAIN
    I am using TASM 5.0 and TLINK32 to compile.

    Thanks in advance!
     
  2. Mark44

    Well-Known Member

    Nov 26, 2007
    626
    1
    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
     
  3. maple23

    Thread Starter New Member

    Apr 23, 2008
    6
    0
    I'm new to debuggers, but am trying to use Olly Debug. I'm reading the tutorial on using it right now...
     
Loading...