Esempio n. 1
0
        public static O2RulePack createRules_SourcesAndSinks(String sCirDataFile)
        {
            var rpRulePack = new O2RulePack();
            if (false == File.Exists(sCirDataFile))
                DI.log.error("in createRules_SourcesAndSinks, provide CirData file not found: {0}", sCirDataFile);
            else
            {
                List<String> lsFunctions = MiscUtils.getFunctionsSignaturesFrom02CirData(sCirDataFile);
                // in this type of scan, there are two rules	    	
                // if functions make no calls then they are maked as both Sources and Sinks
                // other cases receive no marking
                // sinks have preference (for the cases there there are no calls into and from

                CirData fcdCirData = CirLoad.loadSerializedO2CirDataObject(sCirDataFile);

                foreach (string sFunction in lsFunctions)
                {
                    ICirFunction cfCirFunction = fcdCirData.dFunctions_bySignature[sFunction];
                    if (cfCirFunction.FunctionsCalledUniqueList.Count == 0)
                    {
                        addRule(createRule(O2RuleType.Sink, sFunction, fcdCirData.sDbId), rpRulePack);
                        addRule(createRule(O2RuleType.Source, sFunction, fcdCirData.sDbId), rpRulePack);
                    }
                }
            }
            return rpRulePack;
        }
Esempio n. 2
0
 /// <summary>
 ///  recursive mapping of traces tracetype (required since there could be multiple sources
 /// </summary>
 /// <param name="o2RulePack"></param>
 /// <param name="indexedO2Rules"></param>
 /// <param name="o2Traces"></param>
 /// <param name="languageDBId"></param>
 /// <param name="o2NewRuleType"></param>
 private static void updateO2RulePackWithFindingsTraceTypes (O2RulePack o2RulePack,IDictionary<string, List<IO2Rule>> indexedO2Rules, List<IO2Trace> o2Traces, string languageDBId, O2RuleType o2NewRuleType)
 {
     foreach (var o2Trace in o2Traces)
     {
         updateSourceOrSinkRule(o2RulePack, indexedO2Rules, o2Trace.signature, languageDBId, o2Trace.traceType);
         updateO2RulePackWithFindingsTraceTypes(o2RulePack, indexedO2Rules, o2Trace.childTraces, languageDBId, o2NewRuleType);
     }
 }
Esempio n. 3
0
 public static String saveRulePack(String pathToSaveFile, String sTypeOfPack, O2RulePack o2rulePackToSave)
 {
     if (false == File.Exists(pathToSaveFile) && false == Directory.Exists(Path.GetDirectoryName(pathToSaveFile)))
         pathToSaveFile = DI.config.TempFileNameInTempDirectory + "_" + pathToSaveFile;
     string rulePackFile = pathToSaveFile + "_" + o2rulePackToSave.RulePackName + "_" + "(" +
                           o2rulePackToSave.o2Rules.Count + ")_" + sTypeOfPack + ".O2RulePack";
     return saveRulePack(rulePackFile, o2rulePackToSave);
 }
Esempio n. 4
0
 public static string saveRulePack(string rulePackFile, O2RulePack o2rulePackToSave)
 {
     if (o2rulePackToSave.o2Rules.Count > 0)
     {
         Serialize.createSerializedXmlFileFromObject(o2rulePackToSave, rulePackFile);
         DI.log.info("Saved O2RulePack {0} with {1} rules", rulePackFile, o2rulePackToSave.o2Rules.Count);
         return rulePackFile;
     }
     return "";
 }
 private void saveCurrentFilter(string typeOfRule, string signatureFilter, O2Thread.FuncVoid onComplete)
 {
     O2Thread.mtaThread(
         () =>
             {                        
                 var o2RulePack = new O2RulePack("All loaded rules", rulesToShow);
                 var savedFile = O2RulePackUtils.saveRulePack(typeOfRule, signatureFilter, o2RulePack);
                 DI.log.showMessageBox("Current filtered rules saved to: " + savedFile);
                 onComplete();
             });
 }
