Example #1
0
        public static TM_Xml_Database           xmlDB_Load_GuidanceItems_and_Create_CacheFile(this TM_Xml_Database tmDatabase)
        {
            if (tmDatabase.UsingFileStorage)
            {
                var pathXmlLibraries = TM_Xml_Database.Current.Path_XmlLibraries;
                if (pathXmlLibraries.notNull() && pathXmlLibraries.notNull())
                {
                    lock (pathXmlLibraries)
                    {
                        //if (tmDatabase.getCacheLocation().fileExists().isFalse())
                        //{
                        "[TM_Xml_Database] in xmlDB_Load_GuidanceItems, creating cache file".debug();
                        var o2Timer = new O2Timer("loaded GuidanceItems from disk").start();
                        //Load GuidanceItem from the disk
                        foreach (var item in tmDatabase.GuidanceExplorers_Paths)
                        {
                            var guidanceExplorer           = item.Key;
                            var pathToLibraryGuidanceItems = item.Value.parentFolder();
                            var libraryId = guidanceExplorer.library.name.guid();
                            "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_GuidanceItemsToCache();


                        tmDatabase.ensureFoldersAndViewsIdsAreUnique();
                        tmDatabase.removeMissingGuidanceItemsIdsFromViews();
                        o2Timer.stop();
                        //}
                    }
                }
            }
            return(tmDatabase);
        }
        public static TM_Xml_Database                    load_GuidanceItemsFromCache(this TM_Xml_Database tmDatabase)
        {
            //"Loading items from cache".info();
            var chacheFile = tmDatabase.getCacheLocation();

            if (chacheFile.fileExists().isFalse())
            {
                "[TM_Xml_Database] in loadGuidanceItemsFromCache, cached file not found: {0}".error(chacheFile);
                tmDatabase.xmlDB_Load_GuidanceItems_and_Create_CacheFile();
            }
            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.Current.Cached_GuidanceItems.add(loadedGuidanceItem.Metadata.Id,
                                                                             loadedGuidanceItem);
                        }
                    }
                    o2Timer.stop();
                }
                tmDatabase.populateGuidanceItemsFileMappings();
            }
            return(tmDatabase);
        }
        public static void populateGuidanceItemsFileMappings()
        {
            var o2Timer = new O2Timer("populateGuidanceExplorersFileMappings").start();

            foreach (var filePath in TM_Xml_Database.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 (TM_Xml_Database.GuidanceItems_FileMappings.hasKey(guid))
                    {
                        "[populateGuidanceItemsFileMappings] duplicate GuidanceItem ID found {0}".error(guid);
                    }
                    else
                    {
                        TM_Xml_Database.GuidanceItems_FileMappings.Add(guid, filePath);
                    }
                }
            }
            o2Timer.stop();
            "There are {0} files mapped in GuidanceItems_FileMappings".info(TM_Xml_Database.GuidanceItems_FileMappings.size());
        }
        public static Dictionary <IMethod, Dictionary <string, List <KeyValuePair <INode, IMethodOrProperty> > > > externalMethodsAndProperties(this O2MappedAstData astData, string filter, string targetFolder, int numberOfItemsToProcess)
        {
            var MimimumAvailableMemoryRequired = "".availableMemory() / 4;   //50;

            "Starting externalMethodsAndProperties calculations (with min memory required set to: {0}".info(MimimumAvailableMemoryRequired);
            if (targetFolder.valid().isFalse())
            {
                targetFolder = PublicDI.config.getTempFolderInTempDirectory("_AstEngine_ExternalMappings");
            }

            var methodMappingHashesFile = targetFolder.pathCombine("_methodMappingHashes.txt");

            var o2Timer         = new O2Timer("Calculated externalMethodsAndProperties").start();
            var iMethodMappings = new Dictionary <IMethod, Dictionary <string, List <KeyValuePair <INode, IMethodOrProperty> > > >();
            var iMethods        = astData.iMethods();
            var itemsToMap      = iMethods.size();// - targetFolder.files().size();
            var itemsMapped     = 0;

            foreach (var iMethod in iMethods)
            {
                // check avaialble memory
                var availableMemory = new System.Diagnostics.PerformanceCounter("Memory", "Available MBytes").NextValue();
                if (availableMemory < MimimumAvailableMemoryRequired)
                {
                    "In externalMethodsAndProperties, There is not enough free memory to continue (MimimumAvailableMemoryRequired = {0}, availableMemory = {1}. Stopping mappings".error(MimimumAvailableMemoryRequired, availableMemory);
                    "There are {0} iMethodMappings".debug(iMethodMappings.size());
                    break;
                }
                //"Available Memory: {0}".debug(availableMemory);

                //convert method
                var fullName = iMethod.fullName();
                var md5Hash  = fullName.safeFileName().md5Hash();
                var savedMethodMappingsFile = targetFolder.pathCombine(md5Hash) + ".xml";
                //var savedMethodMappingsFile = targetFolder.pathCombine(iMethod.fullName().safeFileName(100))+ ".xml";
                itemsMapped++;
                if (savedMethodMappingsFile.fileExists().isFalse())                 // Skip if method mappings have already been calculated
                {
                    //"Mapping :{0}".debug(iMethod.DotNetName);
                    if (iMethod.Name.regEx(filter))
                    {
                        var mappings = astData.externalMethodsAndProperties(iMethod);
                        iMethodMappings.Add(iMethod, mappings);
                        var savedMethodMappings = astData.saveMappings(mappings);
                        if (savedMethodMappings.fileExists())
                        {
                            Files.MoveFile(savedMethodMappings, savedMethodMappingsFile);
                            methodMappingHashesFile.fileInsertAt(0, "{0}\t{1}".format(md5Hash, fullName).line());
                        }
                    }
                    //savedMethodMappingsFile
                    if (itemsMapped % 10 == 0)                                  // every 10 methods show a log message
                    {
                        "In externalMethodsAndProperties, mapped [{0}/{1}] to folder: {2}".info(itemsMapped, itemsToMap, targetFolder);
                        if (itemsMapped % 100 == 0)
                        {
                            PublicDI.config.gcCollect();                                // every 100 methods release some memory
                        }
                    }
                    if (numberOfItemsToProcess > 0 && numberOfItemsToProcess < iMethodMappings.size())
                    {
                        "In externalMethodsAndProperties, max number of Items To Process reached ({0}), so stopping mappings]".info(numberOfItemsToProcess);
                        "There are {0} iMethodMappings".debug(iMethodMappings.size());
                        break;
                    }
                }
            }
            o2Timer.stop();
            return(iMethodMappings);
        }
