コード例 #1
0
 public void fromTreeNodeListCalculateRulesToAdd_recursive(TreeNodeCollection tncTreeNodes,
                                                           List <String> lsRulesToAdd, CirData fadCirData)
 {
     foreach (TreeNode tnTreeNode in tncTreeNodes)
     {
         if (fadCirData.dClasses_bySignature.ContainsKey(tnTreeNode.Text))
         {
             ICirClass ccCirClass = fadCirData.dClasses_bySignature[tnTreeNode.Text];
             foreach (ICirFunction cfCirFunction in ccCirClass.dFunctions.Values)
             {
                 foreach (TreeNode tnChildNode in tnTreeNode.Nodes)
                 {
                     String sGetterVersion = tnChildNode.Text.Replace("set", "get");
                     if (new FilteredSignature(cfCirFunction.FunctionSignature).sFunctionName == sGetterVersion)
                     {
                         if (false == lsRulesToAdd.Contains(cfCirFunction.FunctionSignature))
                         {
                             lsRulesToAdd.Add(cfCirFunction.FunctionSignature);
                         }
                     }
                     if (tnChildNode.Nodes.Count > 0)
                     {
                         fromTreeNodeListCalculateRulesToAdd_recursive(tnChildNode.Nodes, lsRulesToAdd,
                                                                       fadCirData);
                     }
                 }
             }
         }
         //   String sClass = tnTreeNode.Text;
     }
 }
コード例 #2
0
        public void Test_processTypeDefinition(ICirData cirData, ICirClass cirClass)
        {
            Assert.That(cirClass != null, "cirClass was null");
            Assert.That(cirClass.dFunctions.Count == 7, "cirClass.dFunctions.Count != 7 , it was " + cirClass.dFunctions.Count);

            // check if we can get the functions by name
            ICirFunction testMethodA = cirClass.getFunction("testMethodA()");
            Assert.IsNotNull(testMethodA, "could not get testMethodA from cirClass object");
            ICirFunction testMethodB = cirClass.getFunction("testMethodB()");
            Assert.IsNotNull(testMethodB, "could not get testMethodB from cirClass object");
            Assert.IsNotNull(cirClass.getFunction("testMethodB(System.String)"),
                             "could not get testMethodB(string) from cirClass object");
            Assert.IsNotNull(cirClass.getFunction("testMethodD(System.String,System.Type)"),
                             "could not get testMethodD(System.String,System.Type) from cirClass object");

            ICirFunction testMethodC = cirClass.getFunction("testMethodC");

            // check if we have the calls and isCalledBy
            Assert.That(testMethodA.FunctionsCalledUniqueList.Contains(testMethodB),
                        "failed on testMethodA.FunctionsCalledUniqueList.Contains(testMethodB)");
            Assert.That(testMethodA.FunctionsCalledUniqueList.Contains(testMethodC),
                        "failed on testMethodA.FunctionsCalledUniqueList.Contains(testMethodB)");
            var found = false;
            foreach (var calledByFunction in testMethodB.FunctionIsCalledBy)
                if (calledByFunction.cirFunction == testMethodA)
                    found = true;
            Assert.That(found,
                        "failed on testMethodB.FunctionIsCalledBy.Contains(testMethodA)");
        }
コード例 #3
0
        public void showSpringMvcClases(List <String> lsClasses, CirData fadCirData)
        {
            tvSpringMvcClasses.Nodes.Clear();
            foreach (String sClass in lsClasses)
            {
                ICirClass ccCirClass = fadCirData.dClasses_bySignature[sClass];
                var       tnClass    = new TreeNode(ccCirClass.Signature);
                foreach (CirFunction cfCirFunction in ccCirClass.dFunctions.Values)
                {
                    var fsSignature = new FilteredSignature(cfCirFunction.FunctionSignature);
                    var tnFunction  = new TreeNode(fsSignature.sFunctionNameAndParams);
                    foreach (String sFunctionCalled in ViewHelpers.getCirFunctionStringList(cfCirFunction.FunctionsCalledUniqueList))
                    {
                        var tnFunctionCalled = new TreeNode(sFunctionCalled);
                        //if (sFunctionCalled.IndexOf("setCommandName") > -1)
                        String sCommandNameValue = getValueFromControlFlowGraphCall(cfCirFunction.lcfgBasicBlocks,
                                                                                    sFunctionCalled);
                        if (sCommandNameValue != "")
                        {
                            tnFunctionCalled.Nodes.Add(sCommandNameValue);
                        }
                        tnFunction.Nodes.Add(tnFunctionCalled);
                    }

                    tnClass.Nodes.Add(tnFunction);
                }
                tvSpringMvcClasses.Nodes.Add(tnClass);
            }
        }
        /*    private void onSelectedItemTreeViewBeforeExpand(TreeNode selectedTreeNode)
         * {
         *  //return;
         *  if (selectedTreeNode != null && selectedTreeNode.Tag is ICirFunction)
         *  {
         *      selectedTreeNode.Nodes.Clear();
         *
         *      /*     var filteredSignature = (FilteredSignature)selectedTreeNode.Tag;
         *           var signature = filteredSignature.sOriginalSignature;
         *           if (cirDataAnalysis.dCirFunction_bySignature.ContainsKey(signature))
         *           {* /
         *      var cirFunction = (ICirFunction)selectedTreeNode.Tag;
         *      // makesCallToNode
         *      //var makesCallToNode = new TreeNode("Makes calls to:");
         *      foreach (var makesCallsTo in cirFunction.FunctionsCalledUniqueList)
         *          addCirFunctionToTreeNodeCollection(makesCallsTo, "=>", selectedTreeNode.Nodes);
         *      // isCalledByNode
         *
         *      //var isCalledByNode = new TreeNode("Is called by:");
         *      foreach (var isCalledBy in cirFunction.FunctionIsCalledBy)
         *          addCirFunctionToTreeNodeCollection(isCalledBy, "<=", selectedTreeNode.Nodes);
         *      /*  }
         *        else
         *            selectedTreeNode.Nodes.Add("Could not find the signature:" + signature);*/
        /*     var functionNode = new TreeNode("Function: " + cirFunction.FunctionName);
         *
         *   // makesCallToNode
         *   var makesCallToNode = new TreeNode("Makes calls to:");
         *   foreach (var makesCallsTo in cirFunction.FunctionsCalledUniqueList)
         *       makesCallToNode.Nodes.Add(makesCallsTo.FunctionName);
         *   // isCalledByNode
         *   var isCalledByNode = new TreeNode("Is called by:");
         *   foreach (var isCalledBy in cirFunction.FunctionIsCalledBy)
         *       isCalledByNode.Nodes.Add(isCalledBy.FunctionName);
         *
         *   functionNode.Nodes.Add(makesCallToNode);
         *   functionNode.Nodes.Add(isCalledByNode);
         *   tvSelectedItemInfo.Nodes.Add(functionNode);
         *   ;* /
         * }
         * }
         *
         */


        public void viewCirClass(ICirClass cirClass)
        {
            if (cirClass != null)
            {
                this.invokeOnThread(
                    () =>
                {
                    showClassAttributes(cirClass);
                    laFunctionViewed.Text = cirClass.Signature;
                    rootCirFunction       = null;
                    currentCirClass       = cirClass;

                    tvFunctionIsCalledBy.Nodes.Clear();
                    tvFunctionMakesCallsTo.Nodes.Clear();
                    tvFunctionInfo.Nodes.Clear();

                    //tvClassSuperClasses
                    tvClassSuperClasses.Nodes.Clear();
                    ViewHelpers.addCirClassToTreeNodeCollection(cirClass, "", tvClassSuperClasses.Nodes,
                                                                cirClass.dSuperClasses.Count > 0);
                    O2Forms.expandNodes(tvClassSuperClasses);

                    //tvClassIsSuperClassedBy
                    tvClassIsSuperClassedBy.Nodes.Clear();
                    ViewHelpers.addCirClassToTreeNodeCollection(cirClass, "", tvClassIsSuperClassedBy.Nodes,
                                                                cirClass.dIsSuperClassedBy.Count > 0);
                    O2Forms.expandNodes(tvClassIsSuperClassedBy);

                    viewClassMethods(functionViewerForClassMethods, cirClass, cbViewInheritedMethods.Checked, cbIgnoreCoreObjectClass.Checked);

                    cbCirFunction_IsTainted.Checked = false;
                });
            }
        }
コード例 #5
0
        public void Test_processAssemblyDefinition()
        {
            ICirData           cirData      = new CirData();
            AssemblyDefinition testAssembly = getTestAssembly();

            cirFactory.processAssemblyDefinition(cirData, testAssembly, null);
            Assert.That(cirData.dClasses_bySignature.Count > 0, "cirData.dClasses_bySignature.Count == 0");

            // check that all functions from this assembly match
            checkThatAllFunctionsMatch(cirData, testAssembly);

            // check that the type is there
            TypeDefinition testTypeDefinition = CecilUtils.getType(testAssembly, "testType");

            Assert.That(
                cirData.dClasses_bySignature.ContainsKey(
                    CirFactoryUtils.getTypeUniqueSignatureFromTypeReference(testTypeDefinition)),
                "testTypeDefinition.FullName was not there");
            Assert.IsNotNull(cirData.getClass(testTypeDefinition.FullName),
                             "when using testTypeDefinition.FullName, cirClass was null");

            ICirClass cirClass = cirData.getClass("testType");

            Assert.IsNotNull(cirClass, "when using 'testType',  cirClass was null");
            Test_processTypeDefinition(cirData, cirClass);
        }