Esempio n. 6
0
        public void test_createRulePackWithSourcesAndSinksRulesFromLddbFor_DotNet()
    {
        var ruleDbId = MiscUtils_OunceV6.getIdForSuportedLanguage(SupportedLanguage.DotNet).ToString();
            // create just sources and sinks
            var sourcesRulePack = new O2RulePack("MySql_Sources", mySqlRules_OunceV6.getRules_Sources(ruleDbId));
            var sourcesRulePackFile =  O2RulePackUtils.saveRulePack(sourcesRulePack);
            Assert.That(File.Exists(sourcesRulePackFile), "sourcesRulePackFile doesn't exist");

            var sinksRulePack = new O2RulePack("MySql_Sinks", mySqlRules_OunceV6.getRules_Sinks(ruleDbId));
            var sinksRulePackFile =  O2RulePackUtils.saveRulePack(sinksRulePack);
            Assert.That(File.Exists(sinksRulePackFile), "sinksRulePackFile doesn't exist");            

        }
Esempio n. 7
0
        public static void mapInRulePack_FindingsSourcesAndSinks(O2RulePack o2RulePack, Dictionary<string, List<IO2Rule>> indexedO2Rules, List<IO2Finding> o2Findings, string languageDBId)
        {
            var timer = new O2Timer("mapInRulePack_FindingsSourcesAndSinks").start();
            foreach (O2Finding o2Finding in o2Findings)
                updateO2RulePackWithFindingsTraceTypes(o2RulePack, indexedO2Rules, o2Finding.o2Traces, languageDBId,
                                                       O2RuleType.Source);

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


        }
Esempio n. 8
0
        public void test_createRulePackWithAllRulesFromLddbFor_DotNet()
        {
            
            var numberOfRules = Lddb_OunceV6.getNumberOfRulesInRecTable();
            Assert.That(numberOfRules > 0, "numberOfRules == 0");
            DI.log.info("There {0} rules", numberOfRules);

            var o2Rules = mySqlRules_OunceV6.createO2RulesForAllLddbEntriesForLanguage(SupportedLanguage.DotNet);
            var o2RulePack = new O2RulePack("MySql_Dump", o2Rules);

            Assert.That(o2Rules.Count > 0, "o2Rules.Count ==0");
            var rulePackFile = O2RulePackUtils.saveRulePack(o2RulePack);
            Assert.That(File.Exists(rulePackFile), "rulePacklFile file didn't exist: " + rulePackFile);
            DI.log.info("Rule pack (with {0} rules) saved to {1}", o2Rules.Count, rulePackFile);
        }
        public void calculateRulePack_forFile(string ozamstFileToTest, O2RulePack o2RulePackToUse)
        {
            DI.log.debug("\n\ntesting file: {0}", ozamstFileToTest);
            var timer = new O2Timer("Calculate Rule Pack ").start();
            // load assesment file and get unique signatures
            var o2Findings = new O2AssessmentLoad_OunceV6().loadFile(ozamstFileToTest).o2Findings;
            var uniqueSignatures = RulesAndFindingsUtils.getListOfUniqueSignatures(o2Findings);
            Assert.That(uniqueSignatures.Count > 0, "uniqueSignatures ==0");
            // calculate rulepack for this assessment

            var o2RulePackForOzasmt = RulesAndFindingsUtils.createRulePackWithSignatures(o2RulePackToUse, uniqueSignatures,
                                                               Path.GetFileName(ozamstFileToTest), true, testLanguageDBId);
            Assert.That(o2RulePackForOzasmt.o2Rules.Count > 0, "There were no rules in created o2RulePackForOzasmt");
            timer.stop();
        }
