コード例 #1
0
        protected void FromFile(POIDataSamples dataSamples, String filename)
        {
            FileInfo       f = dataSamples.GetFileInfo(filename);
            VBAMacroReader r = new VBAMacroReader(f);

            try
            {
                AssertMacroContents(dataSamples, r);
            }
            finally
            {
                r.Close();
            }
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        protected void FromStream(POIDataSamples dataSamples, String filename)
        {
            InputStream fis = new FileInputStream(dataSamples.OpenResourceAsStream(filename));

            try
            {
                VBAMacroReader r = new VBAMacroReader(fis);
                try
                {
                    AssertMacroContents(dataSamples, r);
                }
                finally
                {
                    r.Close();
                }
            }
            finally
            {
                fis.Close();
            }
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        protected void FromNPOIFS(POIDataSamples dataSamples, String filename)
        {
            FileInfo         f  = dataSamples.GetFileInfo(filename);
            NPOIFSFileSystem fs = new NPOIFSFileSystem(f);

            try
            {
                VBAMacroReader r = new VBAMacroReader(fs);
                try
                {
                    AssertMacroContents(dataSamples, r);
                }
                finally
                {
                    r.Close();
                }
            }
            finally
            {
                fs.Close();
            }
        }