コード例 #6
0
        public void mapClass(ICirClass cirClass, ICirData _cirData, bool clearPreviousList)
        {

            cirData = _cirData;
            cirRootClass = cirClass;
            mapCurrentClass(clearPreviousList);
        }
コード例 #7
0
 public static void calculateListofMethodsCalledByClass_Recursive(
     ICirClass ccClass, List <ICirClass> lccTargetCompilationClasses, List <String> lsFunctionsCalled,
     String sResultsFilter /*, Dictionary<String, String> dFunctionsNames*/, ICirData fcdCirData)
 {
     if (ccClass != null)
     {
         foreach (ICirFunction cfCirFunction in ccClass.dFunctions.Values)
         {
             foreach (ICirFunction cirFunctionCalled in cfCirFunction.FunctionsCalledUniqueList)
             {
                 String sName = cirFunctionCalled.FunctionSignature;
                 //    if (sName.IndexOf("()") == -1)                          // don't add functions that receive no parameters
                 if (sResultsFilter == "" || sName.IndexOf(sResultsFilter) > -1)
                 {
                     if (false == lsFunctionsCalled.Contains(cirFunctionCalled.FunctionSignature))
                     {
                         lsFunctionsCalled.Add(cirFunctionCalled.FunctionSignature);
                         ICirClass ccCalledClass = getCirClassObjectFromFunctionSignature(cirFunctionCalled.FunctionSignature, fcdCirData);
                         if (false == lccTargetCompilationClasses.Contains(ccCalledClass))
                         {
                             lccTargetCompilationClasses.Add(ccCalledClass);
                         }
                         calculateListofMethodsCalledByClass_Recursive(ccCalledClass, lccTargetCompilationClasses,
                                                                       lsFunctionsCalled, sResultsFilter,
                                                                       /*dFunctionsNames,*/ fcdCirData);
                         //     getCirClassObjectFromFunctionDef(sFunctionCalled,dFunctionsNames, fcdCirData);
                     }
                 }
             }
         }
     }
 }
コード例 #8
0
        public void Test_processTypeDefinition()
        {
            ICirData           cirData            = new CirData();
            AssemblyDefinition testAssembly       = getTestAssembly();
            TypeDefinition     testTypeDefinition = CecilUtils.getType(testAssembly, "testType");
            ICirClass          cirClass           = cirFactory.processTypeDefinition(cirData, testTypeDefinition);

            Test_processTypeDefinition(cirData, cirClass);
        }
        public static ascx_CirDataViewer show(this ICirClass cirClass)
        {
            var cirData = new CirData();

            cirData.dClasses_bySignature.Add(cirClass.Name, cirClass);
            var cirDataViewer = cirData.show(0);

            return(cirDataViewer);
        }
        //   public ICirDataAnalysis cirDataAnalysis { get; set; }

        /*public static void viewCirFunctionSignature(string functionSignature, ICirDataAnalysis _cirDataAnalysis)
         * {
         *  if (_cirDataAnalysis.dCirFunction_bySignature.ContainsKey(functionSignature))
         *      viewCirFunctionSignature(_cirDataAnalysis.dCirFunction_bySignature[functionSignature], _cirDataAnalysis);
         * }*/
        public void viewCirFunction(ICirFunction _rootCirFunction)
        {
            if (_rootCirFunction != null)
            {
                this.invokeOnThread(
                    () =>
                {
                    showFunctionAttributes(_rootCirFunction);
                    laFunctionViewed.Text = _rootCirFunction.FunctionSignature;
                    rootCirFunction       = _rootCirFunction;
                    currentCirClass       = _rootCirFunction.ParentClass;

                    //tvFunctionIsCalledBy
                    tvFunctionIsCalledBy.Nodes.Clear();
                    ViewHelpers.addCirFunctionToTreeNodeCollection(rootCirFunction, "",
                                                                   tvFunctionIsCalledBy.Nodes,
                                                                   rootCirFunction.FunctionIsCalledBy.Count > 0);
                    O2Forms.expandNodes(tvFunctionIsCalledBy);

                    //tvFunctionMakesCallsTo
                    tvFunctionMakesCallsTo.Nodes.Clear();
                    ViewHelpers.addCirFunctionToTreeNodeCollection(rootCirFunction, "",
                                                                   tvFunctionMakesCallsTo.Nodes,
                                                                   rootCirFunction.FunctionsCalledUniqueList.Count > 0);
                    O2Forms.expandNodes(tvFunctionMakesCallsTo);

                    //tvFunctionInfo
                    tvFunctionInfo.Nodes.Clear();
                    ViewHelpers.addCirFunctionToTreeNodeCollection(rootCirFunction, "", tvFunctionInfo.Nodes,
                                                                   rootCirFunction.FunctionsCalledUniqueList.Count > 0 || rootCirFunction.FunctionIsCalledBy.Count > 0);
                    O2Forms.expandNodes(tvFunctionInfo);

                    //tvClassSuperClasses
                    tvClassSuperClasses.Nodes.Clear();
                    if (rootCirFunction.ParentClass != null)
                    {
                        ViewHelpers.addCirClassToTreeNodeCollection(rootCirFunction.ParentClass, "", tvClassSuperClasses.Nodes,
                                                                    rootCirFunction.ParentClass.dSuperClasses.Count > 0);
                        O2Forms.expandNodes(tvClassSuperClasses);
                    }

                    //tvClassSuperClasses
                    tvClassIsSuperClassedBy.Nodes.Clear();
                    if (rootCirFunction.ParentClass != null)
                    {
                        ViewHelpers.addCirClassToTreeNodeCollection(rootCirFunction.ParentClass, "", tvClassIsSuperClassedBy.Nodes,
                                                                    rootCirFunction.ParentClass.dIsSuperClassedBy.Count > 0);
                        O2Forms.expandNodes(tvClassIsSuperClassedBy);
                    }

                    cbCirFunction_IsTainted.Checked = rootCirFunction.IsTainted;

                    viewClassMethods();
                });
            }
        }
コード例 #11
0
 public void clearLoadedData()
 {
     this.invokeOnThread(() =>
     {
         cirData        = null;
         cirRootClass   = null;
         cirClassMapped = new List <ICirClass>();
         tvBindableFields.Nodes.Clear();
     });
 }
コード例 #12
0
     //   public ICirDataAnalysis cirDataAnalysis { get; set; }

        /*public static void viewCirFunctionSignature(string functionSignature, ICirDataAnalysis _cirDataAnalysis)
        {
            if (_cirDataAnalysis.dCirFunction_bySignature.ContainsKey(functionSignature))
                viewCirFunctionSignature(_cirDataAnalysis.dCirFunction_bySignature[functionSignature], _cirDataAnalysis); 
        }*/
        public void viewCirFunction(ICirFunction _rootCirFunction)
        {
            if (_rootCirFunction != null)
                this.invokeOnThread(
                    () =>
                        {
                            showFunctionAttributes(_rootCirFunction);
                            laFunctionViewed.Text = _rootCirFunction.FunctionSignature;
                            rootCirFunction = _rootCirFunction;
                            currentCirClass = _rootCirFunction.ParentClass;
                            
                            //tvFunctionIsCalledBy
                            tvFunctionIsCalledBy.Nodes.Clear();
                            ViewHelpers.addCirFunctionToTreeNodeCollection(rootCirFunction, "",
                                                                           tvFunctionIsCalledBy.Nodes,
                                                                           rootCirFunction.FunctionIsCalledBy.Count > 0);
                            O2Forms.expandNodes(tvFunctionIsCalledBy);

                            //tvFunctionMakesCallsTo
                            tvFunctionMakesCallsTo.Nodes.Clear();
                            ViewHelpers.addCirFunctionToTreeNodeCollection(rootCirFunction, "",
                                                                           tvFunctionMakesCallsTo.Nodes,
                                                                           rootCirFunction.FunctionsCalledUniqueList.Count > 0);
                            O2Forms.expandNodes(tvFunctionMakesCallsTo);

                            //tvFunctionInfo
                            tvFunctionInfo.Nodes.Clear();
                            ViewHelpers.addCirFunctionToTreeNodeCollection(rootCirFunction, "", tvFunctionInfo.Nodes,
                                                                           rootCirFunction.FunctionsCalledUniqueList.Count > 0 || rootCirFunction.FunctionIsCalledBy.Count > 0);
                            O2Forms.expandNodes(tvFunctionInfo);

                            //tvClassSuperClasses
                            tvClassSuperClasses.Nodes.Clear();
                            if (rootCirFunction.ParentClass != null)
                            {
                                ViewHelpers.addCirClassToTreeNodeCollection(rootCirFunction.ParentClass, "", tvClassSuperClasses.Nodes,
                                                                            rootCirFunction.ParentClass.dSuperClasses.Count > 0);
                                O2Forms.expandNodes(tvClassSuperClasses);
                            }

                            //tvClassSuperClasses
                            tvClassIsSuperClassedBy.Nodes.Clear();
                            if (rootCirFunction.ParentClass != null)
                            {
                                ViewHelpers.addCirClassToTreeNodeCollection(rootCirFunction.ParentClass, "", tvClassIsSuperClassedBy.Nodes,
                                                                            rootCirFunction.ParentClass.dIsSuperClassedBy.Count > 0);
                                O2Forms.expandNodes(tvClassIsSuperClassedBy);
                            }

                            cbCirFunction_IsTainted.Checked = rootCirFunction.IsTainted;

                            viewClassMethods();

                        });
        }