Esempio n. 10
0
 public List<IO2Rule> addRulesToDatabase(bool bDeleteDatabase, O2RulePack o2rulePack)
 {
     var rulesNotProcessed = new List<IO2Rule>();
     if (bDeleteDatabase)
         Lddb_OunceV6.action_DeleteAllRules();
     //Utils.debugBreak();
     //removeRulesFromCache();
     DI.log.info("Adding {0} rules to database", o2rulePack.o2Rules.Count);
     foreach (var o2Rule in o2rulePack.o2Rules)
         if (false == addRuleToDatabase(o2Rule))
             rulesNotProcessed.Add(o2Rule);
     DI.log.info("Completed adding {0} rules to database", o2rulePack.o2Rules.Count);
     if (rulesNotProcessed.Count > 0)
         DI.log.info("Total number of rules NOT processed: {0}", rulesNotProcessed.Count);
     return rulesNotProcessed;
 }
 public void importASfile(string fileToLoad)
 {
     if (false == File.Exists(fileToLoad))
         DI.log.error("could not find summary file: {0}", fileToLoad);
     var fileContents = Files.getFileContents(fileToLoad);
 	DI.log.info("Loaded file size: {0}",fileContents.Length);
 	var rules = fileContents.Split(new []{Environment.NewLine},StringSplitOptions.None);
 	DI.log.info("There are {0} rules", rules.Length);
 	
 	var rulesCreated = new List<IO2Rule>();
 	foreach(var rule in rules)
 	{
 		var ruleDetails = rule.Split('\t');
 		var ruleDetailsLength =  ruleDetails.Length;
 		var ruleSignature = (ruleDetailsLength>0)  ? ruleDetails[0] : "";
 		var ruleTaintFrom = (ruleDetailsLength>1)  ? ruleDetails[1] : "";
 		var ruleTaintTo   = (ruleDetailsLength>2)  ? ruleDetails[2] : "";
         DI.log.info("{0} - {1} - {2}", ruleSignature, ruleTaintFrom, ruleTaintTo);
         rulesCreated.Add(createASRule(ruleSignature, ruleTaintFrom, ruleTaintTo));
 	}
     var newRulePack = new O2RulePack("ASummary Rule Pack", rulesCreated);
     setCurrentRulePack(newRulePack);
     refreshRulesViewer();
 }
