/// <summary>
        /// this will return the current CirFunction object for the signature provided or create a new CirFunction
        /// object and return it
        /// </summary>
        /// <param name="cirData"></param>
        /// <param name="functionSignature"></param>
        /// <param name="functionType"></param>
        /// <returns></returns>
        public ICirFunction getCirFunction(ICirData cirData, string functionSignature, string functionType)
        {
            try
            {
            
                if (cirData.dFunctions_bySignature.ContainsKey(functionSignature))
                    return cirData.dFunctions_bySignature[functionSignature];

                // create the function reference                
                var newCirFunction = new CirFunction(functionSignature);
                cirData.dFunctions_bySignature.Add(functionSignature, newCirFunction);

                // add it to the respective CirClas

                var cirClass = getCirClass(cirData,functionType);
                cirClass.dFunctions.Add(functionSignature, newCirFunction);

                return newCirFunction;
            }
            catch (Exception ex)
            {
                DI.log.ex(ex, "in CirFactory.getCirFunction", true);
                return null;
            }
        }
        public ICirFunction addFunction(string newFunctionSignature)
        {
            if (newFunctionSignature == null || dFunctions.ContainsKey(newFunctionSignature))
            {
                return(null);
            }

            var cirFunction = new CirFunction(newFunctionSignature);

            dFunctions.Add(newFunctionSignature, cirFunction);
            return(cirFunction);
        }
        public ICirFunction addCalledFunction(string calledFunctionSignature, string file, int lineNumber)
        {
            ICirFunction calledCirFunction = null;

            foreach (var existingCirFunctionCallReference in FunctionsCalledUniqueList)
            {
                if (calledFunctionSignature == existingCirFunctionCallReference.FunctionSignature)
                {
                    calledCirFunction = existingCirFunctionCallReference;
                }
            }
            if (calledCirFunction == null)      // means we have not mapped a function with this signature before
            {
                calledCirFunction      = new CirFunction(calledFunctionSignature);
                calledCirFunction.File = file;
                FunctionsCalledUniqueList.Add(calledCirFunction);
            }
            FunctionsCalled.Add(new CirFunctionCall(calledCirFunction, calledCirFunction.File, lineNumber));
            return(calledCirFunction);
        }
Beispiel #4
0
        private bool processFunctionAndAddItToNode(TreeNodeCollection tncTargetNode, CirFunction cfCirFunction,
                                                   List<String> lsFunctionsAdded)
        {
            bool bMakesCallTo = false;
            TreeNode tnMethod = O2Forms.newTreeNode(cfCirFunction.FunctionSignature, "", 2, cfCirFunction);

            // add arguments and return value
            if (cbShowArgsAndReturntype.Checked)
            {
                if (cfCirFunction.ReturnType != "")
                    tnMethod.Nodes.Add(
                        O2Forms.newTreeNode(
                            String.Format("retv: {0}", CirDataUtils.getSymbol(fcdCirData,cfCirFunction.ReturnType)), "", 3, null));
                foreach (ICirFunctionParameter functionParameter in cfCirFunction.FunctionParameters)
                    tnMethod.Nodes.Add(O2Forms.newTreeNode(String.Format("arg: {0}", CirDataUtils.getSymbol(fcdCirData, functionParameter.ParameterType)),
                                                           "", 3, null));
            }
            // add variables
            if (rbShowFieldsAndVariables.Checked)
            {
                foreach (String sSymbolRef in cfCirFunction.UsedTypes)
                    tnMethod.Nodes.Add(O2Forms.newTreeNode(String.Format("v: {0}", CirDataUtils.getSymbol(fcdCirData,sSymbolRef)), "",
                                                           4, null));
            }
            // add functions called by this method & 
            foreach (ICirFunction cirFunctionCalled in cfCirFunction.FunctionsCalledUniqueList)
            {
                var sSignature = cirFunctionCalled.FunctionSignature;
                bool bAddSignature = false;
                String sSignatureWithParams = sSignature.Substring(0, sSignature.IndexOf('('));
                if ((false == cbCirAnalyzer_TextFilter_MakesCallsTo.Checked &&
                     false == cbCirAnalyzer_TextFilter_RemoveMakesCallsTo.Checked))
                    bAddSignature = true;

                bool bMatchOnRemovesMakesCallTo = (cbCirAnalyzer_TextFilter_RemoveMakesCallsTo.Checked &&
                                                   sSignatureWithParams.IndexOf(
                                                       (string) tbCirAnalyszer_TextSearchFilter_RemoveMakesCallsTo.Text) == -1);
                bool bMatchOnMakesCallTo = (cbCirAnalyzer_TextFilter_MakesCallsTo.Checked &&
                                            sSignatureWithParams.IndexOf(
                                                (string) tbCirAnalyszer_TextSearchFilter_MakesCallsTo.Text) > -1);

                if ((bMatchOnRemovesMakesCallTo && false == cbCirAnalyzer_TextFilter_MakesCallsTo.Checked) ||
                    (bMatchOnMakesCallTo && false == cbCirAnalyzer_TextFilter_RemoveMakesCallsTo.Checked) ||
                    (bMatchOnRemovesMakesCallTo && bMatchOnMakesCallTo))
                    bAddSignature = true;
                if (bAddSignature)
                {
                    lsFunctionsAdded.Add(sSignature);
                    bMakesCallTo = true;
                    tnMethod.Nodes.Add(O2Forms.newTreeNode(String.Format("fCalled: {0}", sSignature), "", 10, null));
                }
            }
            // add functions that call this method
            foreach (ICirFunction cirIsCalledFunction in cfCirFunction.FunctionIsCalledBy)
                tnMethod.Nodes.Add(O2Forms.newTreeNode(String.Format("isCalledBy: {0}", cirIsCalledFunction.FunctionSignature), "", 11, null));
            if (cbCirAnalyzer_TextFilter_MakesCallsTo.Checked && false == bMakesCallTo)
                return false;
            tncTargetNode.Add(tnMethod);
            return true;
        }
