;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; CleanAllLogs 清除系统中的app、sys、sec和IIS日志
;
; By taiwansee 2007-11-16
;
;已知bug 重启IIS后80服务正常,HTTPS(443端口的)不能访问了。。郁闷。。
;测试环境是windows xp pro sp2 IIS5.1,如有知道的请告知下,先行谢过!
; 使用 nmake 或下列命令进行编译和链接:
; ml /c /coff CleanAllLogs.asm
; Link /subsystem:windows CleanAllLogs.obj
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.386
.model flat, stdcall
option casemap :none
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; Include 文件定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
include advapi32.inc
includelib advapi32.lib
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 数据段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.const
DEBUG equ 0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 数据段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.data
if DEBUG
szCaption db 'Debug info......',0
szOpenEventLogFailed db 'szOpenEventLogFailed',0
szClearEventLogFailed db 'szClearEventLogFailed',0
szCloseEventLogFailed db 'szCloseEventLogFailed',0
szOpenSCManagerFailed db 'szOpenSCManagerFailed',0
szOpenServiceFailed db 'szOpenServiceFailed',0
szQueryServiceStatusFailed db 'szQueryServiceStatusFailed',0
szControlServiceToStopFailed db 'szControlServiceToStopFailed',0
szStartServiceFailed db 'szStartServiceFailed',0
szDeleteFileFailed db 'szDeleteFileFailed',0
szDoNextFile db 'szDoNextFile',0
szBeginDelete db 'szBeginDelete',0
endif
;//////////////清除系统日志///////////////
szApplication db 'Application',0
szSecurity db 'Security',0
szSystem db 'System',0
;//////////////清除系统日志///////////////
szIIS db 'w3svc',0
szFiles db '\*.*',0
szLogfiles db 'ex*.log',0
szXieGang db 5ch,0
szFilesPath db 'logfiles',0
szOnePoint db '.',0
szTwoPoint db '..',0
dwISSuffix dd 0
.data?
dwlpFileName dd ?
dwPrefixLength dd ?
dwSuffixLength dd ?
szPrefix db 128 dup(?) ;前缀支持128个字节
szSuffix db 16 dup(?) ;后缀支持16个字节
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
; 代码段
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
.code
;//////////////清除系统日志///////////////
_CleanSYSLogs proc
local @hTargetLogs:dword,\
@ECX:dword,\
@lpTarget[3]:dword
pushad
lea esi,@lpTarget
mov [esi],offset szApplication
mov [esi+4],offset szSecurity
mov [esi+8],offset szSystem
mov ecx,3
.while ecx
mov @ECX,ecx
mov eax,dword ptr @lpTarget[ecx*4-4]
invoke OpenEventLog,NULL,eax
.if eax!=NULL
mov @hTargetLogs,eax
.else
if DEBUG
invoke MessageBox,NULL,offset szOpenEventLogFailed,\
offset szCaption,\
MB_OK
endif
.endif
;清除由@hTargetLogs指定的日志
invoke ClearEventLog,@hTargetLogs,NULL
.if eax==NULL
if DEBUG
invoke MessageBox,NULL,offset szClearEventLogFailed,\
offset szCaption,\
MB_OK
endif
.endif
;关闭日志句柄
invoke CloseEventLog,@hTargetLogs
.if eax==NULL
if DEBUG
invoke MessageBox,NULL,offset szCloseEventLogFailed,\
offset szCaption,\
MB_OK
endif
.endif
mov ecx,@ECX
dec ecx
.endw
popad
ret
_CleanSYSLogs endp
;//////////////////////////////////////////////////////////////////////////////////////////////////
; 处理用户定义的搜索字符串 /
; 支持的格式:xxx*.yyy 、*.yyy (xxx为前缀,*为通配符,yyy为后缀) /
;///////////////////////////////////////把前缀保存在szPrefix中,长度保存在dwPrefixLength///////////
;///////////////////////////////////////把后缀保存在szSuffix中,长度保存在dwSuffixLength///////////
_PrefixAndSubfix proc
pushad
invoke RtlZeroMemory,offset szPrefix,sizeof szPrefix
invoke RtlZeroMemory,offset szSuffix,sizeof szSuffix
mov esi,offset szLogfiles
lea edi,szPrefix
xor ecx,ecx
@@:
lodsb
cmp al,'*'
jz @F ;找到通配符, 前缀收集结束,跳到收集后缀的地方
inc ecx
stosb ;否则,继续收集前缀信息
jmp @B
@@:
;收集后缀信息....
push ecx
push ecx
pop dwPrefixLength ;保存前缀长度
mov esi,offset szLogfiles
lea edi,szSuffix
add esi,ecx ;修改偏移到后缀开始的地方
add esi,2
mov eax,sizeof szLogfiles ;计算szLogfiles长度
sub eax,ecx
sub eax,2 ;计算后缀长度
mov dword ptr dwSuffixLength,eax ;保存后缀长度
mov ecx,eax ;后缀长度保存到ecx
rep movsb
pop ecx
.if ecx==0;如果相同,说明只看文件后缀了。。后面跳到文件后缀比较的地方
;否则,开始处理文件的前后缀信息。。。。。
mov dwISSuffix,1
.endif
if DEBUG
invoke MessageBox,NULL,offset szPrefix,offset szCaption,MB_OK
invoke MessageBox,NULL,offset szSuffix,offset szCaption,MB_OK
endif
popad
ret
_PrefixAndSubfix endp
_DeleteLogFiles proc _szSystemDirectory,_szFilesPath
local @stFindFileData:WIN32_FIND_DATA,\
@hFindFile:dword,\
@szFileNameBuffer[512]:byte,\
@szFileExtention[100]:byte,\
@dwFileNameLength:dword,\
@szFilePrefix[128]:byte,\
@szFileSuffix[8]:byte,\
@szSystemDirectoryBackup[256]:byte,\
@bk[256]:byte
pushad
;_szSystemDirectory ----> %systemroot%\logfiles\xxxx
invoke lstrcat,_szSystemDirectory,offset szXieGang
invoke lstrcat,_szSystemDirectory,_szFilesPath
;///备份一下_szSystemDirectory指向的路径字符串
;@szSystemDirectoryBackup ----> %systemroot%\logfiles\xxxx
invoke RtlZeroMemory,addr @szSystemDirectoryBackup,sizeof @szSystemDirectoryBackup
invoke lstrlen,dword ptr _szSystemDirectory
inc eax
mov ecx,eax
mov esi,dword ptr _szSystemDirectory
lea edi,@szSystemDirectoryBackup
rep movsb
;////////// szFiles ----> \*.*
;////////// _szSystemDirectory ----> %systemroot%\logfiles\xxxx\*.*
invoke lstrcat,_szSystemDirectory,offset szFiles
if DEBUG
invoke MessageBox,NULL,_szSystemDirectory,offset szCaption,MB_OK
invoke MessageBox,NULL,addr @szSystemDirectoryBackup,offset szCaption,MB_OK
endif
;////////// _szSystemDirectory ----> %systemroot%\logfiles\xxxx\*.*
invoke FindFirstFile,_szSystemDirectory,addr @stFindFileData
.if eax!=INVALID_HANDLE_VALUE
mov @hFindFile,eax
.repeat
lea eax,@stFindFileData.cFileName
mov dwlpFileName,eax
;//如果是一个文件夹,则进入递归调用。。。
.if @stFindFileData.dwFileAttributes==FILE_ATTRIBUTE_DIRECTORY
invoke lstrcmp,dwlpFileName,offset szOnePoint
.if eax==0
jmp DoNextFile
.endif
invoke lstrcmp,dwlpFileName,offset szTwoPoint
.if eax==0
jmp DoNextFile
.endif
;////因为下面是传地址调用,所以进去之前保存下@szSystemDirectoryBackup的值
invoke RtlZeroMemory,addr @bk,sizeof @bk ;清空@bk
invoke lstrcpyn,addr @bk,addr @szSystemDirectoryBackup,\
sizeof @szSystemDirectoryBackup
;////保存好了后就可以进去了哈。。。///
invoke _DeleteLogFiles,addr @szSystemDirectoryBackup,dwlpFileName
;////出来后恢复下@szSystemDirectoryBackup的值
;清空@szSystemDirectoryBackup
invoke RtlZeroMemory,addr @szSystemDirectoryBackup,\
sizeof @szSystemDirectoryBackup
invoke lstrcpyn,addr @szSystemDirectoryBackup,addr @bk,\
sizeof @bk
.else
;//否则查看是否是匹配文件,如果是就删除,否则跳过。。。
;///////////////////处理找到的文件的前缀、后缀信息///////////////////////////////////
.if dwISSuffix==1
jmp @F
.endif
mov eax,sizeof @stFindFileData.cFileName
mov dword ptr @dwFileNameLength,eax
cmp dwPrefixLength,eax
jg DoNextFile ;前缀比文件名都长,肯定不是目标文件了,跳到循环末尾
invoke RtlZeroMemory,addr @szFilePrefix,sizeof @szFilePrefix
;下面开始比较前缀与文件前缀了
lea esi,@stFindFileData.cFileName
lea edi,@szFilePrefix
mov ecx,dwPrefixLength
rep movsb
invoke lstrcmp,offset szPrefix,addr @szFilePrefix
.if eax!=0
jmp DoNextFile
.endif
@@:
mov eax,sizeof @stFindFileData.cFileName
mov dword ptr @dwFileNameLength,eax
;//////否则,说明前缀匹配,开始看后缀,先采集文件后缀信息///
invoke RtlZeroMemory,addr @szFileSuffix,sizeof @szFileSuffix
lea esi,@stFindFileData.cFileName
lea edi,@szFileSuffix
xor ecx,ecx
@@: lodsb
inc ecx
cmp al,'.'
jnz @B
sub @dwFileNameLength,ecx
mov ecx,@dwFileNameLength
rep movsb
;//开始比较后缀与文件后缀,如果相同,则可以执行删除动作
;//否则,跳到循环末尾
invoke lstrcmp,offset szSuffix,addr @szFileSuffix
.if eax!=0
jmp DoNextFile
.endif
;///////////文件通过上面的过滤后,符合条件的就可以被执行删除动作了/////////////////////
;@szSystemDirectoryBackup ----> %systemroot%\logfiles\xxx
;@szFileNameBuffer ----> %systemroot%\logfiles\xxx
invoke lstrcpy,addr @szFileName