Esempio n. 12
0
        //rename this method since we do more than just Source or Sinks here
        private static void updateSourceOrSinkRule(O2RulePack o2RulePack,IDictionary<string, List<IO2Rule>> indexedO2Rules, string ruleSignature, string languageDBId, TraceType traceType)
        {
            if (indexedO2Rules != null && ruleSignature != null)
            {
                //bool createNotMappedRule = false;
                var createRuleWithType = O2RuleType.NotMapped;
                // only proccess Sources, Sinks and Lost Sinks
                if (traceType == TraceType.Source || traceType == TraceType.Known_Sink || traceType == TraceType.Lost_Sink)
                {
                    O2RuleType o2NewRuleType = O2RulePackUtils.getO2RuleTypeFromRuleType(traceType);
                    createRuleWithType = o2NewRuleType;

             /*       if (indexedO2Rules != null && false == string.IsNullOrEmpty(ruleSignature))
                        if (indexedO2Rules.ContainsKey(ruleSignature))
                        {
                            bool thereIsAlreadyARuleWithTheSameRuleType = false;
                            foreach (var o2Rule in indexedO2Rules[ruleSignature])
                            {
                                if (o2Rule.RuleType == O2RuleType.NotMapped)
                                // if it is not mapped change it to o2NewRuleType
                                {
                                    o2Rule.RuleType = o2NewRuleType;
                                    return;
                                }
                                if (o2Rule.RuleType == o2NewRuleType)
                                    // if it is already a rule of type o2NewRuleType, mark it so we can ignore it below
                                    thereIsAlreadyARuleWithTheSameRuleType = true;
                            }
                            if (false == thereIsAlreadyARuleWithTheSameRuleType)
                            // if we got this far, create a new rule of o2NewRuleType                                        
                            {
                                var newRule = O2RulePackUtils.createRule(o2NewRuleType, ruleSignature, languageDBId);
                                indexedO2Rules[ruleSignature].Add(newRule);
                                // add it to the index so that we don't have to calculate it again
                                o2RulePack.o2Rules.Add(newRule);
                            }
                        }
                    */
                }
                bool createNewRule = true;
                IO2Rule notMappedRule = null;

                if (indexedO2Rules.ContainsKey(ruleSignature))
                {
                    foreach (var o2Rule in indexedO2Rules[ruleSignature])
                    {
                        if (o2Rule.RuleType == createRuleWithType)          // dont create if there is already a rule of this type
                        {
                            o2Rule.Tagged = true;
                            createNewRule = false;
                        }
                        if (o2Rule.RuleType == O2RuleType.NotMapped)
                            notMappedRule = o2Rule;
                    }
                }
                // handle the case where we have already added a signature but it is not a NotMapped one
                if (createRuleWithType == O2RuleType.NotMapped &&  createNewRule && notMappedRule == null && indexedO2Rules.ContainsKey(ruleSignature))
                    createNewRule = false;

                // if required, Create  rule
                if (createNewRule)
                {
                    var vulnType = "O2.FindingRule." + createRuleWithType.ToString();
                    var newRule = new O2Rule(createRuleWithType,vulnType, ruleSignature, languageDBId,true);
                    o2RulePack.o2Rules.Add(newRule);
                    if (false == indexedO2Rules.ContainsKey(ruleSignature))
                        indexedO2Rules.Add(ruleSignature, new List<IO2Rule>());
                    indexedO2Rules[ruleSignature].Add(newRule);
                    if (notMappedRule != null)
                        indexedO2Rules[ruleSignature].Remove(notMappedRule);
                }
            }
        }
        private void addCirFunctionsAsRules(
            List<ICirFunction> cirFunctionsToProcess, bool keepRulesLoadedFromDatabase, 
            bool bAddExternalMethodsAsSourcesAndSinks,bool bAddInternalMethodsWithNoCallersAsCallbacks,
            bool bDontMarkAsCallbackOrSinksMethodsWithNoParameters,
            bool bdontAddIfRuleSignatureAlreadyExists, bool bDontAddIfThereAreNoCallersAndCallees,
            string newRulesVulnType)
        {            
            // for performance reasons run this on a separade thread
            O2Thread.mtaThread(
                () =>
                    {
                        // before adding more rules, clear the current list (the return null is to force the Sync version  of invokeOnThread )
                        this.invokeOnThread(()=>
                                                {
                                                    clearChangedRulesList();
                                                    return null;
                                                });
                        
                        var newCallbackSignature = "O2.AutoMapping";
                        DI.log.info("adding {0} cirFunctions as rules", cirFunctionsToProcess.Count);

                        // get rules that we will keep (if there are rules loaded from Db and keepRulesLoadedFromDatabase is set)
                        var newO2Rules = (keepRulesLoadedFromDatabase)
                                             ? O2RulePackUtils.getRulesThatAreFromDB(currentO2RulePack)
                                             : new List<IO2Rule>();

                        //update index
                        indexedCurrentO2Rules = IndexedO2Rules.indexAll(newO2Rules);

                        if (keepRulesLoadedFromDatabase)
                            foreach (var o2Rule in newO2Rules)
                                o2Rule.Tagged = false;

                        var currentDatabaseID = MiscUtils_OunceV6.getIdForSuportedLanguage(currentLanguage).ToString();

                        var listOfChangedRules = new List<IO2Rule>();
                        var functionsToProcess = cirFunctionsToProcess.Count;
                        var functionsProcessed = 0;
                        foreach (var cirFunction in cirFunctionsToProcess)
                        {
                            var functionSignature = new FilteredSignature(cirFunction).sSignature;                            
                            // first check if there are any callers or callees on this function
                            //bDontAddIfThereAreNoCallersAndCallees
                            if (bDontAddIfThereAreNoCallersAndCallees && cirFunction.FunctionIsCalledBy.Count == 0 &&
                                cirFunction.FunctionsCalledUniqueList.Count == 0)
                            {
                                // don't add
                            }
                            else 
                                // then check if this already exists on the database
                                if (bdontAddIfRuleSignatureAlreadyExists &&
                                     indexedCurrentO2Rules.ContainsKey(functionSignature))
                                {
                                    foreach (var o2Rule in indexedCurrentO2Rules[functionSignature])
                                        o2Rule.Tagged = true;
                                }
                                // if not, then we will need ot create a new rule for this function
                                else
                                {                                    
                                    bool addAsNotMappedRule = false;
                                    //var functionSignature = new FilteredSignature(cirFunction).sSignature;

                                    // handle special cases 


                                    //bAddInternalMethodsWithNoCallersAsCallbacks (or the function is explicitly marked with cirFunction.IsTainted
                                    if (cirFunction.IsTainted || 
                                        (bAddInternalMethodsWithNoCallersAsCallbacks && cirFunction.HasControlFlowGraph && cirFunction.FunctionIsCalledBy.Count == 0))
                                    {
                                        //bDontMarkAsCallbackMethodsWithNoParameters
                                        if (false == bDontMarkAsCallbackOrSinksMethodsWithNoParameters ||
                                            cirFunction.FunctionSignature.IndexOf("()") == - 1)
                                            //cirFunction.FunctionParameters.Count > 0)  // can't use this since it is not 100% reliable
                                        {
                                            var newCallback = new O2Rule(O2RuleType.Callback,
                                                                         newCallbackSignature + ".Callback",
                                                                         functionSignature, currentDatabaseID, true);
                                            listOfChangedRules.Add(newCallback);
                                            newO2Rules.Add(newCallback);
                                        }
                                        else
                                            addAsNotMappedRule = true;
                                    }
                                    //bAddExternalMethodsAsSourcesAndSinks  - function calls nobody but it is called by others
                                    else if (bAddExternalMethodsAsSourcesAndSinks &&
                                             cirFunction.FunctionsCalledUniqueList.Count == 0 &&
                                             cirFunction.FunctionIsCalledBy.Count > 0)
                                    {
                                        // when importing CirData created by Core on Java, there is a bug that causes the ReturnType NOT to be populated 
                                        // this is why we use the cirFunction.FunctionSignature.IndexOf(":void") > -1 below instead of the more correct if (string.IsNullOrEmpty(cirFunction.ReturnType))
                                        //if (string.IsNullOrEmpty(cirFunction.ReturnType))
                                        //    DI.log.info("Method had empty cirFunction.ReturnType: {0}", cirFunction.FunctionSignature);
                                        // Only add source if the return parameter is not void
                                        if (!(cirFunction.FunctionSignature.IndexOf(":void") > -1 || cirFunction.ReturnType == "void" || cirFunction.ReturnType == "System.Void"))
                                        {
                                            var newSource = new O2Rule(O2RuleType.Source,
                                                                       newCallbackSignature + ".Source",
                                                                       functionSignature, currentDatabaseID, true);
                                            listOfChangedRules.Add(newSource);
                                            newO2Rules.Add(newSource);
                                        }
                                        else
                                            DI.log.info("Method Not marked as Source: {0}", cirFunction.FunctionSignature);
                                        // for sinks check for bDontMarkAsCallbackOrSinksMethodsWithNoParameters
                                        if (false == bDontMarkAsCallbackOrSinksMethodsWithNoParameters ||
                                            cirFunction.FunctionSignature.IndexOf("()") == -1)
                                            //cirFunction.FunctionParameters.Count > 0)
                                        {

                                            var newSink = new O2Rule(O2RuleType.Sink, newCallbackSignature + ".Sink",
                                                                     functionSignature, currentDatabaseID, true);
                                            listOfChangedRules.Add(newSink);
                                            newO2Rules.Add(newSink);
                                        }
                                        //else                                            
                                        //    DI.log.info("Method Not marked as Sink: ", cirFunction.FunctionSignature);
                                    }
                                    else
                                    {
                                        addAsNotMappedRule = true;
                                    }

                                    if (addAsNotMappedRule)
                                    {
                                        // add as NotMapped
                                        var newO2Rule = new O2Rule(newRulesVulnType, functionSignature, currentDatabaseID) { Tagged = true };
                                        newO2Rules.Add(newO2Rule);
                                    }
                                }
                            // Counter
                            if ((functionsProcessed++)%200 == 0)
                                DI.log.info("In addCirFunctionsAsRules: {0} / {1} cir Functions processed",
                                            functionsProcessed, functionsToProcess);
                        }

                        // make the current rule pack the one with the rules we have just loaded
                            DI.log.info("{0} rules created", newO2Rules.Count);
                            var newRulePack = new O2RulePack("Rule Pack", newO2Rules);
                        setCurrentRulePack(newRulePack);

                        // we need to back to the GUI thread for the updates
                        this.invokeOnThread(
                            () =>
                                {
                                    // hide this ListView for performance reasons
                                    lvChangedRules.Visible = false;
                                    dgvRules.Visible = false;
                                    // add rules
                                    addRulesToChangedRulesList_BatchMode(listOfChangedRules);

                                  //  foreach (var changedO2Rule in listOfChangedRules)
                                  //      addRuleToChangedRulesList(changedO2Rule, false /*checkIfRuleIsAlreadyInList*/);
                                    
                                    // if we are in view all mode changed it to OnlyTaggedRules
                                    if (rbViewMode_AllRules.Checked)
                                        rbViewMode_OnlyTaggedRules.Checked = true;
                                    else
                                        setRulesViewMode(); // trigger refresh

                                    // now that all rules have been added make it visible again
                                    lvChangedRules.Visible = true;
                                    dgvRules.Visible = true;
                                });                                                                        
                    });
        }