コード例 #13
0
 public void showSpringSuperClasses(List <String> lsClasses, ICirData fadCirData)
 {
     tvSpringMvc_SuperClasses.Nodes.Clear();
     foreach (String sClass in lsClasses)
     {
         ICirClass ccCirClass = fadCirData.dClasses_bySignature[sClass];
         var       tnClass    = new TreeNode(ccCirClass.Signature);
         addIsSuperClassedByToTreeNode_ReCursive(tnClass, ccCirClass);
         tvSpringMvc_SuperClasses.Nodes.Add(tnClass);
     }
 }
コード例 #14
0
 public static void raiseSourceCodeReferenceEvent(bool raiseEvent, ICirClass cirClass, bool remapLineNumber)
 {
     if (raiseEvent)
     {
         if (cirClass.File != null && cirClass.FileLine != null)
         {
             int mappedLineNumber = GetMappedLineNumber(cirClass.Name, cirClass.File, cirClass.FileLine, true, remapLineNumber);
             O2Messages.fileOrFolderSelected(cirClass.File, mappedLineNumber);
         }
     }
 }
コード例 #15
0
        // need to check of other class values
        public static void mergeClasses(ICirDataAnalysis cirDataAnalysis, ICirClass classHost, ICirClass classToMerge)
        {
            foreach (var propertyInfo in DI.reflection.getProperties(typeof(ICirClass)))
            {
                if (DI.reflection.getProperty(propertyInfo.Name, classHost) == null && DI.reflection.getProperty(propertyInfo.Name, classToMerge) != null)
                {
                    DI.reflection.setProperty(propertyInfo.Name, classHost,
                                              DI.reflection.getProperty(propertyInfo.Name, classToMerge));
                }
            }

            addClass(cirDataAnalysis, classToMerge);
        }
 private void showClassAttributes(ICirClass cirClass)
 {
     if (cirClass != null)
     {
         tvClassAttributes.Nodes.Clear();
         foreach (var attribute in cirClass.ClassAttributes)
         {
             var signature = new FilteredSignature(attribute.AttributeClass).sSignature;
             var treeNode  = tvClassAttributes.Nodes.Add(signature);
             foreach (var parameter in attribute.Parameters)
             {
                 treeNode.Nodes.Add(parameter.Key);
             }
         }
     }
 }
コード例 #17
0
        public static List <ICirFunction> getListOfInheritedMethods(ICirClass targetClass, bool ignoreCoreObjectClass)
        {
            var inheritedMethods = new List <ICirFunction>();

            if (targetClass != null) // && targetClass.Signature != "java.lang.Object")
            {
                foreach (var cirFunction in targetClass.dFunctions.Values)
                {
                    inheritedMethods.Add(cirFunction);
                }
                foreach (var cirClass in targetClass.dSuperClasses.Values)
                {
                    inheritedMethods.AddRange(getListOfInheritedMethods(cirClass, ignoreCoreObjectClass));
                }
            }
            return(inheritedMethods);
        }
コード例 #18
0
            public static void mapInterfaces(TreeView tvRawData, ICirData cdCirData, String sHardCodedInterfaceKeywork,
                                             bool bAddGluedTracesAsRealTraces)
            {
                DI.log.debug("Mapping Interfaces");
                O2Timer tTimer = new O2Timer("Interfaces mapping completed").start();
                // Int32 iItemsProcessed = 0;

                Dictionary <AssessmentAssessmentFileFinding, O2AssessmentData_OunceV6> dAllSinkFindings =
                    analyzer.getUniqueListOfSinks(tvRawData);

                foreach (AssessmentAssessmentFileFinding fFinding in dAllSinkFindings.Keys)
                {
                    String sSink = AnalysisUtils.getSink(fFinding, dAllSinkFindings[fFinding]);
                    if (sSink != "" && sSink.IndexOf(sHardCodedInterfaceKeywork) > -1)
                    {
                        if (false == cdCirData.dFunctions_bySignature.ContainsKey(sSink))
                        {
                            DI.log.error("in mapInterfaces, could not find signature in loaded CirData file: {0}",
                                         sSink);
                        }
                        else
                        {
                            ICirFunction cfCirFunction = cdCirData.dFunctions_bySignature[sSink];
                            ICirClass    ccCirClass    = cfCirFunction.ParentClass;
                            foreach (ICirClass ccIsSuperClassedBy in ccCirClass.dIsSuperClassedBy.Values)
                            {
                                String sMappedMethodName = cfCirFunction.FunctionSignature.Replace(ccCirClass.Signature,
                                                                                                   ccIsSuperClassedBy.
                                                                                                   Signature);
                                List <O2TraceBlock_OunceV6> lotdMatches =
                                    analyzer.getO2TraceBlocksThatMatchSignature(sMappedMethodName, tvRawData);
                                foreach (O2TraceBlock_OunceV6 otbO2TraceBlockWithTracesToGlue in lotdMatches)
                                {
                                    addFindingAsGlueTrace(otbO2TraceBlockWithTracesToGlue, fFinding,
                                                          dAllSinkFindings[fFinding], tvRawData,
                                                          bAddGluedTracesAsRealTraces);
                                }
                            }
                        }
                    }
                }

                tTimer.stop();
            }
コード例 #19
0
        public static TreeNode addCirClassToTreeNodeCollection(ICirClass cirClass, string treeNodeNamePrefix, TreeNodeCollection treeNodeCollection, bool addDummyChildNode)
        {
            if (cirClass == null)
            {
                return(null);
            }
            //if (cirFunction.FunctionSignature != "")
            //{
            var filteredSignature = new O2.DotNetWrappers.Filters.FilteredSignature(cirClass.Signature);
            var treeNodeName      = String.Format(" => {0}", filteredSignature.sSignature);
            var newTreeNode       = O2Forms.newTreeNode(treeNodeCollection, treeNodeName, cirClass.Signature, 0,
                                                        cirClass);

            if (addDummyChildNode)
            {
                newTreeNode.Nodes.Add("");     // Dummy node so that we have the plus sign
            }
            return(newTreeNode);
            //}
        }
コード例 #20
0
 private static void addClass(ICirDataAnalysis cirDataAnalysis, ICirClass ccCirClass)
 {
     if (cirDataAnalysis.dCirClass_bySignature.ContainsKey(ccCirClass.Signature))
     {
         var mainRefCirClass = cirDataAnalysis.dCirClass_bySignature[ccCirClass.Signature];
         if (mainRefCirClass != ccCirClass)          // if they are diferent we need to sync the superclasses dictionary
         {
             foreach (var superclass in ccCirClass.dSuperClasses.Keys)
             {
                 if (false == mainRefCirClass.dSuperClasses.ContainsKey(superclass))
                 {
                     mainRefCirClass.dSuperClasses.Add(superclass, ccCirClass.dSuperClasses[superclass]);
                 }
             }
         }
     }
     else
     {
     }
     foreach (ICirFunction cfCirFunction in ccCirClass.dFunctions.Values)
     //                if (cfCirFunction.HasControlFlowGraph)
     {
         if (false == cirDataAnalysis.dCirFunction.ContainsKey(cfCirFunction))
         {
             cirDataAnalysis.dCirFunction.Add(cfCirFunction, ccCirClass);
         }
         // we need this cross check with ccCirClass since we will it to resolve cfCirFunction data
         if (false ==
             cirDataAnalysis.dCirFunction_bySignature.ContainsKey(cfCirFunction.FunctionSignature))
         {
             addFunction(cirDataAnalysis, cfCirFunction);
         }
         else
         {
             var functionHost =
                 cirDataAnalysis.dCirFunction_bySignature[cfCirFunction.FunctionSignature];
             var functionToMerge = cfCirFunction;
             mergeFunctions(cirDataAnalysis, functionHost, functionToMerge);
         }
     }
 }
コード例 #21
0
        public static void calculateTargetComplilationClassFromStartClassSignature(
            String sStartClassSignature, ref List <ICirClass> lccTargetCompilationClasses,
            ref List <String> lsFunctionsCalled, String sResultsFilter, /*Dictionary<String, String> dFunctionsNames,*/
            ICirData fcdCirData)
        {
            if (lccTargetCompilationClasses == null)
            {
                lccTargetCompilationClasses = new List <ICirClass>();
            }
            if (lsFunctionsCalled == null)
            {
                lsFunctionsCalled = new List <string>();
            }
            ICirClass ccTargetCirClass = null;

            if (fcdCirData.dClasses_bySignature.ContainsKey(sStartClassSignature))
            {
                ccTargetCirClass = fcdCirData.dClasses_bySignature[sStartClassSignature];
            }
            else
            {
                foreach (ICirClass ccCirClass in fcdCirData.dClasses_bySignature.Values)
                {
                    if (ccCirClass.Signature.IndexOf(sStartClassSignature) > -1)
                    {
                        //ccTargetCirClass = fcdCirData.dClasses_bySignature[sCirClass];
                        lccTargetCompilationClasses.Add(ccCirClass);
                        break;
                    }
                }
            }

            calculateListofMethodsCalledByClass_Recursive(ccTargetCirClass, lccTargetCompilationClasses,
                                                          lsFunctionsCalled, sResultsFilter, /*dFunctionsNames,*/ fcdCirData);


            //foreach (String sFunctionCalled in lsFunctionsCalled)
            //     DI.log.debug(getSymbol(sFunctionCalled));
        }