Beispiel #5
0
 public ICirFunction addCalledFunction(string calledFunctionSignature, string file, int lineNumber)
 {
     ICirFunction calledCirFunction = null;
     foreach (var existingCirFunctionCallReference in FunctionsCalledUniqueList)
         if (calledFunctionSignature == existingCirFunctionCallReference.FunctionSignature)
             calledCirFunction = existingCirFunctionCallReference;
     if (calledCirFunction == null)      // means we have not mapped a function with this signature before
     {
         calledCirFunction = new CirFunction(calledFunctionSignature);
         calledCirFunction.File = file;
         FunctionsCalledUniqueList.Add(calledCirFunction);
     }
     FunctionsCalled.Add(new CirFunctionCall(calledCirFunction, calledCirFunction.File, lineNumber));
     return calledCirFunction;
 }
        public void showDataForSignature(String sSignature)
        {
            // check if this function is on the current list (if not this is an edge)
            if (false == cirDataAnalysis.dCirFunction_bySignature.ContainsKey(sSignature))
                // this case do a hack by adding this edge as a function
            {
                var lsFunctionsThatCallSignature = new List<ICirFunctionCall>();
                // first find everybody that calls into it
                foreach (ICirFunction ccFunction in cirDataAnalysis.dCirFunction_bySignature.Values)
                    if (cirDataAnalysis.dCirFunction_bySignature.ContainsKey(sSignature))
                        if (ccFunction.FunctionsCalledUniqueList.Contains( cirDataAnalysis.dCirFunction_bySignature[sSignature]))
                            lsFunctionsThatCallSignature.Add(new CirFunctionCall(ccFunction));

                var ccNewCirFunction = new CirFunction
                                           {
                                               FunctionSignature = sSignature,
                                               FunctionIsCalledBy = lsFunctionsThatCallSignature
                                           };
                cirDataAnalysis.dCirFunction_bySignature.Add(sSignature, ccNewCirFunction);
            }
            var tvTraces = new TreeView();
            var lFunctionsCalled = new List<string>();
            const string sFilter_Signature = "";
            const string sFilter_Parameter = "";
            if (cbSearchMode.SelectedItem.ToString() == SearchModes.CalledFunctions.ToString())
                TraceAnalysis.calculateAllTracesFromFunction(sSignature, tvTraces.Nodes, lFunctionsCalled,
                                                             sFilter_Signature, sFilter_Parameter, false,
                                                             cirDataAnalysis);
            else
                TraceAnalysis.calculateAllTracesFromFunction(sSignature, tvTraces.Nodes, lFunctionsCalled,
                                                             sFilter_Signature, sFilter_Parameter, true, cirDataAnalysis);
            if (cbViewMode.SelectedItem.ToString() == ViewModes.List.ToString())
                afv_Functions.showSignatures(lFunctionsCalled);
            else
            {
                replaceTreeView(this, ref tvTreeView, tvTraces);
                if (cbSearchMode.SelectedItem.ToString() == SearchModes.IsCalledBy.ToString())
                    tvTreeView.ExpandAll();
            }
        }
Beispiel #7
0
 public static Dictionary<String, ICirFunction> analysis_getFunctionsThatHaveACallPathIntoFunction(
     CirFunction cfTargetFunction, String sParameterFilter)
 {
     var dMatches = new Dictionary<string, ICirFunction>();
     return dMatches;
 }
Beispiel #8
0
        // these Functions contains multiple analysis on o2CirDump data            
        /*   public enum searchFilter
           {
               byClassName,
               byFunctionName,
               byParameterName
           }*/

        public static Dictionary<String, ICirFunction> analysis_getFunctionsThatHaveACallPathIntoFunction(
            CirFunction cfTargetFunction)
        {
            return analysis_getFunctionsThatHaveACallPathIntoFunction(cfTargetFunction, "");
        }
