Example #1
0
        public static List <TeamMentor_Article> xmlDB_Load_GuidanceItemsV3(this TM_Xml_Database tmDatabase, Guid libraryId, List <string> guidanceItemsFullPaths)
        {
            var o2Timer     = new O2Timer("xmlDB_GuidanceItems").start();
            var itemsLoaded = 0;
            //var maxToLoad = 1000;
            var guidanceItems = new List <TeamMentor_Article>();

            foreach (var fullPath in guidanceItemsFullPaths)
            {
                var guidanceItemId = fullPath.fileName().remove(".xml");
                if (guidanceItemId.isGuid())
                {
                    var guidanceItem = tmDatabase.xmlDB_GuidanceItem(guidanceItemId.guid(), fullPath);
                    if (guidanceItem.notNull())
                    {
                        guidanceItems.add(guidanceItem);
                        guidanceItem.Metadata.Library_Id = libraryId;
                    }
                    //if (maxToload-- < 1)
                    //	break;
                    if (itemsLoaded++ % 200 == 0)
                    {
                        "loaded {0} items".info(itemsLoaded);
                    }
                }
                //if (itemsLoaded > maxToLoad)
                //	break;
            }
            o2Timer.stop();
            return(guidanceItems);
        }
        public static List <TreeNode> FromTreeViewCalculateViewForSpecificRootNode(String sRootNodeToTrace,
                                                                                   TreeView tvTracesData, String sKeyword,
                                                                                   TreeView tvRawData)
        {
            O2Timer tTimer = new O2Timer("Calculating Data TreeView for " + sKeyword).start();
            //tvTargetTreeView.Nodes.Clear();

            var      ltnCalculatedTreeNodes = new List <TreeNode>();
            var      lsFunctionsInTrace     = new List <string>();
            TreeNode tnNewTreeNode          = O2Forms.newTreeNode(tvTracesData.Nodes[sRootNodeToTrace].Text,
                                                                  tvTracesData.Nodes[sRootNodeToTrace].Text, 0,
                                                                  tvTracesData.Nodes[sRootNodeToTrace].Tag);

            addNodesToView_recursive(tnNewTreeNode, tvTracesData.Nodes[sRootNodeToTrace], tvTracesData, sKeyword,
                                     lsFunctionsInTrace, tvRawData);
            if (tnNewTreeNode != null)
            {
                foreach (TreeNode tnTreeNode in tnNewTreeNode.Nodes)
                {
                    ltnCalculatedTreeNodes.Add((TreeNode)tnTreeNode.Clone());
                }
            }
            tTimer.stop();
            if (tnNewTreeNode != null)
            {
                DI.log.info("Trace with {0}Data Calculated: It has {1} ({2}) Nodes (SubNodes)", sKeyword,
                            tnNewTreeNode.GetNodeCount(false), tnNewTreeNode.GetNodeCount(true));
            }
            return(ltnCalculatedTreeNodes);
        }
        public static CommonIRDump loadCirDumpXmlFile_justReturnCommonIRDump(String sPathToFileToProcess, bool bVerbose)
        {
            if (false == isFileACirDumpFile(sPathToFileToProcess))
            //  Path.GetExtension(sPathToFileToProcess) != ".xml")
            {
                DI.log.error("in loadCirDumpXmlFile_justReturnCommonIRDump, only CommonIRDump are supported");
                return(null);
            }
            O2Timer tO2TimerSerializedData = null;

            if (bVerbose)
            {
                DI.log.debug("Processing file {0}", Path.GetFileName(sPathToFileToProcess));
                tO2TimerSerializedData = new O2Timer("Creating object with serialized data ").start();
            }

            //CommonIRDump cidCommonIrDump = (xsd.CirDump.CommonIRDump)serialize.getDeSerializedObjectFromXmlFile(sPathToFileToProcess, typeof(xsd.CirDump.CommonIRDump));
            CommonIRDump cidCommonIrDump = null;

            if (false == loadCirDumpXmlFile(sPathToFileToProcess, ref cidCommonIrDump, false))
            {
                Hack.tryToFixCirDumpProblems(sPathToFileToProcess);
                loadCirDumpXmlFile(sPathToFileToProcess, ref cidCommonIrDump, true);
            }


            if (bVerbose)
            {
                tO2TimerSerializedData.stop();
            }
            return(cidCommonIrDump);
        }
        public void backup(string backupFolder, bool backupPages, bool backupFiles, bool backupCategoryPages, bool backupTemplates, bool backupUsers)
        {
            var o2Timer = new O2Timer("Backed up Wiki in").start();

            Backup_Directory.open(backupFolder);
            if (backupPages && CancelBackup.isFalse())
            {
                backup_Pages(backupFolder);
            }
            if (backupFiles && CancelBackup.isFalse())
            {
                backup_Files(backupFolder);
            }
            if (backupCategoryPages && CancelBackup.isFalse())
            {
                backup_CategoryPages(backupFolder);
            }
            if (backupTemplates && CancelBackup.isFalse())
            {
                backup_Templates(backupFolder);
            }
            if (backupUsers && CancelBackup.isFalse())
            {
                backup_Users(backupFolder);
            }
            //backupFolder.createDir();
            o2Timer.stop();
        }
        public static string loadGuidanceItemsFromCache(this string pathXmlLibraries)
        {
            //"Loading items from cache".info();
            var chacheFile = pathXmlLibraries.getCacheLocation();

            if (chacheFile.fileExists().isFalse())
            {
                "[TM_Xml_Database] in loadGuidanceItemsFromCache, cached file not found: {0}".error(chacheFile);
            }
            else
            {
                var o2Timer             = new O2Timer("loadGuidanceItemsFromCache").start();
                var loadedGuidanceItems = chacheFile.load <List <TeamMentor_Article> >();
                o2Timer.stop();
                if (loadedGuidanceItems.isNull()) //if we couldn't load it , delete it
                {
                    Files.deleteFile(chacheFile);
                }
                else
                {
                    o2Timer = new O2Timer("mapping to memory loadGuidanceItemsFromCache").start();
                    foreach (var loadedGuidanceItem in loadedGuidanceItems)
                    {
                        if (loadedGuidanceItem.notNull())
                        {
                            TM_Xml_Database.Cached_GuidanceItems.add(loadedGuidanceItem.Metadata.Id, loadedGuidanceItem);
                        }
                    }
                    o2Timer.stop();
                }
            }
            return(pathXmlLibraries);
        }
        public static WebBrowser waitForCompleted(this WebBrowser browser, int maxWait)
        {
            var url         = browser.url();
            var o2Timer     = new O2Timer("Loaded page: {0}".format(url)).start();
            var sync        = new AutoResetEvent(false);
            var abortThread = false;
            var thread      = O2Thread.mtaThread(
                () =>
            {
                //if (browser.readyState() == WebBrowserReadyState.Complete && browser.isBusy().isFalse() && url.str().contains("about:blank").isFalse())
                //    "[waitForCompleted] browser.readyState() was set to Complete and browser.isBusy was false when this was called".error();
                while ((browser.readyState() != WebBrowserReadyState.Complete ||
                        browser.isBusy().isTrue()) && abortThread.isFalse())
                {
                    browser.wait(100, false);
                }
                if (url.str() != "about:blank")
                {
                    "Waited for completed for: {0} : {1}".debug(url, browser.url());
                    o2Timer.stop();
                }
                sync.Set();
            });

            if (sync.WaitOne(maxWait).isFalse())
            {
                "Waiting for completion FAILED for: {0}".error(browser.url());
                abortThread = true;
            }
            return(browser);
        }
        public void get_GuiObjects_uniqueStrings_and_guidanceItemsMappings()
        {
            lock (ie)
            {
                "fetching GuiObjects".jQuery_Append_Body(ie);

                Action getGuiObjects =
                    () => {
                    var o2Timer = new O2Timer("Got GuiObjects").start();
                    ie.eval("delete TM.WebServices.Data.GuiObjects");
                    ie.eval("TM.WebServices.WS_Data.getGUIObjects()");
                    ie.waitForJsVariable("TM.WebServices.Data.GuiObjects");
                    o2Timer.stop().str().jQuery_Append_Body(ie);
                };

                //5.loop(getGuiObjects);
                getGuiObjects();

                var uniqueStrings         = ie.getJsVariable("TM.WebServices.Data.GuiObjects.UniqueStrings");
                var guidanceItemsMappings = ie.getJsVariable("TM.WebServices.Data.GuiObjects.GuidanceItemsMappings");
                Assert.That(uniqueStrings.notNull(), "uniqueStrings was null");
                Assert.That(guidanceItemsMappings.notNull(), "guidanceItemsMappings was null");

                var uniqueStrings_StringList         = uniqueStrings.extractList_String();
                var guidanceItemsMappings_StringList = guidanceItemsMappings.extractList_String();
                Assert.That(uniqueStrings_StringList.size() > 0, "no items in uniqueStrings_StringList");
                Assert.That(guidanceItemsMappings_StringList.size() > 0, "no items in guidanceItemsMappings_StringList");

                "Got GuiObjects via Javascriot, with {0} uniqueStrings and {1}".info(uniqueStrings_StringList.size(),
                                                                                     guidanceItemsMappings_StringList.size());
                "ok: get_GuiObjects_uniqueStrings_and_guidanceItemsMappings".jQuery_Append_Body(ie);
            }
        }