コード例 #22
0
        public void Test_MultipleProcessingOfSameTypesAndAssembly()
        {
            ICirData           cirData      = new CirData();
            AssemblyDefinition testAssembly = getTestAssembly();

            // add assembly Object
            cirFactory.processAssemblyDefinition(cirData, testAssembly, null);
            ICirClass cirClass = cirData.getClass("testType");

            // test it
            Test_processTypeDefinition(cirData, cirClass);

            // add each type individually
            foreach (TypeDefinition typeDefinition in CecilUtils.getTypes(testAssembly))
            {
                cirFactory.processTypeDefinition(cirData, typeDefinition);
            }

            // test it again
            ICirClass cirClass2 = cirData.getClass("testType");

            Test_processTypeDefinition(cirData, cirClass);
            Test_processTypeDefinition(cirData, cirClass2);
        }
コード例 #23
0
        public void Test_processTypeDefinition(ICirData cirData, ICirClass cirClass)
        {
            Assert.That(cirClass != null, "cirClass was null");
            Assert.That(cirClass.dFunctions.Count == 7, "cirClass.dFunctions.Count != 7 , it was " + cirClass.dFunctions.Count);

            // check if we can get the functions by name
            ICirFunction testMethodA = cirClass.getFunction("testMethodA()");

            Assert.IsNotNull(testMethodA, "could not get testMethodA from cirClass object");
            ICirFunction testMethodB = cirClass.getFunction("testMethodB()");

            Assert.IsNotNull(testMethodB, "could not get testMethodB from cirClass object");
            Assert.IsNotNull(cirClass.getFunction("testMethodB(System.String)"),
                             "could not get testMethodB(string) from cirClass object");
            Assert.IsNotNull(cirClass.getFunction("testMethodD(System.String,System.Type)"),
                             "could not get testMethodD(System.String,System.Type) from cirClass object");

            ICirFunction testMethodC = cirClass.getFunction("testMethodC");

            // check if we have the calls and isCalledBy
            Assert.That(testMethodA.FunctionsCalledUniqueList.Contains(testMethodB),
                        "failed on testMethodA.FunctionsCalledUniqueList.Contains(testMethodB)");
            Assert.That(testMethodA.FunctionsCalledUniqueList.Contains(testMethodC),
                        "failed on testMethodA.FunctionsCalledUniqueList.Contains(testMethodB)");
            var found = false;

            foreach (var calledByFunction in testMethodB.FunctionIsCalledBy)
            {
                if (calledByFunction.cirFunction == testMethodA)
                {
                    found = true;
                }
            }
            Assert.That(found,
                        "failed on testMethodB.FunctionIsCalledBy.Contains(testMethodA)");
        }
コード例 #24
0
 public void addIsSuperClassedByToTreeNode_ReCursive(TreeNode tnTargetTreeNode, ICirClass ccCirClass)
 {
     foreach (ICirClass ccSuperClass in ccCirClass.dSuperClasses.Values)
     {
         var tnSuperClass = new TreeNode(ccSuperClass.Signature);
         addIsSuperClassedByToTreeNode_ReCursive(tnSuperClass, ccSuperClass);
         tnTargetTreeNode.Nodes.Add(tnSuperClass);
     }
 }
コード例 #25
0
 public static void calculateXrefs_SuperClases_recursive(ICirDataAnalysis cirDataAnalysis, String sSuperClassCustomSignature, ICirClass ccClassToFollow)
 {
     sSuperClassCustomSignature = String.Format("{0}. <- {1}", sSuperClassCustomSignature,
                                                ccClassToFollow.Signature.Replace('.', '_'));
     if (false == cirDataAnalysis.lCirClass_bySuperClass.Contains(sSuperClassCustomSignature))
     {
         cirDataAnalysis.lCirClass_bySuperClass.Add(sSuperClassCustomSignature);
     }
     foreach (CirClass ccIsSuperClassedBy in ccClassToFollow.dIsSuperClassedBy.Values)
     {
         calculateXrefs_SuperClases_recursive(cirDataAnalysis, sSuperClassCustomSignature, ccIsSuperClassedBy);
     }
 }
 public void addIsSuperClassedByToTreeNode_ReCursive(TreeNode tnTargetTreeNode, ICirClass ccCirClass)
 {
     foreach (ICirClass ccSuperClass in ccCirClass.dSuperClasses.Values)
     {
         var tnSuperClass = new TreeNode(ccSuperClass.Signature);
         addIsSuperClassedByToTreeNode_ReCursive(tnSuperClass, ccSuperClass);
         tnTargetTreeNode.Nodes.Add(tnSuperClass);
     }
 }
コード例 #27
0
        public static void viewClassMethods(ascx_FunctionsViewer targetFunctionsViewer , ICirClass targetClass, bool showInheritedMethods, bool ignoreCoreObjectClass)
        {
            if (targetClass != null)
            {
                O2Thread.mtaThread(
                    () =>
                        {
                            targetFunctionsViewer.clearLoadedSignatures();
                            targetFunctionsViewer.setNamespaceDepth(0);
                            var signaturesToShow = new List<string>();
                            if (showInheritedMethods)
                            {
                                List<ICirFunction> inheritedSignatures = CirDataAnalysisUtils.getListOfInheritedMethods(targetClass, ignoreCoreObjectClass);
                                foreach (var inheritedSignature in inheritedSignatures)
                                    signaturesToShow.Add(inheritedSignature.FunctionSignature);
                            }
                            else
                                signaturesToShow.AddRange(targetClass.dFunctions.Keys.ToList());
                            
                            targetFunctionsViewer.showSignatures(signaturesToShow);
                            /*var thread = targetFunctionsViewer.showSignatures(signaturesToShow);
                            if (thread != null)
                            {
                                thread.Join();
                                targetFunctionsViewer.expandNodes();
                            } */                                                     
                        });
            }

        }
コード例 #28
0
 private void showClassAttributes(ICirClass cirClass)
 {
     if (cirClass != null)
     {
         tvClassAttributes.Nodes.Clear();
         foreach (var attribute in cirClass.ClassAttributes)
         {
             var signature = new FilteredSignature(attribute.AttributeClass).sSignature;
             var treeNode = tvClassAttributes.Nodes.Add(signature);
             foreach (var parameter in attribute.Parameters)
                 treeNode.Nodes.Add(parameter.Key);
         }
     }
 }
        public static void viewClassMethods(ascx_FunctionsViewer targetFunctionsViewer, ICirClass targetClass, bool showInheritedMethods, bool ignoreCoreObjectClass)
        {
            if (targetClass != null)
            {
                O2Thread.mtaThread(
                    () =>
                {
                    targetFunctionsViewer.clearLoadedSignatures();
                    targetFunctionsViewer.setNamespaceDepth(0);
                    var signaturesToShow = new List <string>();
                    if (showInheritedMethods)
                    {
                        List <ICirFunction> inheritedSignatures = CirDataAnalysisUtils.getListOfInheritedMethods(targetClass, ignoreCoreObjectClass);
                        foreach (var inheritedSignature in inheritedSignatures)
                        {
                            signaturesToShow.Add(inheritedSignature.FunctionSignature);
                        }
                    }
                    else
                    {
                        signaturesToShow.AddRange(targetClass.dFunctions.Keys.ToList());
                    }

                    targetFunctionsViewer.showSignatures(signaturesToShow);

                    /*var thread = targetFunctionsViewer.showSignatures(signaturesToShow);
                     * if (thread != null)
                     * {
                     *  thread.Join();
                     *  targetFunctionsViewer.expandNodes();
                     * } */
                });
            }
        }
 public static void calculateXrefs_SuperClases_recursive(ICirDataAnalysis cirDataAnalysis, String sSuperClassCustomSignature, ICirClass ccClassToFollow)
 {
     sSuperClassCustomSignature = String.Format("{0}. <- {1}", sSuperClassCustomSignature,
                                                ccClassToFollow.Signature.Replace('.', '_'));
     if (false == cirDataAnalysis.lCirClass_bySuperClass.Contains(sSuperClassCustomSignature))
         cirDataAnalysis.lCirClass_bySuperClass.Add(sSuperClassCustomSignature);
     foreach (CirClass ccIsSuperClassedBy in ccClassToFollow.dIsSuperClassedBy.Values)
         calculateXrefs_SuperClases_recursive(cirDataAnalysis, sSuperClassCustomSignature, ccIsSuperClassedBy);
 }
コード例 #31
0
 public static List <ICirFunction> functions(this ICirClass cirClass)
 {
     return(cirClass.dFunctions.Values.ToList());
 }
コード例 #32
0
 public static List <String> functionNames(this ICirClass cirClass)
 {
     return(cirClass.dFunctions.Keys.ToList());
 }
コード例 #33
0
 public void mapClass(ICirClass cirClass, ICirData _cirData)
 {
     mapClass(cirClass, _cirData, true);
 }