Example #5
0
        private void filterByFilteredSignatures(List <FilteredSignature> filteredSignatures)
        {
            this.invokeOnThread(
                () =>
            {
                var filterToUse = cbFilter1.Text;

                O2Thread.mtaThread(
                    () =>
                {
                    var timer = new O2Timer("filterByFilteredSignatures").start();
                    List <string> listOfFilteredSignatures =
                        O2Linq.getListOfSignatures(filteredSignatures);
                    var newListOfO2Findings = new List <IO2Finding>();
                    foreach (IO2Finding o2Finding in currentO2Findings)
                    {
                        if (listOfFilteredSignatures.Contains(calculateTreeNodeText(o2Finding,
                                                                                    filterToUse, "")))
                        {
                            newListOfO2Findings.Add(o2Finding);
                        }
                    }
                    currentO2Findings = newListOfO2Findings;
                    timer.stop();
                    showCurrentO2Findings();
                });
            });


            /*
             *              this.invokeOnThread(
             *                  () =>
             *                      {
             *
             *                          tvFindings.Visible = false;
             *                          var nodesToRemove = new List<TreeNode>();
             *                          var nodesToAnalyze = new List<TreeNode>();
             *                          foreach (TreeNode treeNode in tvFindings.Nodes)
             *                              nodesToAnalyze.Add(treeNode);
             *
             *
             *                          nodesToRemove = removeFromTreeNodeCollectionOnFilteredSignatures(nodesToAnalyze,
             *                                                                                           listOfFilteredSignatures, currentFilteredTextMappings);
             *
             *
             *                          // and update indexes
             *                  /*        foreach (TreeNode currentTreeNode in tvFindings.Nodes)
             *                              if (currentTreeNode.Tag != null && currentTreeNode.Tag is List<TreeNode>)
             *                              {
             *                                  var subTreeNodesCount = ((List<TreeNode>) currentTreeNode.Tag).Count;
             *                                  if (subTreeNodesCount == 0)
             *                                      nodesToRemove.Add(currentTreeNode);
             *                                  else
             *                                  {
             *                                      currentTreeNode.Text += "   ... after filter (" + subTreeNodesCount +")";
             *                                      currentTreeNode.Collapse();
             *                                  }
             *                              }
             * /
             *                          // remove nodes from current tree
             *                          foreach (TreeNode treeNodeToRemove in nodesToRemove)
             *                              tvFindings.Nodes.Remove(treeNodeToRemove);
             *
             *                          tvFindings.Visible = true;
             *                          tvFindings.Refresh();
             *                          //    refreshView();
             *                      });
             *          });*/
        }
        public bool importFile(string fileToLoad, IO2Assessment o2Assessment)
        {
            try
            {
                if (canLoadFile(fileToLoad))
                {
                    //o2Assessment.lastOzasmtImportWasItSucessfull = false;
                    //o2Assessment.lastOzasmtImportFile = fileToLoad;
                    //o2Assessment.lastOzasmtImportFileSize = Files.getFileSize(fileToLoad);

                    //DateTime startImportTime = DateTime.Now;
                    var           timer = new O2Timer("Loaded assessment " + fileToLoad + " ").start();
                    AssessmentRun assessmentRunToImport = OzasmtUtils_OunceV6.LoadAssessmentRun(fileToLoad);
                    timer.stop();

                    /*     assessmentRun.AssessmentConfig = assessmentRunToImport.AssessmentConfig;
                     * assessmentRun.AssessmentStats = assessmentRunToImport.AssessmentStats;
                     * assessmentRun.Messages = assessmentRunToImport.Messages;
                     * assessmentRun.name = assessmentRunToImport.name ?? OzasmtUtils_OunceV6.calculateAssessmentNameFromScans(assessmentRunToImport);*/

                    o2Assessment.name = assessmentRunToImport.name ??
                                        OzasmtUtils_OunceV6.calculateAssessmentNameFromScans(assessmentRunToImport);

                    // I don't think I need this since the O2Finding objects have the full strings
                    // map top level objects

                    /*
                     * assessmentRun.FileIndeces = assessmentRunToImport.FileIndeces;
                     * assessmentRun.StringIndeces = assessmentRunToImport.StringIndeces;*/

                    // import findings
                    if (null != assessmentRunToImport.Assessment.Assessment)
                    {
                        foreach (Assessment assessment in assessmentRunToImport.Assessment.Assessment)
                        {
                            if (null != assessment.AssessmentFile)
                            {
                                foreach (AssessmentAssessmentFile assessmentFile in assessment.AssessmentFile)
                                {
                                    if (assessmentFile.Finding != null)
                                    {
                                        foreach (AssessmentAssessmentFileFinding finding in assessmentFile.Finding)
                                        {
                                            o2Assessment.o2Findings.Add(OzasmtUtils_OunceV6.getO2Finding(finding,
                                                                                                         assessmentFile,
                                                                                                         assessmentRunToImport));
                                        }
                                    }
                                }
                            }
                        }
                    }

                    // if we made it this far all went ok;
                    //o2Assessment.lastOzasmtImportTimeSpan = DateTime.Now - startImportTime;
                    //o2Assessment.lastOzasmtImportWasItSucessfull = true;
                    return(true);
                }
            }
            catch
            (Exception ex)
            {
                "in importAssessmentRun: {0}".error(ex.Message);
            }
            return(false);
        }
        public void setCompilerEnvironment()
        {
            var o2Timer = new O2Timer("Code Compiled in");

            this.csharpCompiler = new CSharp_FastCompiler();
            //csharpCompiler.field("forceAstBuildDelay",250);       // try to prevent the problem with missing the compilation of the last char
            this.csharpCompiler.beforeSnippetAst =
                () =>
            {
                this.csharpCompiler.InvocationParameters = this.InvocationParameters;
            };


            this.csharpCompiler.onAstFail =
                () =>
            {
                //"AST creation failed".error();
                //	this.sourceCodeViewer.enabled(false);
                executeButton.enabled(false);
                result_RichTextBox.textColor(Color.Red).set_Text("Ast Parsing Errors:\r\n\r\n");
                //.append_Text(csharpCompiler.AstErrors);
                commandsToExecute.updateCodeComplete(csharpCompiler);
                sourceCodeViewer.setDocumentContents(csharpCompiler.SourceCode);
                OnAstFail.invoke();
            };

            this.csharpCompiler.onAstOK =
                () =>
            {
                o2Timer.start();
                commandsToExecute.editor().refresh();
                sourceCodeViewer.enabled(true);
                commandsToExecute.invokeOnThread(() => commandsToExecute.Refresh());
                GeneratedCode = csharpCompiler.SourceCode;
                commandsToExecute.updateCodeComplete(csharpCompiler);
                sourceCodeViewer.setDocumentContents(csharpCompiler.SourceCode);
                OnAstOK.invoke();
            };

            csharpCompiler.onCompileFail =
                () =>
            {
                //"AST OK, but compilation failed".error();
                executeButton.enabled(false);
                var codeOffset = csharpCompiler.getGeneratedSourceCodeMethodLineOffset();
                csharpCompiler.CompilationErrors.runForEachCompilationError(
                    (row, col) =>
                {
                    sourceCodeViewer.editor().setSelectedText(row, col, true, false);
                    commandsToExecute.editor().setSelectedText(
                        row - codeOffset.Line,
                        col - codeOffset.Column,
                        true,                              /*showAsError*/
                        false,                             /*showAsBookMark*/
                        false);                            /*decrementLineAndColumn*/
                });
                result_RichTextBox.textColor(Color.Red)
                .set_Text("Compilation Errors:\r\n\r\n")
                .append_Text(csharpCompiler.CompilationErrors);
                onCompileFail.invoke();
            };
            csharpCompiler.onCompileOK =
                () =>
            {
                o2Timer.stop();
                "Compilation OK".debug();
                commandsToExecute.editor().refresh();
                sourceCodeViewer.editor().refresh();
                result_RichTextBox.set_Text("Compilation OK:\r\n\r\n")
                .textColor(Color.Green);
                executeButton.enabled(true);
                if (AutoSaveOnCompileSuccess && Code != defaultCode)
                {
                    AutoSaveDir.createDir();       // make sure it exits
                    var targetFile = AutoSaveDir.pathCombine(Files.getFileSaveDateTime_Now().trim() + ".cs");
                    targetFile.fileWrite(Code);
                }

                onCompileOK.invoke();
                // once all is done update the codeComplete information
                if (commandsToExecute.editor().o2CodeCompletion.notNull())
                {
                    commandsToExecute.editor().o2CodeCompletion.addReferences(csharpCompiler.ReferencedAssemblies);
                }

                //add_ExtraMethodsFile();									// restore previous mappings here

                //register cacheAssmbly
                var codeMd5 = previousCompiledCodeText.md5Hash();
                CompileEngine.CachedCompiledAssemblies.add(codeMd5, this.csharpCompiler.CompiledAssembly.Location);

                executeButton.enabled(true);

                if (ExecuteOnCompile)
                {
                    execute();
                }
            };
        }