Beispiel #9
0
        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;
        }
Beispiel #10
0
        public static ICirFunction addFunction(ICirData cirData, String sSymbolRef, String sSignature)
        {
            if (cirData.dFunctions_bySignature.ContainsKey(sSignature))
            {
                // if (dSymbols[sSymbolRef] == CONST_NEED_SIGNATURE)
                //     dSymbols[sSymbolRef] = FunctionSignature;
                return cirData.dFunctions_bySignature[sSignature];
            }

            var cfCirFunction = new CirFunction { SymbolDef = sSymbolRef, FunctionSignature = sSignature };
            addSymbol(cirData, sSymbolRef, sSignature);
            cirData.dFunctions_bySignature.Add(sSignature, cfCirFunction);
            //mapFunctionCall(cirData, cfCirFunction, sSymbolRef, sSignature);
            return cfCirFunction;
        }
Beispiel #11
0
        public static ICirFunction createTempCirFunctionWithReturnTypeAndArguments(ICirData cirData, CommonIRDumpCommonIRFunctionSigType fsSymbol)
        {
            //String sSymbolDef = fsSymbol.SymbolDef;
            ICirFunction cfCirFunction = new CirFunction {};
           
            //ICirFunction cfCirFunction;
           /* var functionSignature = getSymbol(cirData, sSymbolDef);

            if (cirData.dTemp_Functions_bySymbolDef.ContainsKey(sSymbolDef))
                cfCirFunction = cirData.dTemp_Functions_bySymbolDef[sSymbolDef];                
            else
            {
                cfCirFunction = new CirFunction { SymbolDef = sSymbolDef };
                cirData.dFunctions_bySignature.Add(functionSignature, cfCirFunction);
                cirData.dTemp_Functions_bySymbolDef.Add(sSymbolDef, cfCirFunction);
                //addSymbol(cirData, sSymbolDef, DI.CONST_NEED_SIGNATURE); // create an SymbolRef with no signature
            }
            /*if (cirData.dFunctions_bySymbolDef.ContainsKey(sSymbolDef))            
                cfCirFunction = cirData.dFunctions_bySymbolDef[sSymbolDef];                
            else
            {
                cfCirFunction = new CirFunction { SymbolDef = sSymbolDef };
                cirData.dFunctions_bySignature.Add(functionSignature, cfCirFunction);
                cirData.dFunctions_bySymbolDef.Add(sSymbolDef, cfCirFunction);
                //addSymbol(cirData, sSymbolDef, DI.CONST_NEED_SIGNATURE); // create an SymbolRef with no signature
            }*/
            //if (cfCirFunction.ReturnType == "") // check if these values have been set
            //{
                //cfCirFunction.ReturnType = fsSymbol.ReturnType.SymbolRef;
                cfCirFunction.ReturnType = fsSymbol.ReturnType.PrintableType;            
                //addSymbol(cirData, fsSymbol.ReturnType.SymbolRef, fsSymbol.ReturnType.PrintableType);
                if (fsSymbol.ArgumentTypes != null)
                    foreach (CommonIRDumpCommonIRFunctionSigTypeArgument fsArgumentType in fsSymbol.ArgumentTypes)
                    {
                        if (false == ViewHelpers.getCirParameterTypeStringList(cfCirFunction.FunctionParameters).Contains(fsArgumentType.SymbolRef))
                        // if there are probs with more arguments than reality, i will need to add 
                        // a more thorough check here (one that handles the differences between the first time data is added (which makes it an 'add' ) 
                        // and the 2nd time (which makes it an 'confirm that they are the same' )
                        {
                            cfCirFunction.FunctionParameters.Add(new CirFunctionParameter { ParameterName = "", ParameterType = fsArgumentType.PrintableType });//fsArgumentType.SymbolRef});
                            //addSymbol(cirData, fsArgumentType.SymbolRef, fsArgumentType.PrintableType);
                        }
                    }
            //}
            /*else if (cfCirFunction.ReturnType != fsSymbol.ReturnType.SymbolRef)
                // double check that nothing major is wrong, since these values should match
                DI.log.error(
                    "in addToFunction_ArgumentsAndReturnType, cfCirFunction.ReturnType != fsSymbol.ReturnType.SymbolRef: {0} != {1}",
                    cfCirFunction.ReturnType, fsSymbol.ReturnType.SymbolRef);*/
            return cfCirFunction;
        }
Beispiel #12
0
        public ICirFunction addFunction(string newFunctionSignature)
        {
            if (newFunctionSignature == null || dFunctions.ContainsKey(newFunctionSignature))
                return null;

            var cirFunction = new CirFunction(newFunctionSignature);            
            dFunctions.Add(newFunctionSignature, cirFunction);
            return cirFunction;
        }