Esempio n. 14
0
        /*public static List<String> getListOfUniqueSignatures_UsingUniqueList(List<IO2Finding> o2Findings)
        {
            // mode 1 use one big list
            var uniqueSignatures = new List<String>();
            // calculate unique signatures 
            var itemsProcessed = 0;
            var itemsToProcess = o2Findings.Count;
            foreach (var o2Finding in o2Findings)
            {
                getListOfUniqueSignatures(o2Finding.o2Traces, uniqueSignatures);                
                if ((itemsProcessed++) % 5000 == 0)
                    DI.log.info("on [{0}/{1}] there are {2} unique signatures", itemsProcessed, itemsToProcess, uniqueSignatures.Count);
            }
            DI.log.info("There are {0} unique signatures", uniqueSignatures.Count);
            return uniqueSignatures;
        }*/




        internal static O2RulePack mapFindingsToCurrentRulePack(
            O2RulePack currentO2RulePack, List<IO2Finding> o2Findings, string languageId, bool keepRulesLoadedFromDatabase)
        {
            var newCallbackSignature = "O2.AutoMapping";
            DI.log.info("converting {0} Findings into rules", o2Findings.Count);

            // get rules that we will keep (if there are rules loaded from Db and keepRulesLoadedFromDatabase is set)
            var newO2Rules = (keepRulesLoadedFromDatabase)
                                 ? O2RulePackUtils.getRulesThatAreFromDB(currentO2RulePack)
                                 : new List<IO2Rule>();

            //update index
            var indexedCurrentO2Rules = IndexedO2Rules.indexAll(newO2Rules);
            // and if there are any rules from the database, remove any Tagged values                       
            if (keepRulesLoadedFromDatabase)
                foreach (var o2Rule in newO2Rules)
                    o2Rule.Tagged = false;

            // create rulepack 
            var newRulePack = new O2RulePack("Rule Pack", newO2Rules);

            // and call the function that does the mappings
            mapInRulePack_FindingsSourcesAndSinks(newRulePack, indexedCurrentO2Rules , o2Findings, languageId);
            
            DI.log.info("{0} rules created", newRulePack.o2Rules.Count);
            
            return newRulePack;

        }