Example #8
0
        public static TM_Xml_Database xmlDB_Load_GuidanceItems(this TM_Xml_Database tmDatabase)
        {
            var pathXmlLibraries = TM_Xml_Database.Path_XmlLibraries;

            lock (pathXmlLibraries)
            {
                if (pathXmlLibraries.getCacheLocation().fileExists().isFalse())
                {
                    "[TM_Xml_Database] in xmlDB_Load_GuidanceItems, cache file didn't exist, so creating it".debug();
                    var o2Timer = new O2Timer("loaded GuidanceItems from disk").start();
                    //Load GuidanceItem from the disk
                    foreach (var guidanceExplorer in tmDatabase.xmlDB_GuidanceExplorers())
                    {
                        var libraryId = guidanceExplorer.library.name.guid();
                        var pathToLibraryGuidanceItems = pathXmlLibraries.pathCombine(guidanceExplorer.library.caption);
                        "libraryId: {0} : {1}".info(libraryId, pathToLibraryGuidanceItems);
                        var filesToLoad = pathToLibraryGuidanceItems.files(true, "*.xml");
                        tmDatabase.xmlDB_Load_GuidanceItemsV3(libraryId, filesToLoad);
                    }

                    //save it to the local cache file (reduces load time from 8s to 0.5s)
                    tmDatabase.save_GuidanceItemsCache();
                    o2Timer.stop();

                    tmDatabase.ensureFoldersAndViewsIdsAreUnique();
                    tmDatabase.removeMissingGuidanceItemsIdsFromViews();
                }
            }
            return(tmDatabase);
        }
        public static void populateGuidanceItemsFileMappings(this TM_Xml_Database tmXmlDatabase)
        {
            tmXmlDatabase.GuidanceItems_FileMappings.Clear();
            var o2Timer = new O2Timer("populateGuidanceExplorersFileMappings").start();

            foreach (var filePath in tmXmlDatabase.Path_XmlLibraries.files(true, "*.xml"))
            {
                var fileId = filePath.fileName().remove(".xml");
                if (fileId.isGuid())
                {
                    //"[populateGuidanceItemsFileMappings] loading GuidanceItem ID {0}".info(fileId);
                    var guid = fileId.guid();
                    if (tmXmlDatabase.GuidanceItems_FileMappings.hasKey(guid))
                    {
                        "[populateGuidanceItemsFileMappings] duplicate GuidanceItem ID found {0}".error(guid);
                    }
                    else
                    {
                        TM_Xml_Database.Current.GuidanceItems_FileMappings.Add(guid, filePath);
                    }
                }
            }
            o2Timer.stop();
            "There are {0} files mapped in GuidanceItems_FileMappings".info(TM_Xml_Database.Current.GuidanceItems_FileMappings.size());
        }