Example #8
0
        public static API_Veracode_DetailedXmlFindings show_Flaws_In_SourceCodeViewer(this API_Veracode_DetailedXmlFindings apiVeracode, Control control)
        {
            var topPanel     = control.clear();
            var codeViewer   = topPanel.add_GroupBox("Flaw SourceCode reference").add_SourceCodeViewer();
            var treeView     = codeViewer.parent().insert_Left("Flaws").add_TreeView();
            var propertyGrid = treeView.insert_Below(150, "Flaw properties")
                               .add_PropertyGrid().helpVisible(false);
            var description = codeViewer.insert_Below(150, "Flaw description")
                              .add_TextArea();

            treeView.afterSelect <FlawType>(
                (flaw) => {
                propertyGrid.show(flaw);
                if (apiVeracode.hasLocalSourceCodeFile(flaw))
                {
                    codeViewer.open(apiVeracode.sourceCodeFile(flaw));
                    codeViewer.editor().gotoLine((int)flaw.line);
                }
                else
                {
                    codeViewer.set_Text(".. no source code available...");
                }
                description.set_Text(flaw.description.fix_CRLF());
                treeView.focus();
            });

            treeView.beforeExpand <List <FlawType> >(
                (flaws) => {
                var selectedNode = treeView.selected();
                if (selectedNode.nodes().size() == 1)
                {
                    selectedNode.clear();
                    selectedNode.add_Nodes(flaws,
                                           (flaw) => flaw.type,
                                           (flaw) => apiVeracode.hasLocalSourceCodeFile(flaw)
                                                                                                                                                ? Color.DarkGreen
                                                                                                                                                : Color.DarkRed
                                           );
                }
            });

            Action <TreeNode, Dictionary <string, List <FlawType> > > addFlawsToTreeNode =
                (treeNode, mappedFlaws)
                => {
                foreach (var item in mappedFlaws)
                {
                    treeNode.add_Node(item.Key, item.Value, item.Value.size() > 0);
                }
                /*.*/
            };

            Action showData =
                () => {
                treeView.clear();
                var o2Timer                   = new O2Timer("Building XRefs for flaws").start();
                var mappedFlawsByType         = new Dictionary <string, List <FlawType> >();
                var mappedFlawsByCategoryName = new Dictionary <string, List <FlawType> >();
                var mappedFlawsByFile         = new Dictionary <string, List <FlawType> >();
                var mappedFlawsBySeverity     = new Dictionary <string, List <FlawType> >();

                foreach (var flaw in apiVeracode.flaws())
                {
                    mappedFlawsByCategoryName.add(flaw.categoryname, flaw);
                    mappedFlawsByType.add(flaw.type, flaw);
                    mappedFlawsByFile.add(flaw.sourceCodeFile(), flaw);
                    mappedFlawsBySeverity.add(flaw.severity.str(), flaw);
                }
                o2Timer.stop();
                o2Timer = new O2Timer("Populating treeview").start();
                addFlawsToTreeNode(treeView.add_Node("by Category Name"), mappedFlawsByCategoryName);
                addFlawsToTreeNode(treeView.add_Node("by Type"), mappedFlawsByType);
                addFlawsToTreeNode(treeView.add_Node("by File"), mappedFlawsByFile);
                addFlawsToTreeNode(treeView.add_Node("by Severity"), mappedFlawsBySeverity);
                o2Timer.stop();
            };

            treeView.onDrop(
                (file) => {
                apiVeracode.load(file);
                showData();
            });
            if (apiVeracode.ReportXmlFile.valid())
            {
                showData();
            }
            else
            {
                treeView.add_Node("drop a Veracode DetailedFindings Xml (or zip) file to view it");
            }


//			"There were {0} Files That Could Not Mapped Locally".error(apiVeracode.FilesThatCouldNotMappedLocally.size());

            /*if (treeView.nodes()>0))
             * {
             *      treeView.nodes()[0]
             *                      .expand().nodes()[2].selected();
             * }
             */
            return(apiVeracode);
        }