Esempio n. 15
0
 public static O2RulePack createRulePackThatMatchFindings(O2RulePack o2rulePack, List<IO2Finding> o2Findings, string rulePackName, string languageDBId)
 {
     var uniqueSignatures = getListOfUniqueSignatures(o2Findings);            
     return createRulePackWithSignatures(o2rulePack, uniqueSignatures, rulePackName, true, languageDBId);
 }
Esempio n. 16
0
 public static O2RulePack createRulePackWithSignatures(O2RulePack o2rulePack, List<String> signaturesToFind, string rulePackName, bool addNonMatchingSignaturesAsNewRule, string languageDBId)
 {
     DI.log.info("in createRulePackWithSignatures");
     var o2RulesThatMatchSignatures = new List<IO2Rule>();
     var indexedRules = IndexedO2Rules.indexAll(o2rulePack.getIO2Rules());
     foreach (var signature in signaturesToFind)
         if (indexedRules.ContainsKey(signature))
             foreach (var o2Rule in indexedRules[signature])
                 o2RulesThatMatchSignatures.Add(o2Rule);
         else
             if (addNonMatchingSignaturesAsNewRule)                                            
                 o2RulesThatMatchSignatures.Add(O2RulePackUtils.createRule(O2RuleType.NotMapped, signature, languageDBId));                    
     DI.log.info("createRulePackWithSignatures completed, there were {0} rules found", o2RulesThatMatchSignatures.Count);
     return new O2RulePack(rulePackName, o2RulesThatMatchSignatures);
 }