Example #10
0
        public static void consolidateNonVisibleNodes(GraphData fgdGraphData, bool bVerbose)
        {
            O2Timer tTimer         = new O2Timer("Created consolidaded graph").start();
            int     iPreviousCount = 0;
            int     iItemsToRemove = fgdGraphData.iItemsToRemove; // fgdGraphData.lnEmptyNodes.Count - 2;

            //foreach (Node nNodeToRemove in fgdGraphData.lnEmptyNodes)
            while (fgdGraphData.lnEmptyNodes.Count > 0)
            {
                if (iItemsToRemove > -1 && (0 == iItemsToRemove--))
                {
                    break;
                }
                iPreviousCount = fgdGraphData.lnEmptyNodes.Count;
                deleteNodeFromGraph(fgdGraphData, fgdGraphData.lnEmptyNodes[0], true);
                if (fgdGraphData.lnEmptyNodes.Count >= iPreviousCount)
                {
                    DI.log.error("Something went wrong since fgdGraphData.lnEmptyNodes.Count should go down");
                    break;
                }
            }
            //    createGraphWithConsolidatedPaths(ref fgdGraphData.gGraph);
            fgdGraphData.populateXrefDictionaries();
            if (bVerbose)
            {
                tTimer.stop();
            }
        }
Example #11
0
        public void deleteAddBreakpoints()
        {
            //CommandBase.Debugger.Processes.Active.Breakpoints
            try
            {
                // delete active breakpoints
                var timer = new O2Timer("Deleted active breakpoints in ").start();
                var breakpointsToDelete = new List <MDbgBreakpoint>();
                foreach (MDbgBreakpoint mdbgBreakpoint in o2MDbg.ActiveProcess.Breakpoints)
                {
                    breakpointsToDelete.Add(mdbgBreakpoint);
                }
                DI.log.info("There are {0} breakpoints to delete");
                foreach (MDbgBreakpoint mdbgBreakpoint in breakpointsToDelete)
                {
                    mdbgBreakpoint.Delete();
                }

                // delete archived breakpoints
                archivedBreakpoints_InSourceCode = new List <string>();
                timer.stop();
            }
            catch (Exception ex)
            {
                DI.log.ex(ex, "in deleteAddBreakpoints");
            }
        }
 private void addBreakpointsToAllMethodsInModule(string moduleToProcess, bool verbose)
 {
     DI.log.debug("Adding {0} breakpoints", methodsInModule.Count);
     O2Thread.mtaThread(() =>
     {
         var numberOfBreakpointsAdded = 0;
         var breakpointOffset         = 0;
         var timer         = new O2Timer("Breakpoint added in").start();
         MDbgModule module = DI.o2MDbg.sessionData.getModule(moduleToProcess);
         if (module != null)
         {
             foreach (Type typeInModule in module.Importer.DefinedTypes)
             {
                 // no point in adding interfaces or abstract types since they will not be bound (double check on abstract!!)
                 //if (false == typeInModule.IsInterface && false == typeInModule.IsAbstract)   // these are not implemented in the original MDbg :(
                 foreach (MethodInfo methodInType in typeInModule.GetMethods())
                 {
                     DI.o2MDbg.BreakPoints.add(moduleToProcess, typeInModule.FullName,
                                               methodInType.Name, breakpointOffset,
                                               verbose);
                     if (numberOfBreakpointsAdded++ % 500 == 0)
                     {
                         DI.log.info(
                             "  update: {0} breakpoints added so far of a max of {1}",
                             numberOfBreakpointsAdded, methodsInModule.Count);
                     }
                 }
             }
         }
         timer.stop();
         DI.log.info("There where {0} breakpoints added of a max of {1}", numberOfBreakpointsAdded, methodsInModule.Count);
     });
 }