Example #9
0
        public ascx_WSDL_Creation_and_Execution buildGui()
        {
            var topPanel = this.add_Panel();

            topPanel.insert_Below(100).add_LogViewer();
            //var assemblyInvoke = topPanel.add_Control<O2.External.SharpDevelop.Ascx.ascx_AssemblyInvoke>();
            //assemblyInvoke.loadAssembly("OnlineStorage.dll".assembly());
            //var methodProperties = topPanel.add_DataGridView();
            var methodProperties = topPanel.add_GroupBox("Request Data").add_Control <ascx_ObjectViewer>();

            methodProperties.showSerializedString().createObjectWhenNull().simpleView();

            Methods_TreeView           = methodProperties.parent().insert_Left("Soap Methods").add_TreeView().sort();
            ExecutionResult            = methodProperties.parent().insert_Below(150).add_GroupBox("Web Service Invocation Response Data").add_TextArea();
            ExecutionResult_Properties = ExecutionResult.insert_Right().add_PropertyGrid();
            ExecutionResult_TreeView   = ExecutionResult_Properties.insert_Below().add_TreeView();
            ExecuteSoapRequest_Button  = methodProperties.insert_Below(40)
                                         .add_Button("Execute Soap request")
                                         .font_bold()
                                         .fill();

            Methods_TreeView.afterSelect <MethodInfo>(
                (methodInfo) => {
                CurrentMethod = methodInfo;
                "Current Method: {0}".info(CurrentMethod.Name);
                "Current Method: Signature = {0}".info(CurrentMethod.str());
                "Current Method: DeclaringType = {0}".info(CurrentMethod.DeclaringType.FullName);
                SoapParametersObject = methodInfo.create_LiveObject_From_MethodInfo_Parameters("Soap_Invocation_Parameters");
                if (SoapParametersObject.notNull())
                {
                    methodProperties.visible(true);
                    methodProperties.show(SoapParametersObject);
                }
                else
                {
                    methodProperties.visible(false);
                }
                //new O2FormsReflectionASCX().loadMethodInfoParametersInDataGridView(methodInfo, methodProperties);
            });

            ExecuteSoapRequest_Button.onClick(
                () => {
                //var parameters = new O2FormsReflectionASCX().getParameterObjectsFromDataGridColumn(methodProperties, "Value");
                var invocationParameters = new List <object>();
                foreach (var property in SoapParametersObject.type().properties())
                {
                    invocationParameters.add(SoapParametersObject.property(property.Name));
                }

                ExecutionResult.set_Text("[{0}] Executing method : {1}".line().format(DateTime.Now, CurrentMethod.Name));

                var liveObject = CurrentMethod.DeclaringType.ctor();
                ExecutionResult.append_Line("Created dynamic proxy object of type: {0}".format(liveObject));

                try
                {
                    var o2Timer  = new O2Timer("Method execution time: ").start();
                    ResultObject = CurrentMethod.Invoke(liveObject, invocationParameters.ToArray());
                    ExecutionResult.append_Line("Method execution time: {0}".format(o2Timer.stop()));
                    ExecutionResult.append_Line("Method Executed OK, here is the return value:");
                    ExecutionResult.append_Line(ResultObject.str().lineBeforeAndAfter());
                    ExecutionResult_Properties.show(ResultObject);
                    ExecutionResult_TreeView.xmlShow(ResultObject.serialize());
                }
                //catch(System.Web.Services.Protocols.SoapException ex)
                //{

                //}
                catch (Exception ex)
                {
                    ExecutionResult.append_Line((ex.InnerException.property("Detail") as System.Xml.XmlElement).OuterXml);
                    ExecutionResult.append_Line(ex.InnerException.Message);
                    ExecutionResult.append_Line(ex.InnerException.StackTrace);
                    //show.info(ex);
                    //ex.details();
                }

                //currentMethod.invoke(parameters);

                ExecutionResult.append_Line("Execution complete");
            });


            Methods_TreeView.insert_Below(20)
            .add_CheckBox("Show Full Method Signatures", 0, 0, (value) => ShowFullMethodSignatures = value)
            .autoSize()
            .parent <Panel>()
            .add_CheckBox("Cache WSDL Dll", 0, 200, (value) => Cache_WSDL_Dll = value)
            .autoSize()
            .check();


            //.append_Link("Delete cached compiled dll", deleteCachedFile);

            ExecutionResult.insert_Below(20)
            .add_Link("View serialized string of response object", 0, 0,
                      () => {
                var serializedResponse = ResultObject.serialize(false);
                if (serializedResponse.notNull())
                {
                    "".showInCodeViewer().set_Text(serializedResponse, "a.xml");
                }
            });

            TestWebServices = topPanel.insert_Above(22).add_ComboBox();

            WsdlLocation = topPanel.insert_Above(22)
                           .add_LabelAndTextAndButton("Load Custom WSDL from location (file or url)", "", "Load", (value) => open(value))
                           .control <TextBox>();
            ExtraWsdlParameres = topPanel.insert_Above(22).add_Label("Extra wsdl.exe parameters").left(WsdlLocation.Left).top(2)
                                 .append_TextBox("").align_Right(topPanel);
            addScriptingSupport();


            add_TestWebServices();

            return(this);
        }
        public static void remapIsCalledByXrefs(ICirDataAnalysis cirDataAnalysis)
        {
            try
            {
                remapSuperClassesXrefs(cirDataAnalysis);
                var timer = new O2Timer("remapIsCalledByXrefs").start();

                // first clear all Xref

                foreach (var cirFunction in cirDataAnalysis.dCirFunction_bySignature.Values)
                {
                    cirFunction.FunctionIsCalledBy = new List <ICirFunctionCall>();
                }

                // make sure all FunctionsCalledUniqueList and FunctionsCalled are syncronized with dCirFunction_bySignature
                var functionsToMap     = cirDataAnalysis.dCirFunction_bySignature.Values.ToList().Count;
                var functionsProcessed = 0;
                foreach (var cirFunction in cirDataAnalysis.dCirFunction_bySignature.Values.ToList())
                {
                    for (int i = 0; i < cirFunction.FunctionsCalledUniqueList.Count; i++)
                    {
                        cirFunction.FunctionsCalledUniqueList[i] = syncFunctions(cirDataAnalysis, cirFunction.FunctionsCalledUniqueList[i]);
                    }
                    for (int i = 0; i < cirFunction.FunctionsCalled.Count; i++)
                    {
                        cirFunction.FunctionsCalled[i].cirFunction = syncFunctions(cirDataAnalysis, cirFunction.FunctionsCalled[i].cirFunction);
                    }
                    if ((functionsProcessed++) % 500 == 0)
                    {
                        DI.log.info("  processed {0} / {1}", functionsProcessed, functionsToMap);
                    }
                }

                // check the FunctionsCalledUniqueList is calledby mappngs
                foreach (var cirFunction in cirDataAnalysis.dCirFunction_bySignature.Values)
                {
                    foreach (var functionCalled in cirFunction.FunctionsCalled)
                    {
                        var functionCalledXref = getFunctionRef(cirDataAnalysis, functionCalled.cirFunction);

                        /*if (false == cirDataAnalysis.dCirFunction_bySignature.ContainsValue(functionCalled))
                         *  DI.log.error("in remapIsCalledByXrefs something is wrong because the called fucntions does not have a cirFunction mapping: {0}", functionCalled.FunctionSignature);
                         * else
                         * //{*/
                        bool found = false;
                        foreach (var functionCall in functionCalled.cirFunction.FunctionIsCalledBy)
                        {
                            if (functionCall.cirFunction == functionCalledXref)
                            {
                                found = true;
                            }
                        }
                        if (found == false)
                        {
                            functionCalled.cirFunction.FunctionIsCalledBy.Add(new CirFunctionCall(cirFunction, functionCalled.fileName, functionCalled.lineNumber));
                        }
                        //if (false == functionCalledXref.FunctionIsCalledBy.Contains(cirFunction))
                        //    functionCalledXref.FunctionIsCalledBy.Add(cirFunction);
                    }
                }

                // make sure all functions are syncronized with dCirFunction_bySignature
                foreach (var cirFunction in cirDataAnalysis.dCirFunction_bySignature.Values)
                {
                    for (int i = 0; i < cirFunction.FunctionsCalledUniqueList.Count; i++)
                    {
                        cirFunction.FunctionsCalledUniqueList[i] = syncFunctions(cirDataAnalysis, cirFunction.FunctionsCalledUniqueList[i]);
                    }
                }

                // endure all iscalledby are correcly mapped
                foreach (var cirFunction in cirDataAnalysis.dCirFunction_bySignature.Values)
                {
                    for (int i = 0; i < cirFunction.FunctionIsCalledBy.Count; i++)
                    {
                        cirFunction.FunctionIsCalledBy[i].cirFunction = syncFunctions(cirDataAnalysis, cirFunction.FunctionIsCalledBy[i].cirFunction);
                    }
                }

                // make sure there is a reference to this function on the Classes Dictionanry
                foreach (var cirFunction in cirDataAnalysis.dCirFunction_bySignature.Values)
                {
                    foreach (var functionCalled in cirFunction.FunctionsCalled)
                    {
                        if (functionCalled.cirFunction.ParentClass == null)
                        {
                            var functionSignature = new FilteredSignature(functionCalled.cirFunction.FunctionSignature);
                            var parentClassName   = functionSignature.sFunctionClass;
                            if (false == cirDataAnalysis.dCirClass_bySignature.ContainsKey(parentClassName))
                            {
                                cirDataAnalysis.dCirClass_bySignature.Add(parentClassName, new CirClass(parentClassName));
                            }
                            var parentCirClass = cirDataAnalysis.dCirClass_bySignature[parentClassName];
                            var functionAlreadyMappedToClass = false;
                            foreach (var cirFunctionMappedToClass in parentCirClass.dFunctions.Values)
                            {
                                if (cirFunctionMappedToClass.FunctionSignature == functionCalled.cirFunction.FunctionSignature)
                                {
                                    functionAlreadyMappedToClass = true;
                                }
                            }
                            if (false == functionAlreadyMappedToClass)
                            {
                                parentCirClass.dFunctions.Add(functionCalled.cirFunction.FunctionSignature, functionCalled.cirFunction);
                            }
                            functionCalled.cirFunction.ParentClass         = parentCirClass;
                            functionCalled.cirFunction.ParentClassName     = parentCirClass.Name;
                            functionCalled.cirFunction.ParentClassFullName = parentCirClass.FullName;
                        }
                    }
                }

                timer.stop();
            }
            catch (Exception ex)
            {
                DI.log.error("in remapIsCalledByXrefs: {0}", ex.Message);
            }
        }