Esempio n. 17
0
        public static O2RulePack createRules_CallBacksOnEdges_And_ExternalSinks(String sCirDataFile)
        {
            var rpRulePack = new O2RulePack();
            if (false == File.Exists(sCirDataFile))
                DI.log.error(
                    "in createRules_CallBacksOnEdges_And_ExternalSinks, provide CirData file not found: {0}",
                    sCirDataFile);
            else
            {
                List<String> lsFunctions = MiscUtils.getFunctionsSignaturesFrom02CirData(sCirDataFile);
                // in this type of scan, there are two rules	    	
                // if functions make no calls it is a Sink
                // if nobody calls the function it is a callback
                // sinks have preference (for the cases there there are no calls into and from

                ICirData fcdCirData = CirLoad.loadSerializedO2CirDataObject(sCirDataFile);

                foreach (string sFunction in lsFunctions)
                {
                    ICirFunction cfCirFunction = fcdCirData.dFunctions_bySignature[sFunction];
                    if (cfCirFunction.FunctionsCalledUniqueList.Count == 0)
                        addRule(createRule(O2RuleType.Sink, sFunction, fcdCirData.sDbId), rpRulePack);                        
                        // DI.log.error("   Make no Calls (make sink): {0}" , cfCirFunction.sSignature);
                    else if (cfCirFunction.FunctionIsCalledBy.Count == 0)
                        addRule(createRule(O2RuleType.Callback, sFunction, fcdCirData.sDbId), rpRulePack);                    
                }
            }
            return rpRulePack;
        }
Esempio n. 18
0
 public static O2RulePack createRulePackThatMatchFindings(O2RulePack o2rulePack, List<IO2Finding> o2Findings, string languageDBId)
 {
     return createRulePackThatMatchFindings(o2rulePack, o2Findings, "RulePackThatMatchFindings", languageDBId);
 }
Esempio n. 19
0
        public static O2RulePack createRules_CallBacksOnControlFlowGraphs_And_ExternalSinks(String sCirDataFile)
        {
            var rpRulePack = new O2RulePack();
            if (false == File.Exists(sCirDataFile))
                DI.log.error(
                    "in createRules_CallBacksOnControlFlowGraphs_And_ExternalSinks, provide CirData file not found: {0}",
                    sCirDataFile);
            else
            {
                List<String> lsFunctions = MiscUtils.getFunctionsSignaturesFrom02CirData(sCirDataFile);
                // in this type of scan, there are two rules	    	
                // if functions have a ControlFlowGraph they are Callbacks
                // everything else is a sink	    	

                ICirData fcdCirData = CirLoad.loadSerializedO2CirDataObject(sCirDataFile);
                Dictionary<String, ICirFunction> dFunctionsWithControlFlowGraphs =
                    CirDataUtils.getFunctionsWithControlFlowGraph(fcdCirData);
                foreach (string sFunction in lsFunctions)
                {
                    if (dFunctionsWithControlFlowGraphs.ContainsKey(sFunction))
                        addRule(createRule(O2RuleType.Callback, sFunction, fcdCirData.sDbId), rpRulePack);                        
                    else
                        addRule(createRule(O2RuleType.Sink, sFunction, fcdCirData.sDbId), rpRulePack);                        
                }
            }
            return rpRulePack;
        }
Esempio n. 20
0
 public static List<IO2Rule> getRulesThatAreFromDB(O2RulePack o2RulePack)
 {
     return (from IO2Rule o2Rule in o2RulePack.o2Rules where o2Rule.FromDb select o2Rule).ToList();
 }
 public void setCurrentRulePack(O2RulePack o2RulePack)
 {
     if (o2RulePack == null)
         return;
     currentO2RulePack = o2RulePack;
     indexedCurrentO2Rules = IndexedO2Rules.indexAll(currentO2RulePack.getIO2Rules());
 }
Esempio n. 22
0
 public static string saveRulePack(O2RulePack o2rulePackToSave)
 {
     return saveRulePack(DI.config.TempFileNameInTempDirectory, "",
                         o2rulePackToSave);
 }
Esempio n. 23
0
 public static void addRule(IO2Rule rRule, O2RulePack o2rulePack)
 {
     o2rulePack.o2Rules.Add((O2Rule)rRule);
 }