Example #13
0
        public void Test_ProcessingAllO2AssembliesFromDirectory(ICirData cirData, string targetDirectory, bool verify,
                                                                bool verbose)
        {
            O2Timer checkTimer =
                new O2Timer("Test_ProcessingAllAssembliesFromDirectory " + targetDirectory + " took ").start();
            List <string> targetAssemblies = Files.getFilesFromDir_returnFullPath(targetDirectory, "*.exe");

            targetAssemblies.AddRange(Files.getFilesFromDir_returnFullPath(targetDirectory, "*.dll"));
            //targetAssemblies.AddRange();
            DI.log.debug("Testing processing of {0} dlls and exes directory {1}", targetAssemblies.Count,
                         targetDirectory);
            if (!verify)
            {
                DI.log.debug("Note, verification is disabled");
            }
            foreach (string targetDll in targetAssemblies)
            {
                if (CecilUtils.isDotNetAssembly(targetDll, false))
                {
                    Test_LoadingAssembly(cirData, targetDll, verify, verbose);
                }
            }
            CirFactoryUtils.showCirDataStats(cirData);
            checkTimer.stop();
        }
Example #14
0
        public void Test_LoadingAssembly(ICirData cirData, string assemblyToLoad, bool verify, bool verbose)
        {
            AssemblyDefinition assemblyDefinition = CecilUtils.getAssembly(assemblyToLoad);

            if (assemblyDefinition == null)
            {
                return;
            }

            var loadTimer = new O2Timer("Assembly " + Path.GetFileName(assemblyToLoad) + " Loaded in");

            if (verbose)
            {
                loadTimer.start();
            }
            cirFactory.processAssemblyDefinition(cirData, assemblyDefinition, assemblyToLoad);
            if (verbose)
            {
                loadTimer.stop();
            }
            if (verify)
            {
                var checkTimer = new O2Timer("       functions checked in  ");
                if (verbose)
                {
                    checkTimer.start();
                }
                checkThatAllFunctionsMatch(cirData, assemblyDefinition);
                if (verbose)
                {
                    checkTimer.stop();
                }
            }
        }
        public static void calculateO2TraceBlocksIntoTreeView(Dictionary <String, O2TraceBlock_OunceV6> dO2TraceBlock,
                                                              ref TreeView tvTargetTreeView)
        {
            DI.log.info("incalculateO2TraceBlocksIntoTreeView: {0}", dO2TraceBlock.Keys.Count);
            O2Timer tTimer = new O2Timer("Calculating Raw Data TreeView").start();

            tvTargetTreeView = new TreeView();
            var itemsProcessed = 0;
            var itemsToProcess = dO2TraceBlock.Keys.Count;
            var updateInterval = 1000;

            foreach (var sSignature in dO2TraceBlock.Keys)
            {
                if (itemsProcessed++ % updateInterval == 0)
                {
                    DI.log.info("[{0}/{1}]", itemsProcessed, itemsToProcess);
                }
                O2TraceBlock_OunceV6 otdO2TraceBlockOunceV6 = dO2TraceBlock[sSignature];
                //String sRootNodeText = String.Format("{0} {1} {2}", otdO2TraceBlockOunceV6.sSignature, System.IO.Path.GetFileName(otdO2TraceBlockOunceV6.sFile),otdO2TraceBlockOunceV6.sLineNumber);
                String sRootNodeText = String.Format("{0}      {1}      {2}", otdO2TraceBlockOunceV6.sSignature,
                                                     otdO2TraceBlockOunceV6.sFile, otdO2TraceBlockOunceV6.sLineNumber);
                TreeNode tnRootNode = O2Forms.newTreeNode(sRootNodeText, sRootNodeText, 0, otdO2TraceBlockOunceV6);
                // handle Sinks
                TreeNode tnSinks = O2Forms.newTreeNode("Sinks", "Sinks", 0, null);
                foreach (AssessmentAssessmentFileFinding fFinding in otdO2TraceBlockOunceV6.dSinks.Keys)
                {
                    String sSink = getUniqueSignature(fFinding, TraceType.Known_Sink,
                                                      otdO2TraceBlockOunceV6.dSinks[fFinding], true);
                    // analysis.Analysis.getSink(fFinding, otdO2TraceBlockOunceV6.dSinks[fFinding]);
                    if (!string.IsNullOrEmpty(sSink) || sSink != sRootNodeText)
                    {
                        TreeNode tnSink = O2Forms.newTreeNode(sSink, sSink, 0, null);
                        tnSinks.Nodes.Add(tnSink);
                    }
                }
                tnRootNode.Nodes.Add(tnSinks);
                TreeNode tnSources = O2Forms.newTreeNode("Sources", "Sources", 0, null);
                foreach (AssessmentAssessmentFileFinding fFinding in otdO2TraceBlockOunceV6.dSources.Keys)
                {
                    String sSource = getUniqueSignature(fFinding, TraceType.Source,
                                                        otdO2TraceBlockOunceV6.dSources[fFinding], true);
                    if (sSource == "" || sSource == null || sSource != sRootNodeText)
                    {
                        TreeNode tnSource = O2Forms.newTreeNode(sSource, sSource, 0, null);
                        tnSources.Nodes.Add(tnSource);
                    }
                }
                tnRootNode.Nodes.Add(tnSources);
                tvTargetTreeView.Nodes.Add(tnRootNode);
            }
            DI.log.info("[{0}/{1}]", itemsProcessed, itemsToProcess);
            //tvTargetTreeView.Sort();                                  // removed for performance reasons
            //tvAllTraces.Nodes.AddRange(tvRawData.Nodes);

            //tvAllTraces = tvRawData;
            tTimer.stop();
            DI.log.info("Tree View with Raw Data Calculated: It has {0} ({1}) Nodes (SubNodes)",
                        tvTargetTreeView.GetNodeCount(false), tvTargetTreeView.GetNodeCount(true));
        }
