public void Bug59830() { // This file is intentionally omitted from the test-data directory // unless we can extract the vbaProject.bin from this Word 97-2003 file // so that it's less likely to be opened and executed on a Windows computer. // The file is attached to bug 59830. // The Macro Virus only affects Windows computers, as it Makes a // subprocess call to powershell.exe with an encoded payload // The document Contains macros that execute on workbook open if macros // are enabled FileInfo doc = POIDataSamples.GetDocumentInstance().GetFileInfo("macro_virus.doc.do_not_open"); VBAMacroReader Reader = new VBAMacroReader(doc); Dictionary <String, String> macros = Reader.ReadMacros(); Assert.IsNotNull(macros); Reader.Close(); }
protected void AssertMacroContents(POIDataSamples samples, VBAMacroReader r) { Assert.IsNotNull(r); Dictionary <String, String> contents = r.ReadMacros(); Assert.IsNotNull(contents); Assert.IsFalse(contents.Count == 0, "Found 0 macros"); /* * Assert.AreEqual(5, contents.Size()); * * // Check the ones without scripts * String[] noScripts = new String[] { "ThisWorkbook", * "Sheet1", "Sheet2", "Sheet3" }; * foreach (String entry in noScripts) { * Assert.IsTrue(entry, contents.ContainsKey(entry)); * * String content = contents.Get(entry); * assertContains(content, "Attribute VB_Exposed = True"); * assertContains(content, "Attribute VB_Customizable = True"); * assertContains(content, "Attribute VB_TemplateDerived = False"); * assertContains(content, "Attribute VB_GlobalNameSpace = False"); * assertContains(content, "Attribute VB_Exposed = True"); * } */ // Check the script one POITestCase.AssertContains(contents, "Module1"); String content = contents["Module1"]; Assert.IsNotNull(content); POITestCase.AssertContains(content, "Attribute VB_Name = \"Module1\""); //assertContains(content, "Attribute TestMacro.VB_Description = \"This is a test macro\""); // And the macro itself String testMacroNoSub = expectedMacroContents[samples]; POITestCase.AssertContains(content, testMacroNoSub); }