コード例 #34
0
        public bool addBindableFieldsIntoTreeView_Recursive(TreeNodeCollection tncTreeNodes, ICirClass targetCirClass, bool bHideGetAndSetStrings)
        {
            if (cirClassMapped.Contains(targetCirClass))
            {
                //tncTreeNodes.Add(targetCirClass.Signature + " : RECURSIVE CALL");
                return(true);
            }


            if (targetCirClass.Signature != "java.util.List")
            {
                cirClassMapped.Add(targetCirClass);
            }

            //var classSourceCodeLine = O2.Core.CIR.CirUtils.ViewHelpers.GetMappedLineNumber(targetCirClass.Name, targetCirClass.File, targetCirClass.FileLine, false, true);
            //if (classSourceCodeLine > 0)
            //{
            //    var classSourceCodetext = Files.getLineFromSourceCode(targetCirClass.File, (uint)classSourceCodeLine);
            //}
            // check for max depth
            var nodeCountToStopRecursion = 200;

            if (tvBindableFields.GetNodeCount(true) > nodeCountToStopRecursion)
            //if (tncTreeNodes.Count > 0 && O2Forms.getStringListWithAllParentNodesName(tncTreeNodes[0]).Count > maxDepth)
            {
                tncTreeNodes.Add("***** MAX node count (for recursive Search) reached: " + nodeCountToStopRecursion);
                return(false);
            }

            if (numberOfItemsProcessed++ > 20)
            //if (tncTreeNodes.Count > 0 && O2Forms.getStringListWithAllParentNodesName(tncTreeNodes[0]).Count > maxDepth)
            {
                tncTreeNodes.Add("***** MAX numberOfItemsProcessed count (for recursive Search) reached: " + nodeCountToStopRecursion);
                numberOfItemsProcessed = 0;
                return(false);
            }



            //String sFixedClassToFind = sClassToFind[0].ToString().ToUpper() + sClassToFind.Substring(1);
            //foreach (ICirClass ccCirClass in fadCirData.dClasses_bySignature.Values)
            //{
            //   if (ccCirClass.Name == sFixedClassToFind)
            {
                var tnClass = new TreeNode(targetCirClass.Signature);

                foreach (ICirFunction cfCirFunction in O2.Core.CIR.CirUtils.CirDataAnalysisUtils.getListOfInheritedMethods(targetCirClass, true))
                {
                    String sFunctionName = cfCirFunction.FunctionName; //new FilteredSignature(cfCirFunction.FunctionSignature).sFunctionName;
                    switch (sFunctionName.Substring(0, 3))
                    {
                    case "get":
                        if (cfCirFunction.FunctionParameters.Count == 0 && cfCirFunction.FunctionNameAndParameters.IndexOf("()") > -1)            // spring will only invoke this is the getter has no parameters
                        {
                            var    tnSubObject         = new TreeNode(sFunctionName);
                            String sFixedSubObjectName = sFunctionName.Replace("get", "");
                            if (bHideGetAndSetStrings)
                            {
                                tnSubObject.Text = sFixedSubObjectName;
                            }

                            //tnSubObject = tnClass;
                            var returnType = cfCirFunction.ReturnType.Replace("&", "").Replace("[]", "");
                            if (returnType != "char" && returnType != "char[]" && returnType != "void" && returnType != "long" && returnType != "int" && returnType != "bool" &&
                                returnType != "wchar_t" && returnType != "double" && returnType != "float" && returnType != "short" && returnType != "java.math.BigDecimal" &&
                                returnType != "java.lang.String" && returnType != "java.util.Date" && returnType != "java.lang.Object" /* && returnType != "java.util.List"*/ &&
                                returnType != "java.lang.Integer" && returnType != "java.lang.Long" && returnType != "java.lang.Double" &&
                                returnType != "org.joda.time.LocalTime" && returnType != "org.joda.time.LocalDate" && returnType != "org.joda.time.LocalDateTime")
                            {
                                if (cirData.dClasses_bySignature.ContainsKey(returnType))
                                {
                                    switch (returnType)
                                    {
                                    case "java.lang.Class":                     // special class for if we get a Class back (need to try exploitability)

                                        tnSubObject.Text += "   - returns  java.lang.Class ";
                                        if (bHideGetAndSetStrings)
                                        {
                                            tncTreeNodes.Add(tnSubObject);
                                        }
                                        else
                                        {
                                            tnClass.Nodes.Add(tnSubObject);
                                        }
                                        break;

                                    case "java.util.List":
                                    case "java.util.Set":
                                        // lets see if the source code as a clue about which class this list maps to:
                                        ICirClass resolvedClass = null;
                                        try
                                        {
                                            if (cfCirFunction.File != null && cfCirFunction.FileLine != null)
                                            {
                                                var sourceCodeLine         = O2.DotNetWrappers.Windows.Files.getLineFromSourceCode(cfCirFunction.File, UInt32.Parse(cfCirFunction.FileLine), false);
                                                var specialTagTextStart    = "O2Helper:MVCAutoBindListObject:";
                                                var indexOfSpecialTagStart = sourceCodeLine.IndexOf(specialTagTextStart);
                                                if (indexOfSpecialTagStart > -1)
                                                {
                                                    indexOfSpecialTagStart += specialTagTextStart.Length;
                                                    int indexOfSpecialTagEnd = sourceCodeLine.LastIndexOf("*/");
                                                    if (indexOfSpecialTagEnd > indexOfSpecialTagStart)
                                                    {
                                                        var specialTag = sourceCodeLine.Substring(indexOfSpecialTagStart, indexOfSpecialTagEnd - indexOfSpecialTagStart);
                                                        if (cirData.dClasses_bySignature.ContainsKey(specialTag))
                                                        {
                                                            resolvedClass = cirData.dClasses_bySignature[specialTag];
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            DI.log.error("in addBindableFieldsIntoTreeView_Recursive, while mapping java.util.List:", ex.Message);
                                        }
                                        if (resolvedClass == null)
                                        {
                                            tnSubObject.Text += " -- JAVA.UTIL.LIST (you must add a Tag like /*[O2Helper:MVCAutoBindListObject:*/ to the source code so that we can calculate the corrent object binding";
                                            tncTreeNodes.Add(tnSubObject);
                                        }
                                        else
                                        {
                                            //   tnSubObject.Text += "GOT MAPPING";
                                            //   tncTreeNodes.Add(tnSubObject);
                                            cirClassMapped.Remove(targetCirClass);          // take it out since we haven't really added it
                                            addBindableFieldsIntoTreeView_Recursive(tnSubObject.Nodes, resolvedClass, bHideGetAndSetStrings);
                                            //cirClassMapped.Add(targetCirClass);     // and add it here
                                            if (bHideGetAndSetStrings)
                                            {
                                                tncTreeNodes.Add(tnSubObject);
                                            }
                                            else
                                            {
                                                tnClass.Nodes.Add(tnSubObject);
                                            }
                                        }
                                        break;

                                    default:
                                        //var targetTreeNodeCollection = (bHideGetAndSetStrings) ? tncTreeNodes : tnClass.Nodes;
                                        var repeatedClass = addBindableFieldsIntoTreeView_Recursive(tnSubObject.Nodes, cirData.dClasses_bySignature[returnType], bHideGetAndSetStrings);
                                        if (repeatedClass)
                                        {
                                            tnSubObject.Text += "    - repeated class': " + returnType;
                                        }

                                        if (repeatedClass || tnSubObject.Nodes.Count > 0)
                                        {
                                            if (bHideGetAndSetStrings)
                                            {
                                                tncTreeNodes.Add(tnSubObject);
                                            }
                                            else
                                            {
                                                tnClass.Nodes.Add(tnSubObject);
                                            }
                                        }
                                        break;
                                    }
                                }
                                else
                                if (returnType != "")
                                {
                                    DI.log.error("On function {0} Could not find return type {1}", cfCirFunction.FunctionSignature, returnType);
                                }
                            }
                        }
                        break;

                    case "set":
                        //String sSetNodeText = new FilteredSignature(cfCirFunction.FunctionSignature).sFunctionName;
                        String sSetNodeText = cfCirFunction.FunctionNameAndParameters;
                        if (bHideGetAndSetStrings)
                        {
                            sSetNodeText = sSetNodeText.Substring(3);     //.Replace("set", "");
                        }
                        var newNode = new TreeNode(sSetNodeText);
                        newNode.ForeColor = System.Drawing.Color.Red;

                        if (bHideGetAndSetStrings)
                        {
                            tncTreeNodes.Add(newNode);
                        }
                        else
                        {
                            tnClass.Nodes.Add(newNode);
                        }

                        break;

                    default:
                        break;
                    }
                }
                if (tnClass.Nodes.Count > 0)
                {
                    tncTreeNodes.Add(tnClass);
                }
                //}
                //    String sClassName =
            }
            return(false);
        }
コード例 #35
0
 public void mapClass(ICirClass cirClass, ICirData _cirData, bool clearPreviousList)
 {
     cirData      = _cirData;
     cirRootClass = cirClass;
     mapCurrentClass(clearPreviousList);
 }
コード例 #36
0
 public void showClass(ICirClass cirClass, ICirData _cirData)
 {
     mapClass(cirClass, _cirData);
 }
コード例 #37
0
            public static bool ResolveInterfacesOnTreeView_recursive(TreeNode tnStartNode, ICirData cdCirData,
                                                                     Dictionary <String, O2TraceBlock_OunceV6> dO2TraceBlock,
                                                                     Dictionary <String, O2TraceBlock_OunceV6> dRawData,
                                                                     //TreeView tvRawData_,
                                                                     String sHardCodedInterfaceKeywork)
            {
                var stStackTrace = new StackTrace();

                if (stStackTrace.FrameCount > 50)
                {
                    String sMsg =
                        String.Format(
                            "on ResolveInterfacesOnTreeView_recursive, max StackTrace reached, aborting this leaf:{0}",
                            tnStartNode.Text);
                    DI.log.error(sMsg);
                    return(false);
                }
                if (tnStartNode != null)
                {
                    foreach (TreeNode tnNode in tnStartNode.Nodes)
                    {
                        if (tnNode.Text.IndexOf(sHardCodedInterfaceKeywork) > -1)
                        {
                            if (tnNode.Tag != null)
                            {
                                var    fviFindingViewItem = (FindingViewItem)tnNode.Tag;
                                String sSink = AnalysisUtils.getSink(fviFindingViewItem.fFinding,
                                                                     fviFindingViewItem.oadO2AssessmentDataOunceV6);
                                if (cdCirData.dFunctions_bySignature.ContainsKey(sSink))
                                {
                                    ICirFunction cfCirFunction = cdCirData.dFunctions_bySignature[sSink];
                                    ICirClass    ccCirClass    = cfCirFunction.ParentClass;
                                    foreach (ICirClass ccIsSuperClassedBy in ccCirClass.dIsSuperClassedBy.Values)
                                    {
                                        String sMappedMethodName =
                                            cfCirFunction.FunctionSignature.Replace(ccCirClass.Signature,
                                                                                    ccIsSuperClassedBy.Signature);
                                        List <O2TraceBlock_OunceV6> lotdMatches =
                                            analyzer.getO2TraceBlocksThatMatchSignature(sMappedMethodName, dO2TraceBlock);
                                        foreach (O2TraceBlock_OunceV6 otbO2TraceBlock in lotdMatches)
                                        {
                                            TreeNode tnNewNode_forImplementation =
                                                O2Forms.newTreeNode(otbO2TraceBlock.sUniqueName,
                                                                    otbO2TraceBlock.sUniqueName, 0, null);
                                            tnNode.ForeColor = Color.CadetBlue;
                                            tnNewNode_forImplementation.ForeColor = Color.DarkBlue;
                                            foreach (
                                                AssessmentAssessmentFileFinding fFinding in otbO2TraceBlock.dSinks.Keys)
                                            {
                                                var fviFindingViewItem_ForSink = new FindingViewItem(fFinding,
                                                                                                     fFinding.vuln_name ?? OzasmtUtils_OunceV6.
                                                                                                     getStringIndexValue
                                                                                                         (UInt32.Parse
                                                                                                             (fFinding
                                                                                                             .
                                                                                                             vuln_name_id),
                                                                                                         otbO2TraceBlock.dSinks[fFinding]),
                                                                                                     null,
                                                                                                     otbO2TraceBlock.
                                                                                                     dSinks[fFinding
                                                                                                     ]);
                                                String sUniqueName_ForSink =
                                                    analyzer.getUniqueSignature(fviFindingViewItem_ForSink.fFinding,
                                                                                TraceType.Known_Sink,
                                                                                fviFindingViewItem_ForSink.
                                                                                oadO2AssessmentDataOunceV6, true);
                                                TreeNode tnImplementation_Sink = O2Forms.newTreeNode(
                                                    sUniqueName_ForSink, sUniqueName_ForSink, 0,
                                                    fviFindingViewItem_ForSink);
                                                tnNewNode_forImplementation.Nodes.Add(tnImplementation_Sink);
                                                if (tnImplementation_Sink.Text != "")
                                                {
                                                    if (false ==
                                                        analyzer.addCompatibleTracesToNode_recursive(
                                                            tnImplementation_Sink, fviFindingViewItem_ForSink,
                                                            dRawData[tnImplementation_Sink.Text], "Sinks", dRawData))
                                                    {
//                                                            (O2TraceBlock_OunceV6)
//                                                            tvRawData.Nodes[tnImplementation_Sink.Text].Tag, "Sinks",
//                                                          tvRawData))
                                                        return(false);
                                                    }
                                                }
                                                // need to see any posible side effects of this (false check was not there on small projects)
                                            }
                                            tnNode.Nodes.Add(tnNewNode_forImplementation);
                                        }
                                    }
                                }
                            }
                        }
                        foreach (TreeNode tnChildNode in tnNode.Nodes)
                        {
                            if (false ==
                                ResolveInterfacesOnTreeView_recursive(tnChildNode, cdCirData, dO2TraceBlock, dRawData, //tvRawData,
                                                                      sHardCodedInterfaceKeywork))
                            {
                                return(false);
                            }
                        }
                    }
                }
                return(true);
            }
コード例 #38
0
 public static void raiseSourceCodeReferenceEvent(bool raiseEvent, ICirClass cirClass, bool remapLineNumber)
 {
     if (raiseEvent)
         if (cirClass.File != null && cirClass.FileLine != null)
         {
             int mappedLineNumber = GetMappedLineNumber(cirClass.Name, cirClass.File, cirClass.FileLine, true, remapLineNumber);
             O2Messages.fileOrFolderSelected(cirClass.File, mappedLineNumber);
         }
 }
 public static void calculateListofMethodsCalledByClass_Recursive(
     ICirClass ccClass, List<ICirClass> lccTargetCompilationClasses, List<String> lsFunctionsCalled,
     String sResultsFilter/*, Dictionary<String, String> dFunctionsNames*/, ICirData fcdCirData)
 {
     if (ccClass != null)
         foreach (ICirFunction cfCirFunction in ccClass.dFunctions.Values)
             foreach (ICirFunction cirFunctionCalled in cfCirFunction.FunctionsCalledUniqueList)
             {
                 String sName = cirFunctionCalled.FunctionSignature;
                 //    if (sName.IndexOf("()") == -1)                          // don't add functions that receive no parameters
                 if (sResultsFilter == "" || sName.IndexOf(sResultsFilter) > -1)
                 {
                     if (false == lsFunctionsCalled.Contains(cirFunctionCalled.FunctionSignature))
                     {
                         lsFunctionsCalled.Add(cirFunctionCalled.FunctionSignature);
                         ICirClass ccCalledClass = getCirClassObjectFromFunctionSignature(cirFunctionCalled.FunctionSignature,fcdCirData);
                         if (false == lccTargetCompilationClasses.Contains(ccCalledClass))
                             lccTargetCompilationClasses.Add(ccCalledClass);
                         calculateListofMethodsCalledByClass_Recursive(ccCalledClass, lccTargetCompilationClasses,
                                                                       lsFunctionsCalled, sResultsFilter,
                                                                       /*dFunctionsNames,*/ fcdCirData);
                         //     getCirClassObjectFromFunctionDef(sFunctionCalled,dFunctionsNames, fcdCirData);
                     }
                 }
             }
 }
コード例 #40
0
 public static TreeNode addCirClassToTreeNodeCollection(ICirClass cirClass, string treeNodeNamePrefix, TreeNodeCollection treeNodeCollection, bool addDummyChildNode)
 {
     if (cirClass == null)
         return null;
     //if (cirFunction.FunctionSignature != "")
     //{
     var filteredSignature = new FilteredSignature(cirClass.Signature);
     var treeNodeName = String.Format(" => {0}", filteredSignature.sSignature);
     var newTreeNode = O2Forms.newTreeNode(treeNodeCollection, treeNodeName, cirClass.Signature, 0,
                                               cirClass);
         if (addDummyChildNode)
             newTreeNode.Nodes.Add(""); // Dummy node so that we have the plus sign
         return newTreeNode;
     //}
 }
コード例 #41
0
        /*    private void onSelectedItemTreeViewBeforeExpand(TreeNode selectedTreeNode)
        {
            //return;
            if (selectedTreeNode != null && selectedTreeNode.Tag is ICirFunction)
            {
                selectedTreeNode.Nodes.Clear();

                /*     var filteredSignature = (FilteredSignature)selectedTreeNode.Tag;
                     var signature = filteredSignature.sOriginalSignature;
                     if (cirDataAnalysis.dCirFunction_bySignature.ContainsKey(signature))
                     {* /
                var cirFunction = (ICirFunction)selectedTreeNode.Tag;
                // makesCallToNode
                //var makesCallToNode = new TreeNode("Makes calls to:");
                foreach (var makesCallsTo in cirFunction.FunctionsCalledUniqueList)
                    addCirFunctionToTreeNodeCollection(makesCallsTo, "=>", selectedTreeNode.Nodes);
                // isCalledByNode

                //var isCalledByNode = new TreeNode("Is called by:");
                foreach (var isCalledBy in cirFunction.FunctionIsCalledBy)
                    addCirFunctionToTreeNodeCollection(isCalledBy, "<=", selectedTreeNode.Nodes);
                /*  }
                  else
                      selectedTreeNode.Nodes.Add("Could not find the signature:" + signature);*/
                /*     var functionNode = new TreeNode("Function: " + cirFunction.FunctionName);

                     // makesCallToNode
                     var makesCallToNode = new TreeNode("Makes calls to:");
                     foreach (var makesCallsTo in cirFunction.FunctionsCalledUniqueList)
                         makesCallToNode.Nodes.Add(makesCallsTo.FunctionName);
                     // isCalledByNode
                     var isCalledByNode = new TreeNode("Is called by:");
                     foreach (var isCalledBy in cirFunction.FunctionIsCalledBy)
                         isCalledByNode.Nodes.Add(isCalledBy.FunctionName);

                     functionNode.Nodes.Add(makesCallToNode);
                     functionNode.Nodes.Add(isCalledByNode);
                     tvSelectedItemInfo.Nodes.Add(functionNode);
                     ;* /
            }
        }

        */


        public void viewCirClass(ICirClass cirClass)
        {
            if (cirClass != null)
                this.invokeOnThread(
                    () =>
                    {
                        showClassAttributes(cirClass);
                        laFunctionViewed.Text = cirClass.Signature;
                        rootCirFunction = null;
                        currentCirClass = cirClass;
                        
                        tvFunctionIsCalledBy.Nodes.Clear();                        
                        tvFunctionMakesCallsTo.Nodes.Clear();                        
                        tvFunctionInfo.Nodes.Clear();

                        //tvClassSuperClasses
                        tvClassSuperClasses.Nodes.Clear();
                        ViewHelpers.addCirClassToTreeNodeCollection(cirClass, "", tvClassSuperClasses.Nodes,
                                                                       cirClass.dSuperClasses.Count > 0);
                        O2Forms.expandNodes(tvClassSuperClasses);

                        //tvClassIsSuperClassedBy
                        tvClassIsSuperClassedBy.Nodes.Clear();
                        ViewHelpers.addCirClassToTreeNodeCollection(cirClass, "", tvClassIsSuperClassedBy.Nodes,
                                                                       cirClass.dIsSuperClassedBy.Count > 0);
                        O2Forms.expandNodes(tvClassIsSuperClassedBy);

                        viewClassMethods(functionViewerForClassMethods, cirClass, cbViewInheritedMethods.Checked, cbIgnoreCoreObjectClass.Checked);

                        cbCirFunction_IsTainted.Checked = false;


                    });
        }
コード例 #42
0
 public void showClass(ICirClass cirClass, ICirData _cirData)
 {
     mapClass(cirClass, _cirData);
 }
 private static void addClass(ICirDataAnalysis cirDataAnalysis, ICirClass ccCirClass)
 {
     if (cirDataAnalysis.dCirClass_bySignature.ContainsKey(ccCirClass.Signature))
     {
         var mainRefCirClass = cirDataAnalysis.dCirClass_bySignature[ccCirClass.Signature];
         if (mainRefCirClass != ccCirClass)          // if they are diferent we need to sync the superclasses dictionary
         {
             foreach (var superclass in ccCirClass.dSuperClasses.Keys)
                 if (false == mainRefCirClass.dSuperClasses.ContainsKey(superclass))
                     mainRefCirClass.dSuperClasses.Add(superclass, ccCirClass.dSuperClasses[superclass]);
         }
     }
     else
     {
     }
     foreach (ICirFunction cfCirFunction in ccCirClass.dFunctions.Values)
     //                if (cfCirFunction.HasControlFlowGraph)
     {
         if (false == cirDataAnalysis.dCirFunction.ContainsKey(cfCirFunction))
             cirDataAnalysis.dCirFunction.Add(cfCirFunction, ccCirClass);                
         // we need this cross check with ccCirClass since we will it to resolve cfCirFunction data
         if (false ==
             cirDataAnalysis.dCirFunction_bySignature.ContainsKey(cfCirFunction.FunctionSignature))
             addFunction(cirDataAnalysis, cfCirFunction);
         else
         {
             var functionHost =
                 cirDataAnalysis.dCirFunction_bySignature[cfCirFunction.FunctionSignature];
             var functionToMerge = cfCirFunction;
             mergeFunctions(cirDataAnalysis, functionHost, functionToMerge);
         }
     }
 }
コード例 #44
0
 public void clearLoadedData()
 {
     this.invokeOnThread(() =>
                             {
                                 cirData = null;
                                 cirRootClass = null;
                                 cirClassMapped = new List<ICirClass>();
                                 tvBindableFields.Nodes.Clear();
                             });
 }
コード例 #45
0
ファイル: CirDataUtils.cs プロジェクト: pusp/o2platform
        public static ICirFunction addFunction(ICirData cirData, Object oFunction, ICirClass ccCirClass)
        {
            ICirFunction cfCirFunction = null;
            try
            {
                String sSignature = DI.reflection.getProperty("UniqueID", oFunction).ToString();
                String sSymbolRef = DI.reflection.getProperty("SymbolRef", oFunction).ToString();

                if (cirData.dFunctions_bySignature.ContainsKey(sSignature))
                    cfCirFunction = cirData.dFunctions_bySignature[sSignature];

                if (cfCirFunction == null)
                {
                    // create method object
                    cfCirFunction = new CirFunction { SymbolDef = sSymbolRef };
                    // ccCirClass.dFunctions.Add(sSymbolRef, cfCirFunction);
                    cirData.dFunctions_bySignature.Add(sSignature, cfCirFunction);
                    //cirData.dTemp_Functions_bySymbolDef.Add(sSymbolRef, cfCirFunction);
                    //addSymbol(cirData,sSymbolRef, sSignature);                    
                    

                    /*if (cirData.dFunctions_bySymbolDef.ContainsKey(sSymbolRef))
                    {
                        cfCirFunction.FunctionParameters = cirData.dFunctions_bySymbolDef[sSymbolRef].FunctionParameters;
                        cfCirFunction.ReturnType = cirData.dFunctions_bySymbolDef[sSymbolRef].ReturnType;       // _TODO: _BUG: I think there is a bug here where the ReturnType is not correctly set for ALL funtions
                    }*/
                }
                cfCirFunction.ParentClass = ccCirClass;

                if (cfCirFunction.FunctionSignature != "" && cfCirFunction.FunctionSignature != sSignature) // error
                {
                    DI.log.error("In addFunction cfCirFunction.FunctionSignature != FunctionSignature  : {0} {1} != {2}",
                                 sSymbolRef, cfCirFunction.FunctionSignature, sSignature);
                    return cfCirFunction;
                }

                //if (ccCirClass.dFunctions.ContainsKey(sSymbolRef))   // means we already processed this method
                //    return cfCirFunction;


                //cmNewcirFunction.FunctionSignature = cmfMemberFunction.UniqueID;                    
                // there are generic for both Static and Member Functions so we can use reflection to get them
                cfCirFunction.FunctionSignature = sSignature;
                //   addSymbol(sSymbolRef, FunctionSignature);          // this will make sure the dSymbol href table is correctly populated
                //cfCirFunction.sSymbolRef = sSymbolRef;
                // add Variables
                processFunctionVariables(cirData,cfCirFunction, oFunction);

                // process ControlFlowGraphs
                if (processControlFlowGraph(cirData,cfCirFunction, oFunction))
                    if (null != ccCirClass)
                        ccCirClass.bClassHasMethodsWithControlFlowGraphs = true;
                // keep track if this class has methods with ControlFlowGraphs                    

                // add method to dClasses   
                if (null != ccCirClass && false == ccCirClass.dFunctions.ContainsKey(sSignature))
                {
                    ccCirClass.dFunctions.Add(sSignature, cfCirFunction);
                }
            }
            catch (Exception ex)
            {
                DI.log.error("in addFunction: {0}", ex.Message);
            }
            return cfCirFunction;
        }
コード例 #46
0
        public bool addBindableFieldsIntoTreeView_Recursive(TreeNodeCollection tncTreeNodes, ICirClass targetCirClass, bool bHideGetAndSetStrings)
        {
            if (cirClassMapped.Contains(targetCirClass))
            {
                //tncTreeNodes.Add(targetCirClass.Signature + " : RECURSIVE CALL");
                return true;
            }


            if (targetCirClass.Signature != "java.util.List")
                cirClassMapped.Add(targetCirClass);

            //var classSourceCodeLine = O2.Core.CIR.CirUtils.ViewHelpers.GetMappedLineNumber(targetCirClass.Name, targetCirClass.File, targetCirClass.FileLine, false, true);
            //if (classSourceCodeLine > 0)
            //{
            //    var classSourceCodetext = Files.getLineFromSourceCode(targetCirClass.File, (uint)classSourceCodeLine);
            //}            
            // check for max depth
            var nodeCountToStopRecursion = 200;
            if (tvBindableFields.GetNodeCount(true) > nodeCountToStopRecursion)
            //if (tncTreeNodes.Count > 0 && O2Forms.getStringListWithAllParentNodesName(tncTreeNodes[0]).Count > maxDepth)
            {
                tncTreeNodes.Add("***** MAX node count (for recursive Search) reached: " + nodeCountToStopRecursion);
                return false;
            }

            if (numberOfItemsProcessed++ > 20)
            //if (tncTreeNodes.Count > 0 && O2Forms.getStringListWithAllParentNodesName(tncTreeNodes[0]).Count > maxDepth)
            {
                tncTreeNodes.Add("***** MAX numberOfItemsProcessed count (for recursive Search) reached: " + nodeCountToStopRecursion);
                numberOfItemsProcessed = 0;
                return false;
            }



            //String sFixedClassToFind = sClassToFind[0].ToString().ToUpper() + sClassToFind.Substring(1);
            //foreach (ICirClass ccCirClass in fadCirData.dClasses_bySignature.Values)
            //{
            //   if (ccCirClass.Name == sFixedClassToFind)
            {
                var tnClass = new TreeNode(targetCirClass.Signature);

                foreach (ICirFunction cfCirFunction in O2.Core.CIR.CirUtils.CirDataAnalysisUtils.getListOfInheritedMethods(targetCirClass, true))
                {
                    String sFunctionName = cfCirFunction.FunctionName; //new FilteredSignature(cfCirFunction.FunctionSignature).sFunctionName;
                    switch (sFunctionName.Substring(0, 3))
                    {
                        case "get":
                            if (cfCirFunction.FunctionParameters.Count == 0 && cfCirFunction.FunctionNameAndParameters.IndexOf("()") > -1)        // spring will only invoke this is the getter has no parameters
                            {
                                var tnSubObject = new TreeNode(sFunctionName);
                                String sFixedSubObjectName = sFunctionName.Replace("get", "");
                                if (bHideGetAndSetStrings)
                                    tnSubObject.Text = sFixedSubObjectName;

                                //tnSubObject = tnClass;
                                var returnType = cfCirFunction.ReturnType.Replace("&", "").Replace("[]", "");
                                if (returnType != "char" && returnType != "char[]" && returnType != "void" && returnType != "long" && returnType != "int" && returnType != "bool" &&
                                     returnType != "wchar_t" && returnType != "double" && returnType != "float" && returnType != "short" && returnType != "java.math.BigDecimal" &&
                                    returnType != "java.lang.String" && returnType != "java.util.Date" && returnType != "java.lang.Object" /* && returnType != "java.util.List"*/ &&
                                    returnType != "java.lang.Integer" && returnType != "java.lang.Long" && returnType != "java.lang.Double" &&
                                    returnType != "org.joda.time.LocalTime" && returnType != "org.joda.time.LocalDate" && returnType != "org.joda.time.LocalDateTime")
                                {
                                    if (cirData.dClasses_bySignature.ContainsKey(returnType))
                                    {
                                        switch (returnType)
                                        {
                                            case "java.lang.Class":             // special class for if we get a Class back (need to try exploitability)

                                                tnSubObject.Text += "   - returns  java.lang.Class ";
                                                if (bHideGetAndSetStrings)
                                                    tncTreeNodes.Add(tnSubObject);
                                                else
                                                    tnClass.Nodes.Add(tnSubObject);
                                                break;
                                            case "java.util.List":
                                            case "java.util.Set":
                                                // lets see if the source code as a clue about which class this list maps to:
                                                ICirClass resolvedClass = null;
                                                try
                                                {
                                                    if (cfCirFunction.File != null && cfCirFunction.FileLine != null)
                                                    {
                                                        var sourceCodeLine = O2.DotNetWrappers.Windows.Files.getLineFromSourceCode(cfCirFunction.File, UInt32.Parse(cfCirFunction.FileLine),false);
                                                        var specialTagTextStart = "O2Helper:MVCAutoBindListObject:";
                                                        var indexOfSpecialTagStart = sourceCodeLine.IndexOf(specialTagTextStart);
                                                        if (indexOfSpecialTagStart > -1)
                                                        {
                                                            indexOfSpecialTagStart += specialTagTextStart.Length;
                                                            int indexOfSpecialTagEnd = sourceCodeLine.LastIndexOf("*/");
                                                            if (indexOfSpecialTagEnd > indexOfSpecialTagStart)
                                                            {
                                                                var specialTag = sourceCodeLine.Substring(indexOfSpecialTagStart, indexOfSpecialTagEnd - indexOfSpecialTagStart);
                                                                if (cirData.dClasses_bySignature.ContainsKey(specialTag))
                                                                {
                                                                    resolvedClass = cirData.dClasses_bySignature[specialTag];
                                                                }
                                                            }
                                                        }

                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    DI.log.error("in addBindableFieldsIntoTreeView_Recursive, while mapping java.util.List:", ex.Message);
                                                }
                                                if (resolvedClass == null)
                                                {
                                                    tnSubObject.Text += " -- JAVA.UTIL.LIST (you must add a Tag like /*[O2Helper:MVCAutoBindListObject:*/ to the source code so that we can calculate the corrent object binding";
                                                    tncTreeNodes.Add(tnSubObject);
                                                }
                                                else
                                                {
                                                    //   tnSubObject.Text += "GOT MAPPING";
                                                    //   tncTreeNodes.Add(tnSubObject);                                                        
                                                    cirClassMapped.Remove(targetCirClass);  // take it out since we haven't really added it
                                                    addBindableFieldsIntoTreeView_Recursive(tnSubObject.Nodes, resolvedClass, bHideGetAndSetStrings);
                                                    //cirClassMapped.Add(targetCirClass);     // and add it here
                                                    if (bHideGetAndSetStrings)
                                                        tncTreeNodes.Add(tnSubObject);
                                                    else
                                                        tnClass.Nodes.Add(tnSubObject);
                                                }
                                                break;
                                            default:
                                                //var targetTreeNodeCollection = (bHideGetAndSetStrings) ? tncTreeNodes : tnClass.Nodes;
                                                var repeatedClass = addBindableFieldsIntoTreeView_Recursive(tnSubObject.Nodes, cirData.dClasses_bySignature[returnType], bHideGetAndSetStrings);
                                                if (repeatedClass)
                                                    tnSubObject.Text += "    - repeated class': " + returnType;

                                                if (repeatedClass || tnSubObject.Nodes.Count > 0)
                                                    if (bHideGetAndSetStrings)
                                                        tncTreeNodes.Add(tnSubObject);
                                                    else
                                                        tnClass.Nodes.Add(tnSubObject);
                                                break;
                                        }
                                    }
                                    else
                                        if (returnType != "")
                                            DI.log.error("On function {0} Could not find return type {1}", cfCirFunction.FunctionSignature, returnType);
                                }
                            }
                            break;
                        case "set":
                            //String sSetNodeText = new FilteredSignature(cfCirFunction.FunctionSignature).sFunctionName;
                            String sSetNodeText = cfCirFunction.FunctionNameAndParameters;
                            if (bHideGetAndSetStrings)
                                sSetNodeText = sSetNodeText.Substring(3); //.Replace("set", "");                                
                            var newNode = new TreeNode(sSetNodeText);
                            newNode.ForeColor = System.Drawing.Color.Red;

                            if (bHideGetAndSetStrings)
                                tncTreeNodes.Add(newNode);
                            else
                                tnClass.Nodes.Add(newNode);

                            break;
                        default:
                            break;
                    }
                }
                if (tnClass.Nodes.Count > 0)
                    tncTreeNodes.Add(tnClass);
                //}
                //    String sClassName = 
            }
            return false;
        }
コード例 #47
0
ファイル: CirDataUtils.cs プロジェクト: pusp/o2platform
 public static void mapSuperClasses(ICirData cirData, CommonIRDumpClassSymbols csClassSymbols, ICirClass ccNewCirClass)
 {
     if (csClassSymbols.Superclasses != null)
         foreach (CommonIRDumpClassSymbolsSuperclass csSuperClass in csClassSymbols.Superclasses)
         {
             // add SuperClasses to current Class
             ccNewCirClass.dSuperClasses.Add(csSuperClass.SymbolRef,
                                             getClass(cirData,csSuperClass.SymbolRef, csSuperClass.ClassType));
             // add XRef (i.e. add current class to the SuperClass d...)
             ICirClass ccCirClass = getClass(cirData,csSuperClass.SymbolRef, csSuperClass.ClassType);
             ccCirClass.dIsSuperClassedBy.Add(ccNewCirClass.SymbolDef, ccNewCirClass);
         }
 }
        // need to check of other class values
        public static void mergeClasses(ICirDataAnalysis cirDataAnalysis, ICirClass classHost, ICirClass classToMerge)
        {
            foreach (var propertyInfo in DI.reflection.getProperties(typeof(ICirClass)))
                if (DI.reflection.getProperty(propertyInfo.Name, classHost) == null && DI.reflection.getProperty(propertyInfo.Name, classToMerge) != null)
                    DI.reflection.setProperty(propertyInfo.Name, classHost,
                                              DI.reflection.getProperty(propertyInfo.Name, classToMerge));

            addClass(cirDataAnalysis, classToMerge);
        }
コード例 #49
0
ファイル: CirDataUtils.cs プロジェクト: pusp/o2platform
 internal static void addSuperClassMapping(ICirData cirData,ICirClass cirClass, string superClassToMap)
 {
     cirClass.dSuperClasses.Add(superClassToMap, cirData.getClass(superClassToMap));
     var superClassedClass = cirData.getClass(superClassToMap);
     superClassedClass.dIsSuperClassedBy.Add(cirClass.Signature, cirClass);
     /*foreach (ICirClass cirClass in cirDataAnalysis.dCirClass_bySignature.Values.ToList())
         foreach (string superClassSignature in cirClass.dSuperClasses.Keys.ToList())
             if (cirClass.dSuperClasses[superClassSignature] == null)
                 if (cirDataAnalysis.dCirClass_bySignature.ContainsKey(superClassSignature))
                     cirClass.dSuperClasses[superClassSignature] = cirDataAnalysis.dCirClass_bySignature[superClassSignature];
                 else
                 {
                     cirDataAnalysis.dCirClass_bySignature.Add(superClassSignature, new CirClass(superClassSignature));
                     cirClass.dSuperClasses[superClassSignature] = cirDataAnalysis.dCirClass_bySignature[superClassSignature];
                 }*/
 }
 public static List<ICirFunction> getListOfInheritedMethods(ICirClass targetClass, bool ignoreCoreObjectClass)
 {
     var inheritedMethods = new List<ICirFunction>();
     if (targetClass!=null) // && targetClass.Signature != "java.lang.Object")
     {
         foreach (var cirFunction in targetClass.dFunctions.Values)
             inheritedMethods.Add(cirFunction);
         foreach(var cirClass in targetClass.dSuperClasses.Values)
             inheritedMethods.AddRange(getListOfInheritedMethods(cirClass, ignoreCoreObjectClass));
     }
     return inheritedMethods;
 }
コード例 #51
0
 public void mapClass(ICirClass cirClass, ICirData _cirData)
 {
     mapClass(cirClass, _cirData, true);
 }