Example #16
0
        public bool Save(string savedCirDataFile)
        {
            Files.deleteFile(savedCirDataFile);
            var timer = new O2Timer("Saving CirData").start();

            CirDataAnalysisUtils.saveCirDataAnalysisObjectAsCirDataFile(this, savedCirDataFile);
            timer.stop();
            return(File.Exists(savedCirDataFile));
        }
Example #17
0
 public void createHost()
 {
     //if (WebServerHost.isNull())
     {
         var o2Timer = new O2Timer("Creating WebServer host").start();
         WebServerHost = (WebServerHost)ApplicationHost.CreateApplicationHost(typeof(WebServerHost), "/", WebRootDir);
         //WebServerHost = ApplicationHost.CreateApplicationHost(typeof(WebServerHost), "/", WebRootDir);
         o2Timer.stop();
     }
 }
Example #18
0
        public static IIS_Log_File logFile_Convert(this string file)
        {
            var o2Timer = new O2Timer("created IIS_Log_File object from file: {0}".format(file)).start();
            var logFile = new IIS_Log_File();

            logFile.File = file;
            logFile.convertData();
            o2Timer.stop();
            return(logFile);
        }
        public static API_CatNet analyze(this API_CatNet catNet, string file)
        {
            var o2Timer = new O2Timer("Scanned file in :").start();

            catNet.Engine.Analyze(file);
            o2Timer.stop();

            catNet.Engine.AnalysisEngine.ResetState();
            return(catNet);
        }