Example #11
0
            public static void findSpringAttributes(TreeView tvRawData)
            {
                String  sFunctionSignature = "ModelMap.addAttribute";
                O2Timer tTimer             = new O2Timer("Resolving attribute based function: {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 + "(");
                    // make sure we have not added this already
                    if (sSink.IndexOf(sSpringParameter) == -1)
                    {
                        //     String sSinkWithAttributeName = sSink.Replace("(", "_" + sSpringParameter + "(");
                        //      String sSinkWithAttributeName = sSpringParameter;
                        String sUniqueSignature = analyzer.getUniqueSignature(fFinding, TraceType.Known_Sink,
                                                                              dMatches[fFinding], true);
                        var otbO2TraceBlockOfThisFinding = (O2TraceBlock_OunceV6)tvRawData.Nodes[sUniqueSignature].Tag;

                        CallInvocation ciCallInvocation =
                            AnalysisSearch.findTraceTypeInSmartTrace_Recursive_returnCallInvocation(
                                fFinding.Trace, TraceType.Known_Sink);
                        UInt32 uNewId = OzasmtUtils_OunceV6.addTextToStringIndexes(sSinkWithAttributeName,
                                                                                   dMatches[fFinding].arAssessmentRun);
                        ;
                        ciCallInvocation.sig_id = uNewId;
                        DI.log.debug(" Found spring attribute '{0}' on sinks and modified to {1}", sSpringParameter,
                                     sSinkWithAttributeName);
                        //o2.analysis.Analysis.getSink(fFinding, dMatches[fFinding]));
                        otbO2TraceBlockOfThisFinding.sSignature  = sSinkWithAttributeName;
                        otbO2TraceBlockOfThisFinding.sUniqueName = analyzer.getUniqueSignature(fFinding,
                                                                                               TraceType.
                                                                                               Known_Sink,
                                                                                               dMatches[fFinding], true);

                        List <O2TraceBlock_OunceV6> lotbO2TraceBlockWithVelocityMappings =
                            analyzer.getO2TraceBlocksThatMatchSignature(sSinkWithAttributeName, tvRawData);


/*                        String sVelocityMapping = String.Format("{0}            0", sSinkWithAttributeName);
 *                      TreeNode tnVelocityNode = tvRawData.Nodes[sVelocityMapping];
 *                      if (tnVelocityNode != null)
 */
                        foreach (
                            O2TraceBlock_OunceV6 otbO2TraceBlockWithVelocityMappings in lotbO2TraceBlockWithVelocityMappings)
                        {
                            if (otbO2TraceBlockWithVelocityMappings.sFile.IndexOf(".vm") > -1)
                            {
                                //O2TraceBlock_OunceV6 otbO2TraceBlockWithVelocityMappings = (O2TraceBlock_OunceV6)tnVelocityNode.Tag;
                                foreach (
                                    AssessmentAssessmentFileFinding fVelocityFinding in
                                    otbO2TraceBlockWithVelocityMappings.dSinks.Keys)
                                {
                                    if (false == otbO2TraceBlockOfThisFinding.dGluedSinks.ContainsKey(fVelocityFinding))
                                    {
                                        otbO2TraceBlockOfThisFinding.dGluedSinks.Add(fVelocityFinding,
                                                                                     otbO2TraceBlockWithVelocityMappings
                                                                                     .dSinks[fVelocityFinding]);
                                    }
                                    if (false == otbO2TraceBlockOfThisFinding.dSinks.ContainsKey(fVelocityFinding))
                                    {
                                        otbO2TraceBlockOfThisFinding.dSinks.Add(fVelocityFinding,
                                                                                otbO2TraceBlockWithVelocityMappings.
                                                                                dSinks[fVelocityFinding]);
                                    }
                                }
                            }
                        }
                    }
                }
                tTimer.stop();
            }