Programming 版 (精华区)

发信人: pzc (不过如此), 信区: Programming
标  题: EnumDir(only exe)
发信站: 哈工大紫丁香 (2002年03月08日10:50:55 星期五), 站内信件

The program browses 'd:\test' dir for all exe file
and uses msgbox to show them.
win2k only
compiled by masm32v5

.386
.model flat, stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
wfd WIN32_FIND_DATA <>
CurDir db 'd:\test\',0
sds db '*.*',0
dwFindFirstFil  dd 77E68DD4h
dwFindNextFil   dd 77E64BCAh
dwFindClose    dd 77E68D24h
.code
start:
call EnumDir
ret
EnumDir:
push   ebp
mov    ebp,esp       ;ebp-4=hSearch ebp-264=DirofFile[]
sub    esp,272       ;ebp-268=bFind ebp-272=CurDirLen
mov    esi,[ebp+8]
xor    ecx,ecx
.while byte ptr [esi+ecx]!=0
       inc  ecx
.endw
mov    [ebp-272],ecx
lea    edi,[ebp-264]
rep    movsb
mov    esi,offset sds ;offset of "*.*"
movsw
movsw
push   offset wfd
lea    eax,[ebp-264]
push   eax
call   dwFindFirstFile
mov    [ebp-4],eax    ;hSearch=eax
l_next:
push   offset wfd
push   [ebp-4]
call   dwFindNextFile
mov    [ebp-268],eax
.if    eax==FALSE
       jmp short l_close
.endif
.if    byte ptr [wfd+44]=='.'
      jmp short l_next
.endif
lea    edi,[ebp-264]
add    edi,[ebp-272]
       lea    esi,[wfd+44]
       .while byte ptr [esi+ecx]!=0
              inc  ecx
       .endw
       rep    movsb           ;strcat(DirofFile,wfd.cFileName)
       .if  dword ptr [wfd]==FILE_ATTRIBUTE_DIRECTORY
             mov    byte ptr [edi],'\'
             mov    byte ptr [edi+1],0           ;let DirofFile have a end
             lea    eax,[ebp-264]
             push   eax
             call   EnumDir
       .else
             mov    byte ptr [edi],0
             call  File_Test
       .endif
       jmp short l_next
l_close:
push   [ebp-4]
call   dwFindClose
add    esp,272
pop    ebp
ret    4
File_Test:
             sub    edi,4
             cmp    dword ptr[edi],6578652Eh  ; 6578652E= .exe
             jnz    short ft_end
             lea    eax,[ebp-264]
             Invoke MessageBox,NULL,eax,eax,0
ft_end:
ret
end start 

--
※ 来源:·哈工大紫丁香 bbs.hit.edu.cn·[FROM: 202.118.236.144]
[百宝箱] [返回首页] [上级目录] [根目录] [返回顶部] [刷新] [返回]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.429毫秒