Example #20
0
            public static void addVelocityMappings(TreeView tvRawData)
            {
                String  sFunctionSignature = "ModelMap.addAttribute";
                O2Timer tTimer             = new O2Timer("Adding Velocity Mappings : {0} ").start();
                Dictionary <AssessmentAssessmentFileFinding, O2AssessmentData_OunceV6> dMatches =
                    analyzer.getSinksFindingsThatMatchRegEx(tvRawData, sFunctionSignature);

                foreach (AssessmentAssessmentFileFinding fFinding in dMatches.Keys)
                {
                    // resolve addAddtibute name
                    String sSinkContext        = AnalysisUtils.getSinkContext(fFinding, dMatches[fFinding]);
                    var    fsFilteredSignature = new FilteredSignature(sSinkContext);
                    String sParameters         = fsFilteredSignature.sParameters.Replace("\"", "");
                    String sSpringParameter    = sParameters.Substring(0, sParameters.IndexOf(',')).Trim();

                    // create a unique name for it:
                    String sSink = AnalysisUtils.getSink(fFinding, dMatches[fFinding]);
                    // String sSinkWithAttributeName = sSink.Replace("(", "_" + sSpringParameter + "(");
                    String sVelocityMapping = String.Format("{0}            0", sSink);

                    TreeNode tnVelocityNode = tvRawData.Nodes[sSink];
                    if (tnVelocityNode != null)
                    {
                        var otbO2TraceBlockWithVelocityMappings = (O2TraceBlock_OunceV6)tnVelocityNode.Tag;

                        String sUniqueSignature = analyzer.getUniqueSignature(fFinding, TraceType.Known_Sink,
                                                                              dMatches[fFinding], true);
                        var otbO2TraceBlockToAddVelocityMappings = (O2TraceBlock_OunceV6)tvRawData.Nodes[sUniqueSignature].Tag;
                        //   sUniqueSignature = sUniqueSignature.Replace("_" + sSpringParameter + "(", "(");
                        //  O2TraceBlock_OunceV6 otbO2TraceBlockToAddVelocityMappings = (O2TraceBlock_OunceV6)tvRawData.Nodes[sUniqueSignature].Tag;

                        if (otbO2TraceBlockWithVelocityMappings.dSinks.Count > 1)
                        {
                        }

                        foreach (
                            AssessmentAssessmentFileFinding fVelocityFinding in
                            otbO2TraceBlockWithVelocityMappings.dSinks.Keys)
                        {
                            if (false == otbO2TraceBlockToAddVelocityMappings.dGluedSinks.ContainsKey(fVelocityFinding))
                            {
                                otbO2TraceBlockToAddVelocityMappings.dGluedSinks.Add(fVelocityFinding,
                                                                                     otbO2TraceBlockWithVelocityMappings
                                                                                     .dSinks[fVelocityFinding]);
                            }
                            if (false == otbO2TraceBlockToAddVelocityMappings.dSinks.ContainsKey(fVelocityFinding))
                            {
                                otbO2TraceBlockToAddVelocityMappings.dSinks.Add(fVelocityFinding,
                                                                                otbO2TraceBlockWithVelocityMappings.
                                                                                dSinks[fVelocityFinding]);
                            }
                        }
                    }
                }
            }
        public void createUniqueListOfSignatures_forFile(string ozamstFileToTest)
        {
            DI.log.debug("\n\ntesting file: {0}", ozamstFileToTest);
            var timer            = new O2Timer("Unique Signatures calculated").start();
            var o2Findings       = new O2AssessmentLoad_OunceV6().loadFile(ozamstFileToTest).o2Findings;
            var uniqueSignatures = RulesAndFindingsUtils.getListOfUniqueSignatures(o2Findings);

            Assert.That(uniqueSignatures.Count > 0, "uniqueSignatures ==0");
            DI.log.info("Unique Signatures calculated = {0}", uniqueSignatures.Count);
            timer.stop();
        }
        public static bool click_Button_in_Window(this API_GuiAutomation guiAutomation, string windowTitle, string buttonText, bool animateMouse, int timesToTry)
        {
            Func <bool> check =
                () => {
                var o2Timer = new O2Timer("click_Button_in_Window").start();

                var scriptErrorWindow = guiAutomation.window(windowTitle);
                if (scriptErrorWindow.isNull())
                {
                }
                //"didn't find window with title: {0}".error(windowTitle);
                else
                {
                    var button = scriptErrorWindow.button(buttonText);
                    if (button.isNull())
                    {
                    }
                    // "didn't find button with text: {0}".error(buttonText);
                    else
                    {
                        "Found it: Clicking on button '{0}' in window '{1}' after {2} tries".debug(windowTitle, buttonText, timesToTry);
                        if (animateMouse)
                        {
                            button.mouse();
                        }
                        try
                        {
                            button.click();
                        }
                        catch (Exception ex)
                        {
                            "[API_GuiAutomation][click_Button_in_Window] on or after clicking on button".error(ex.Message);
                        }
                        o2Timer.stop();
                        return(true);
                    }
                }
                return(false);
            };

            "Trying to find  button '{0}' in window '{1}' for {2} tries".info(windowTitle, buttonText, timesToTry);

            for (int i = 0; i < timesToTry; i++)
            {
                var result = check();
                if (result)
                {
                    return(true);
                }
            }
            "Didn't find  button '{0}' in window '{1}' after {2} tries".error(windowTitle, buttonText, timesToTry);
            return(false);
        }
        public static string saveGuidanceItemsToCache(this string pathXmlLibraries)
        {
            var cacheFile = pathXmlLibraries.getCacheLocation();
            var o2Timer   = new O2Timer("saveGuidanceItemsToCache").start();

            lock (TM_Xml_Database.Cached_GuidanceItems)
            {
                TM_Xml_Database.Cached_GuidanceItems.Values.toList().saveAs(cacheFile);
            }
            o2Timer.stop();
            return(pathXmlLibraries);
        }
Example #24
0
        public static Database map_Table_Data(this Database database)
        {
            "Mapping table data".info();
            var timer = new O2Timer("Mapped tabled data").start();

            foreach (var table in database.tables())
            {
                database.map_Table_Data(table);
            }
            timer.stop();
            return(database);
        }
        public static void create_CustomSavedAssessmentRunFile_From_FindingsResult_List(
            List <AnalysisSearch.FindingsResult> lfrFindingsResults, String sPathToNewAssessmentFile)
        {
            O2Timer tTimer =
                new O2Timer("Creating new AssessmentRun File " + sPathToNewAssessmentFile).start();

            if (lfrFindingsResults.Count == 0)
            {
                DI.log.error("Aborting, no findings to save");
            }
            else
            {
                AssessmentRun arNewAssessmentRun = OzasmtUtils_OunceV6.getDefaultAssessmentRunObject();
                arNewAssessmentRun.name = "Search Results Project";
                var lFilesAndFindingsToAdd =
                    new Dictionary <AssessmentAssessmentFile, List <AssessmentAssessmentFileFinding> >();
                var dNewStringIndex = new Dictionary <String, UInt32>();
                var dNewFileIndex   = new Dictionary <String, UInt32>();
                foreach (AnalysisSearch.FindingsResult frFindingsResult in lfrFindingsResults)
                {
                    if (false == lFilesAndFindingsToAdd.ContainsKey(frFindingsResult.fFile))
                    // doesn't exist so we need to add it
                    {
                        lFilesAndFindingsToAdd.Add(frFindingsResult.fFile, new List <AssessmentAssessmentFileFinding>());
                    }

                    lFilesAndFindingsToAdd[frFindingsResult.fFile].Add(
                        VirtualTraces.createNewFindingFromExistingOne(frFindingsResult.fFinding, dNewStringIndex,
                                                                      dNewFileIndex,
                                                                      frFindingsResult.oadO2AssessmentDataOunceV6));
                }
                arNewAssessmentRun.StringIndeces = OzasmtUtils_OunceV6.createStringIndexArrayFromDictionary(dNewStringIndex);
                arNewAssessmentRun.FileIndeces   = OzasmtUtils_OunceV6.createFileIndexArrayFromDictionary(dNewFileIndex);

                var lafNewAssessmentFilesToAdd = new List <AssessmentAssessmentFile>();
                foreach (AssessmentAssessmentFile afOriginalFile in lFilesAndFindingsToAdd.Keys)
                {
                    AssessmentAssessmentFile afNewFile =
                        VirtualTraces.createNewAssessmentFileFromExistingOne(afOriginalFile);
                    afNewFile.Finding = lFilesAndFindingsToAdd[afOriginalFile].ToArray();
                    lafNewAssessmentFilesToAdd.Add(afNewFile);
                }
                arNewAssessmentRun.Assessment.Assessment[0].AssessmentFile = lafNewAssessmentFilesToAdd.ToArray();

                DI.log.info("New assessmentRun file created in memory, now saving it");
                // and save the serialized object as an Xml file
                OzasmtUtils_OunceV6.createSerializedXmlFileFromAssessmentRunObject(arNewAssessmentRun, sPathToNewAssessmentFile);
                tTimer.stop();
            }
            // if (false)
            //     o2Messages.sendMessage("open ViewAssessmentRun," + sPathToNewAssessmentFile);
        }
Example #26
0
        public static Dictionary<String, XmlNode> getAllBeans_RecursiveSearch(String sWebRoot)
        {
            if (bLoadFromO2VarsIfAvailable && vars.get(sO2VarToHoldBeansDictionary) != null)
                if (((Dictionary<String, XmlNode>) vars.get(sO2VarToHoldBeansDictionary)).Count > 0)
                    return (Dictionary<String, XmlNode>) vars.get(sO2VarToHoldBeansDictionary);
            O2Timer tTimer = new O2Timer("Loading all beans from web root").start();
            var dBeans = new Dictionary<String, XmlNode>();
            var lsXmlFilesInWebRoot = new List<String>();
            Files.getListOfAllFilesFromDirectory(lsXmlFilesInWebRoot, sWebRoot, true, "*.xml", false);
            DI.log.info("{0} xml files found", lsXmlFilesInWebRoot.Count);
            int iFilesProcessed = 0;
            foreach (var sXmlFile in lsXmlFilesInWebRoot)
            {
                try
                {
                    if (Path.GetExtension(sXmlFile).ToLower() == ".xml")
                    {
                        DI.log.info("({0}/{1} Processing xml file: {2}", (iFilesProcessed++), lsXmlFilesInWebRoot.Count,
                                    sXmlFile);
                        var xdXmlDocument = new XmlDocument();
                        String sXmlFileContents = Files.getFileContents(sXmlFile);
                        sXmlFileContents = sXmlFileContents.Replace("<!DOCTYPE", "<!--");
                        sXmlFileContents = sXmlFileContents.Replace(".dtd\">", "-->");

                        xdXmlDocument.LoadXml(sXmlFileContents);
                        xdXmlDocument.XmlResolver = null;
                        XmlNodeList xnlBeans = xdXmlDocument.GetElementsByTagName("bean");

                        foreach (XmlNode xnNode in xnlBeans)
                            if (xnNode.Attributes["id"] != null)
                            {
                                // first add by id
                                if (!dBeans.ContainsKey(xnNode.Attributes["id"].Value))
                                    dBeans.Add(xnNode.Attributes["id"].Value, xnNode);
                            }
                            else if (xnNode.Attributes["name"] != null) // then add by name
                                if (!dBeans.ContainsKey(xnNode.Attributes["name"].Value))
                                    dBeans.Add(xnNode.Attributes["name"].Value, xnNode);
                    }
                }
                catch (Exception ex)
                {
                    DI.log.ex(ex, "in getAllBeans_RecursiveSearch (inside foreach (var sXmlFile in lsXmlFilesInWebRoot)");
                    throw;
                }
            }
            vars.set_(sO2VarToHoldBeansDictionary, dBeans);
            DI.log.info("{0} beans loaded", dBeans.Count);

            tTimer.stop();
            return dBeans;
        }
Example #27
0
        public void _test_createJarStubForAllO2Assemblies()
        {
            var o2Timer      = new O2Timer("created Jar Stubs for all O2Assemblies").start();
            var o2Assemblies = CompileEngine.getListOfO2AssembliesInExecutionDir();

            foreach (var o2Assembly in o2Assemblies)
            {
                var jarStubFile = JavaCompile.createJarStubForDotNetDll(o2Assembly, IKVMConfig.jarStubsCacheDir);
                Assert.That(File.Exists(jarStubFile), "jarStubFile didn't exist: {0}", jarStubFile);
            }
            DI.log.info("\n...all done\n");
            o2Timer.stop();
        }
 public void loadAssessmentRunFileAndAddItToList(String sPathToFile, bool bCheckSourceCodeReferences)
 {
     if (Path.GetExtension(sPathToFile) == ".zip")
     {
         string tempFolder = DI.config.TempFolderInTempDirectory;
         new zipUtils().unzipFile(sPathToFile, tempFolder);
         foreach (string unzipedFile in Files.getFilesFromDir_returnFullPath(tempFolder))
         {
             loadAssessmentRunFileAndAddItToList(unzipedFile, bCheckSourceCodeReferences);
         }
     }
     else
     {
         O2AssessmentData_OunceV6 oadO2AssessmentData = null;
         O2Timer tTimer = new O2Timer("Loaded SavedAssessmentFile").start();
         Analysis.loadAssessmentFile(sPathToFile, false, ref oadO2AssessmentData);
         if (oadO2AssessmentData.arAssessmentRun == null)
         {
             DI.log.error(
                 "Serialized Saved Assessment run was null (are you sure this is an SavedAssessment file? :{0}",
                 sPathToFile);
             return;
         }
         // Calculate Xrefs into fadAssessmentData
         Analysis.populateDictionariesWithXrefsToLoadedAssessment(ffFindingFilter, bDropDuplicateSmartTraces,
                                                                  bIgnoreRootCallInvocation, oadO2AssessmentData);
         if (oadO2AssessmentData != null)
         {
             foreach (object oItem in lbLoadedAssessmentFiles.Items)
             {
                 if (oItem.ToString() == oadO2AssessmentData.ToString())
                 {
                     DI.log.error(
                         "in loadAssessmentRunFileAndAddItToList, file is already in the list of O2AssessmentRun objects");
                     tTimer.stop();
                     return;
                 }
             }
             lbLoadedAssessmentFiles.Items.Add(oadO2AssessmentData);
             //O2Forms.executeMethodThreadSafe(lbLoadedAssessmentFiles,lbLoadedAssessmentFiles.Items, "Add", new object[] { oadO2AssessmentData });
             //lbTargetSavedAssessmentFiles.Items.Add(oadO2AssessmentData);
         }
         if (bCheckSourceCodeReferences)
         {
             checkIfSourceCodeReferencesAreValid();
         }
         tTimer.stop();
         ascx_svpSearchAssessmentRun.setCheckBox_Checked(2, true);
     }
 }
Example #29
0
        public static Fortify_Scan mapFvdlData(this Fortify_Scan fortifyScan)
        {
            var o2Timer = new O2Timer("Mapped Fvdl Data").start();

            fortifyScan.mapScanDetails()
            .mapContextPool()
            .mapDescriptions()
            .mapCalledWithNoDefs()
            .mapSinks()
            .mapSources()
            .mapSnippets()
            .mapVulnerabilities();
            o2Timer.stop();
            return(fortifyScan);
        }
        public static void mapInRulePack_FindingsSourcesAndSinks(O2RulePack o2RulePack, Dictionary <string, List <IO2Rule> > indexedO2Rules, List <IO2Finding> o2Findings, string languageDBId)
        {
            var timer = new O2Timer("mapInRulePack_FindingsSourcesAndSinks").start();

            foreach (O2Finding o2Finding in o2Findings)
            {
                updateO2RulePackWithFindingsTraceTypes(o2RulePack, indexedO2Rules, o2Finding.o2Traces, languageDBId,
                                                       O2RuleType.Source);
            }

            /*updateSourceOrSinkRule(o2RulePack,indexedO2Rules, o2Finding.Source, languageDBId, O2RuleType.Source);
             * updateSourceOrSinkRule(o2RulePack,indexedO2Rules, o2Finding.KnownSink, languageDBId, O2RuleType.Sink);
             * updateSourceOrSinkRule(o2RulePack, indexedO2Rules, o2Finding.LostSink, languageDBId, O2RuleType.LostSink);                */
            timer.stop();
        }