public static AnalysisSearch.FindingsResult createFindingsResultForSourceAndSink(String sSourceSignature,
                                                                                         String sSinkSignature,
                                                                                         String sFakeActionObjectId,
                                                                                         String sVulnName,
                                                                                         String sVulnType,
                                                                                         String sCallerName,
                                                                                         String sFileName)
        {
            var nfNewFinding = new VirtualTraces.NewFinding();

            nfNewFinding.setFinding_FileName(sFileName);
            nfNewFinding.setFinding_VulnName(sVulnName);
            nfNewFinding.setFinding_VulnType(sVulnType);
            nfNewFinding.setFinding_fakeActionObjectId(sFakeActionObjectId);
            nfNewFinding.setFinding_CallerName(sCallerName);

            CallInvocation ciRootNode = nfNewFinding.setRootTrace(sVulnName);
            CallInvocation ciSource   = nfNewFinding.addCallToCall(sSourceSignature, ciRootNode, TraceType.Source);
            CallInvocation ciNode     = nfNewFinding.addCallToCall(sCallerName, ciSource, TraceType.Root_Call);
            CallInvocation ciSink     = nfNewFinding.addCallToCall(sSinkSignature, ciNode, TraceType.Known_Sink);


            var frFindingsResult = new AnalysisSearch.FindingsResult(nfNewFinding.oadNewO2AssessmentDataOunceV6);

            frFindingsResult.fFinding = nfNewFinding.fFinding;
            frFindingsResult.fFile    = nfNewFinding.fFile;
            return(frFindingsResult);
        }
        public static O2TraceBlock_OunceV6 getTraceBlockToGlueFinding(AssessmentAssessmentFileFinding fFinding,
                                                                      TraceType ttTraceType,
                                                                      O2AssessmentData_OunceV6 oadO2AssessmentDataOunceV6,
                                                                      Dictionary <String, O2TraceBlock_OunceV6> dO2TraceBlock)
        {
            CallInvocation ciCallInvocation =
                AnalysisSearch.findTraceTypeInSmartTrace_Recursive_returnCallInvocation(fFinding.Trace, ttTraceType);

            if (ciCallInvocation == null)
            {
                return(null);
            }
            String sSourceSignature = OzasmtUtils_OunceV6.getStringIndexValue(ciCallInvocation.sig_id, oadO2AssessmentDataOunceV6);
            String sFile            = OzasmtUtils_OunceV6.getFileIndexValue(ciCallInvocation.fn_id, oadO2AssessmentDataOunceV6);
            String sLineNumber      = ciCallInvocation.line_number.ToString();
            String sTraceRootText   = OzasmtUtils_OunceV6.getStringIndexValue(fFinding.Trace[0].sig_id, oadO2AssessmentDataOunceV6);
            String sUniqueName      = String.Format("{0}      {1}      {2}", sSourceSignature, sFile, sLineNumber);

            // need to find a better way to clue the final sinks since at the moment I am getting a couple sinks trown by the cases when a sink also become a source of tainted data
            //String sUniqueName = String.Format("{0} {1} {2} {3}", sSourceSignature, sFile, sLineNumber, sTraceRootText);

            if (false == dO2TraceBlock.ContainsKey(sUniqueName))
            {
                dO2TraceBlock.Add(sUniqueName, new O2TraceBlock_OunceV6());
                dO2TraceBlock[sUniqueName].sSignature     = sSourceSignature;
                dO2TraceBlock[sUniqueName].sFile          = sFile;
                dO2TraceBlock[sUniqueName].sLineNumber    = sLineNumber;
                dO2TraceBlock[sUniqueName].sTraceRootText = sTraceRootText;
                dO2TraceBlock[sUniqueName].sUniqueName    = sUniqueName;
            }
            return(dO2TraceBlock[sUniqueName]);
        }
            public CallInvocation addCallToCall(String sNewCallName, CallInvocation ciTargetCallInvocation,
                                                TraceType ttTraceType)
            {
                var    ciNewCallInvocation = new CallInvocation();
                UInt32 uCall = OzasmtUtils_OunceV6.addTextToStringIndexes(sNewCallName, oadNewO2AssessmentDataOunceV6.arAssessmentRun);

                ciNewCallInvocation.sig_id = uCall;
                ciNewCallInvocation.cxt_id = uCall;
                // by default make these the same (the context is used to remove duplicate findings)
                ciNewCallInvocation.fn_id = 1;
                // add file mapping so that the viewer's can point to the vm file
                ciNewCallInvocation.trace_type = (UInt32)ttTraceType;
                if (ciTargetCallInvocation.CallInvocation1 == null)
                {
                    ciTargetCallInvocation.CallInvocation1 = new[] { ciNewCallInvocation }
                }
                ;
                else
                {
                    var lTargetCallTraces = new List <CallInvocation>(ciTargetCallInvocation.CallInvocation1);
                    lTargetCallTraces.Add(ciNewCallInvocation);
                    ciTargetCallInvocation.CallInvocation1 = lTargetCallTraces.ToArray();
                }
                return(ciNewCallInvocation);
            }
            public CallInvocation setRootTrace(string sRootTraceText)
            {
                var    ciCallInvocation = new CallInvocation();
                UInt32 uRootTraceText   = OzasmtUtils_OunceV6.addTextToStringIndexes(sRootTraceText,
                                                                                     oadNewO2AssessmentDataOunceV6.arAssessmentRun);

                ciCallInvocation.sig_id     = uRootTraceText;
                ciCallInvocation.fn_id      = 1;
                ciCallInvocation.trace_type = (UInt32)TraceType.Root_Call;
                fFinding.Trace = new[] { ciCallInvocation };
                return(ciCallInvocation);
            }
 public static void MakeAllLostSinksIntoKnownSinks(O2AssessmentData_OunceV6 oadO2AssessmentDataOunceV6)
 {
     foreach (AssessmentAssessmentFileFinding fFinding in oadO2AssessmentDataOunceV6.dFindings.Keys)
     {
         CallInvocation ciLostSink =
             AnalysisSearch.findTraceTypeInSmartTrace_Recursive_returnCallInvocation(fFinding.Trace,
                                                                                     TraceType.Lost_Sink);
         if (ciLostSink != null)
         {
             ciLostSink.trace_type = (UInt32)TraceType.Known_Sink;
         }
     }
 }
        public static String getSource(AssessmentAssessmentFileFinding fFinding, O2AssessmentData_OunceV6 oadF1AssessmentDataOunceV6)
        {
            CallInvocation ciCallInvocation =
                AnalysisSearch.findTraceTypeInSmartTrace_Recursive_returnCallInvocation(fFinding.Trace,
                                                                                        TraceType.Source);

            if (ciCallInvocation != null)
            {
                return(OzasmtUtils_OunceV6.getStringIndexValue(ciCallInvocation.sig_id, oadF1AssessmentDataOunceV6));
            }

            return("");
        }
Esempio n. 7
0
            // recursive function that compares two SmartTraces
            public bool areCallInvoctionObjectsEqual(CallInvocation ciExistingCallInvocation,
                                                     CallInvocation ciNewCallInvocation, bool bIgnoreRootCallInvocation)
            {
                // first check if the functions called are different (note that we ignore the value of .fn_id which the one that indicates which file it is used)
                if (false == bIgnoreRootCallInvocation)
                {
//                    if (ciExistingCallInvocation.sig_id != ciNewCallInvocation.sig_id)        // originally i used the signature but that was losing a number of different traces
                    if (ciExistingCallInvocation.cxt_id != ciNewCallInvocation.cxt_id)
                    {
                        // going to use the context id since that is a much better representation of the trace's contents
                        return(false);
                    }
                }
                bIgnoreRootCallInvocation = false; // after the first time always do the check above

                // then check the childs of both trees
                if (ciExistingCallInvocation.CallInvocation1 == null && ciNewCallInvocation.CallInvocation1 == null)
                {
                    // if both are null they are equal
                    return(true);
                }
                if (ciExistingCallInvocation.CallInvocation1 == null || ciNewCallInvocation.CallInvocation1 == null)
                {
                    // if only one of them is null, then they are different
                    return(false);
                }
                if (ciExistingCallInvocation.CallInvocation1.Length != ciNewCallInvocation.CallInvocation1.Length)
                {
                    // if they have different number of child notes they are different
                    return(false);
                }
                for (int i = 0; i < ciExistingCallInvocation.CallInvocation1.Length; i++)
                {
                    if (i < ciNewCallInvocation.CallInvocation1.Length)
                    // need to double check if this is still needed since we now have the lenght check above
                    {
                        bool bResult = areCallInvoctionObjectsEqual(ciExistingCallInvocation.CallInvocation1[i],
                                                                    ciNewCallInvocation.CallInvocation1[i],
                                                                    bIgnoreRootCallInvocation);
                        if (false == bResult)
                        {
                            return(false);
                        }
                    }
                }
                // if we make it this far means they are equal
                return(true);
            }
        // we need to create new CallInvocation Objects because we need to change them
        public static CallInvocation[] updateAssessmentRunWithTraceReferences_recursive(
            List <CallInvocation> lciNewCallInvocation, CallInvocation[] aciOriginalCallInvocation,
            Dictionary <String, UInt32> dNewStringIndex, Dictionary <String, UInt32> dNewFileIndex,
            O2AssessmentData_OunceV6 fadOriginalO2AssessmentDataOunceV6)
        {
            if (aciOriginalCallInvocation == null)
            {
                return(null);
            }
            else
            {
                foreach (CallInvocation ciOriginalCallInvocation in aciOriginalCallInvocation)
                {
                    var ciNewCallInvocation = new CallInvocation();
                    ciNewCallInvocation.cn_id = updateNewAssessmentRunWithStringID(ciOriginalCallInvocation.cn_id,
                                                                                   dNewStringIndex,
                                                                                   fadOriginalO2AssessmentDataOunceV6);
                    ciNewCallInvocation.column_number = ciOriginalCallInvocation.column_number;
                    ciNewCallInvocation.cxt_id        = updateNewAssessmentRunWithStringID(ciOriginalCallInvocation.cxt_id,
                                                                                           dNewStringIndex,
                                                                                           fadOriginalO2AssessmentDataOunceV6);
                    ciNewCallInvocation.fn_id = updateNewAssessmentRunWithFileID(ciOriginalCallInvocation.fn_id,
                                                                                 dNewFileIndex,
                                                                                 fadOriginalO2AssessmentDataOunceV6);
                    ciNewCallInvocation.line_number = ciOriginalCallInvocation.line_number;
                    ciNewCallInvocation.mn_id       = updateNewAssessmentRunWithStringID(ciOriginalCallInvocation.mn_id,
                                                                                         dNewStringIndex,
                                                                                         fadOriginalO2AssessmentDataOunceV6);
                    ciNewCallInvocation.ordinal = ciOriginalCallInvocation.ordinal;
                    ciNewCallInvocation.sig_id  = updateNewAssessmentRunWithStringID(ciOriginalCallInvocation.sig_id,
                                                                                     dNewStringIndex,
                                                                                     fadOriginalO2AssessmentDataOunceV6);
                    ciNewCallInvocation.taint_propagation = ciOriginalCallInvocation.taint_propagation;
                    ciNewCallInvocation.Text       = ciOriginalCallInvocation.Text;
                    ciNewCallInvocation.trace_type = ciOriginalCallInvocation.trace_type;

                    var lciNewCallInvocation_Child = new List <CallInvocation>();
                    ciNewCallInvocation.CallInvocation1 =
                        updateAssessmentRunWithTraceReferences_recursive(lciNewCallInvocation_Child,
                                                                         ciOriginalCallInvocation.CallInvocation1,
                                                                         dNewStringIndex, dNewFileIndex,
                                                                         fadOriginalO2AssessmentDataOunceV6);

                    lciNewCallInvocation.Add(ciNewCallInvocation);
                }
                return(lciNewCallInvocation.ToArray());
            }
        }
 public static void showCallInvocationDetailsInDataGridView(DataGridView dgvDataGridView,
                                                            CallInvocation ciCallInvocation,
                                                            O2AssessmentData_OunceV6 oadAssessmentDataOunceV6)
 {
     if (ciCallInvocation != null)
     {
         try
         {
             dgvDataGridView.Columns.Clear();
             O2Forms.addToDataGridView_Column(dgvDataGridView, "Name", 90);
             O2Forms.addToDataGridView_Column(dgvDataGridView, "Value", -1);
             dgvDataGridView.Rows.Add("sig_id",
                                      OzasmtUtils_OunceV6.getStringIndexValue(ciCallInvocation.sig_id, oadAssessmentDataOunceV6));
             dgvDataGridView.Rows.Add("cxt_id",
                                      OzasmtUtils_OunceV6.getStringIndexValue(ciCallInvocation.cxt_id, oadAssessmentDataOunceV6));
             dgvDataGridView.Rows.Add("fn_id",
                                      OzasmtUtils_OunceV6.getFileIndexValue(ciCallInvocation.fn_id, oadAssessmentDataOunceV6));
             dgvDataGridView.Rows.Add("cn id",
                                      OzasmtUtils_OunceV6.getStringIndexValue(ciCallInvocation.cn_id, oadAssessmentDataOunceV6));
             dgvDataGridView.Rows.Add("trace_type", ciCallInvocation.trace_type.ToString());
             dgvDataGridView.Rows.Add("column_number", ciCallInvocation.column_number.ToString());
             dgvDataGridView.Rows.Add("line_number", ciCallInvocation.line_number.ToString());
             dgvDataGridView.Rows.Add("mn_id",
                                      OzasmtUtils_OunceV6.getStringIndexValue(ciCallInvocation.mn_id, oadAssessmentDataOunceV6));
             dgvDataGridView.Rows.Add("ordinal", ciCallInvocation.ordinal.ToString());
             dgvDataGridView.Rows.Add("taint_propagation", ciCallInvocation.taint_propagation);
             if (ciCallInvocation.Text != null)
             {
                 var sbText = new StringBuilder();
                 foreach (String sLine in ciCallInvocation.Text)
                 {
                     sbText.AppendLine(sLine);
                 }
                 dgvDataGridView.Rows.Add("Text", sbText.ToString());
             }
             //ciCallInvocation.Text;
         }
         catch (Exception ex)
         {
             DI.log.error("in showCallInvocationDetailsInDataGridView :{0}", ex.Message);
         }
     }
 }
        public static String getTextFromFindingBySmartTraceFilter(CallInvocation cCall,
                                                                  O2AssessmentData_OunceV6 fadO2AssessmentDataOunceV6,
                                                                  Analysis.SmartTraceFilter stfSmartTraceFilter)
        {
            String sText = "";

            //case Analysis.SmartTraceFilter.MethodName:  // Use this as the default (since it will cover for the cases where the context or source are empty
            if (cCall.sig_id == 0 && cCall.fn_id > 0)
            {
                sText = fadO2AssessmentDataOunceV6.arAssessmentRun.StringIndeces[cCall.fn_id - 1].value;
            }
            else if (cCall.sig_id == 0)
            {
                sText = "...";
            }
            else
            {
                sText = fadO2AssessmentDataOunceV6.arAssessmentRun.StringIndeces[cCall.sig_id - 1].value;
            }
            switch (stfSmartTraceFilter)
            {
            case Analysis.SmartTraceFilter.Context:
                if (0 != cCall.cxt_id)
                {
                    sText = fadO2AssessmentDataOunceV6.arAssessmentRun.StringIndeces[cCall.cxt_id - 1].value;
                }
                break;

            case Analysis.SmartTraceFilter.SourceCode:
                List <String> lsSourceCode =
                    Files.loadSourceFileIntoList(
                        fadO2AssessmentDataOunceV6.arAssessmentRun.FileIndeces[cCall.fn_id - 1].value);
                String sSounceCodeLine = Files.getLineFromSourceCode(cCall.line_number, lsSourceCode);
                if ("" != sSounceCodeLine)
                {
                    sText = sSounceCodeLine;
                    sText = sText.Replace("\t", "");
                }
                break;
            }
            return(sText);
        }
Esempio n. 11
0
            public static void addSuportForDynamicMethodsOnSinks(TreeView tvRawData, ICirData cdCirData,
                                                                 bool bAddGluedTracesAsRealTraces)
            {
                O2Timer tTimer = new O2Timer("Adding Support for Dynamic Methods on Sinks").start();
                // first get a unique list of Sink Traces
                Dictionary <AssessmentAssessmentFileFinding, O2AssessmentData_OunceV6> dAllSinkFindings =
                    analyzer.getUniqueListOfSinks(tvRawData);

                //List<String> lsMatches = new List<string>();
                foreach (AssessmentAssessmentFileFinding fFinding in dAllSinkFindings.Keys)
                {
                    CallInvocation ciSink =
                        AnalysisSearch.findTraceTypeInSmartTrace_Recursive_returnCallInvocation(fFinding.Trace,
                                                                                                TraceType.
                                                                                                Known_Sink);
                    if (ciSink != null)
                    {
                        String sContext = OzasmtUtils_OunceV6.getStringIndexValue(ciSink.cxt_id, dAllSinkFindings[fFinding]);
//                        var fsFilteredSignature = new FilteredSignature(sContext);
                        if (sContext.IndexOf("java.lang.Object.getClass()") > -1 && sContext.IndexOf("new") > -1 &&
                            sContext.IndexOf("$") > -1)
                        {
                            // we have a match lets get the class out
                            String sClass = sContext.Substring(sContext.IndexOf("new") + 4);
                            sClass = sClass.Substring(0, sClass.IndexOf(' '));

                            // Find traces that match the found class and add them as GluedSinks
                            foreach (TreeNode tnMatchNode in tvRawData.Nodes)
                            {
                                if (tnMatchNode.Text.IndexOf(sClass) > -1)
                                {
                                    addFindingAsGlueTrace((O2TraceBlock_OunceV6)tnMatchNode.Tag, fFinding,
                                                          dAllSinkFindings[fFinding], tvRawData,
                                                          bAddGluedTracesAsRealTraces);
                                }
                            }
                        }
                    }
                }

                tTimer.stop();
            }
        public static String getUniqueSignature(AssessmentAssessmentFileFinding fFinding, TraceType ttTraceType,
                                                O2AssessmentData_OunceV6 oadO2AssessmentDataOunceV6, bool bShowFullPathForFileName)
        {
            CallInvocation ciCallInvocation =
                AnalysisSearch.findTraceTypeInSmartTrace_Recursive_returnCallInvocation(fFinding.Trace, ttTraceType);

            if (ciCallInvocation == null)
            {
                return(null);
            }
            String sSourceSignature = OzasmtUtils_OunceV6.getStringIndexValue(ciCallInvocation.sig_id, oadO2AssessmentDataOunceV6);
            String sFile            = OzasmtUtils_OunceV6.getFileIndexValue(ciCallInvocation.fn_id, oadO2AssessmentDataOunceV6);
            String sLineNumber      = ciCallInvocation.line_number.ToString();

            if (bShowFullPathForFileName)
            {
                return(String.Format("{0}      {1}      {2}", sSourceSignature, sFile, sLineNumber));
            }
            else
            {
                return(String.Format("{0}      {1}      {2}", sSourceSignature, Path.GetFileName(sFile), sLineNumber));
            }
        }
        public static void createAssessmentFileWithVirtualTraces_fromTwoSourceAssessmentFiles(String sAssessmentFile1,
                                                                                              String sAssessmentFile2,
                                                                                              String sTargetFile)
        {
            O2AssessmentData_OunceV6 fadF1AssessmentData_sAssessmentFile1 = null;
            O2AssessmentData_OunceV6 fadF1AssessmentData_sAssessmentFile2 = null;


            // get list of traces with
            List <AssessmentAssessmentFileFinding> lfFindingsWithTraces_sAssessmentFile2 =
                AnalysisUtils.getListOfAllFindingsWithTraces(sAssessmentFile2, ref fadF1AssessmentData_sAssessmentFile2);

            // calculate traces to join
            var dTracesToAppend = new Dictionary <String, List <CallInvocation> >();

            foreach (AssessmentAssessmentFileFinding fFinding in lfFindingsWithTraces_sAssessmentFile2)
            {
                if (fFinding.Trace != null && fFinding.Trace[0] != null && fFinding.Trace[0].CallInvocation1 != null &&
                    fFinding.Trace[0].CallInvocation1.Length > 1)
                {
                    if (
                        OzasmtUtils_OunceV6.getStringIndexValue(fFinding.Trace[0].CallInvocation1[0].sig_id,
                                                                fadF1AssessmentData_sAssessmentFile2).IndexOf(
                            sExternalSourceString) > -1)
                    {
                        String sSignatureOfCallbackFunction =
                            OzasmtUtils_OunceV6.getStringIndexValue(fFinding.Trace[0].CallInvocation1[1].sig_id,
                                                                    fadF1AssessmentData_sAssessmentFile2);
                        if (false == dTracesToAppend.ContainsKey(sSignatureOfCallbackFunction))
                        {
                            dTracesToAppend.Add(sSignatureOfCallbackFunction, new List <CallInvocation>());
                        }

                        dTracesToAppend[sSignatureOfCallbackFunction].Add(fFinding.Trace[0].CallInvocation1[1]);
                    }
                }
            }


            // get sinks to append traces
            List <String> lsSinks_sAssessmentFile1 = AnalysisAssessmentFile.getListOf_KnownSinks(sAssessmentFile1, ref fadF1AssessmentData_sAssessmentFile1);

            Analysis.populateDictionariesWithXrefsToLoadedAssessment(Analysis.FindingFilter.SmartTraces, true, true,
                                                                     fadF1AssessmentData_sAssessmentFile1);

            var dNewStringIndex = new Dictionary <String, UInt32>();

            foreach (
                AssessmentRunStringIndex siStringIndex in
                fadF1AssessmentData_sAssessmentFile1.arAssessmentRun.StringIndeces)
            {
                dNewStringIndex.Add(siStringIndex.value, siStringIndex.id);
            }
            var dNewFileIndex = new Dictionary <String, UInt32>();

            foreach (AssessmentRunFileIndex siStringIndex in fadF1AssessmentData_sAssessmentFile1.arAssessmentRun.FileIndeces)
            {
                dNewFileIndex.Add(siStringIndex.value, siStringIndex.id);
            }

            TraceType tTraceType = TraceType.Known_Sink;

            foreach (String sSink in lsSinks_sAssessmentFile1)
            {
                if (dTracesToAppend.ContainsKey(sSink))
                {
                    List <AssessmentAssessmentFileFinding> lfFindingsWithSink =
                        AnalysisUtils.getListOfFindingsWithTraceAndSignature(sSink, tTraceType,
                                                                             fadF1AssessmentData_sAssessmentFile1);
                    foreach (AssessmentAssessmentFileFinding fFindingToJoin in lfFindingsWithSink)
                    {
                        var lfNewFindinds = new List <AssessmentAssessmentFileFinding>();

                        foreach (CallInvocation ciCallInvocationToAppend in dTracesToAppend[sSink])
                        {
                            // append trace

                            AssessmentAssessmentFileFinding fNewFinding = createNewFindingFromExistingOne(
                                fFindingToJoin, dNewStringIndex, dNewFileIndex, fadF1AssessmentData_sAssessmentFile1);
                            CallInvocation ciSinkNode =
                                AnalysisSearch.findTraceTypeAndSignatureInSmartTrace_Recursive_returnCallInvocation(
                                    fNewFinding.Trace, tTraceType, sSink, fadF1AssessmentData_sAssessmentFile1);
                            ciSinkNode.trace_type = (int)TraceType.Source;
                            var lciTempNewCallInvocation = new List <CallInvocation>(); // used by the recursive function
                            ciSinkNode.CallInvocation1 = updateAssessmentRunWithTraceReferences_recursive(
                                lciTempNewCallInvocation,
                                //new CallInvocation[] { ciCallInvocationToAppend },
                                ciCallInvocationToAppend.CallInvocation1,
                                dNewStringIndex,
                                dNewFileIndex,
                                fadF1AssessmentData_sAssessmentFile2);

                            lfNewFindinds.Add(fNewFinding);
                        }
                        AssessmentAssessmentFile fFile = fadF1AssessmentData_sAssessmentFile1.dFindings[fFindingToJoin];
                        var lfFindingsInCurrentFile    = new List <AssessmentAssessmentFileFinding>(fFile.Finding);
                        lfFindingsInCurrentFile.Remove(fFindingToJoin);
                        lfFindingsInCurrentFile.AddRange(lfNewFindinds);
                        fFile.Finding = lfFindingsInCurrentFile.ToArray();
                    }
                }
            }

            // update indexes
            fadF1AssessmentData_sAssessmentFile1.arAssessmentRun.StringIndeces =
                OzasmtUtils_OunceV6.createStringIndexArrayFromDictionary(dNewStringIndex);
            fadF1AssessmentData_sAssessmentFile1.arAssessmentRun.FileIndeces =
                OzasmtUtils_OunceV6.createFileIndexArrayFromDictionary(dNewFileIndex);

            //String sTargetFile = config.getTempFileNameInF1TempDirectory();
            OzasmtUtils_OunceV6.createSerializedXmlFileFromAssessmentRunObject(
                fadF1AssessmentData_sAssessmentFile1.arAssessmentRun, sTargetFile);
            DI.log.debug("Joined assesment saved to:{0}", sTargetFile);
        }
            public bool appendTrace_FindingSourceToFindingSink(AssessmentAssessmentFileFinding fJoinAtSink,
                                                               FindingViewItem fviJoinAtSource)
            {
                //Get the Sink of the first trace
                CallInvocation ciSinkNode =
                    AnalysisSearch.findTraceTypeInSmartTrace_Recursive_returnCallInvocation(fJoinAtSink.Trace,
                                                                                            TraceType.Known_Sink);

                if (ciSinkNode == null)
                {
                    //              DI.log.error("in appendTrace_FindingSourceToFindingSink, could not find the Sink of fviJoinAtSink");
                    return(false);
                }

                // get the source of the 2nd trace

                // There are 3 possible Gluing Scenarios
                //   a source that has child nodes (when it is a callback)
                //   a source trace that has a compatible signature with the sink trace (when it was creted via a source of tainded data rule).  For this one we will have to find the correct injection point
                //   a source trace that has nothing do with the source (interfaces gluing for example) and we have the same two cases above
                // the strategy to find a gluing point (on the fviJoinAtSource is to find the first trace that has a sink

                // try to get case 1 see if the current source has child nodes
                CallInvocation ciSourceNode =
                    AnalysisSearch.findTraceTypeInSmartTrace_Recursive_returnCallInvocation(
                        fviJoinAtSource.fFinding.Trace, TraceType.Source);

                if (ciSourceNode == null)
                {
                    DI.log.error(
                        "in appendTrace_FindingSourceToFindingSink, could not find the Source of fviJoinAtSource");
                    return(false);
                }

                if (ciSourceNode.CallInvocation1 == null) // means we are case 2 or 3
                {
                    CallInvocation ciSourceNodeWithSink =
                        AnalysisSearch.fromSourceFindFirstTraceWithAChildSink(fviJoinAtSource.fFinding,
                                                                              fviJoinAtSource.oadO2AssessmentDataOunceV6);
                    if (ciSourceNodeWithSink != null)
                    {
                        // if we found this it means that we are now on Trace that the first child node goes to the source and the 2nd goes to the Sink
                        ciSourceNode = ciSourceNodeWithSink.CallInvocation1[1];
                    }
                }

                // make the previous Sink that Type 4 that doesn't seem to be used (could make it sources but it is cleaner with using this extra trace type for the joins
                ciSinkNode.trace_type = (int)TraceType.Type_4;


                CallInvocation[] aciCallInvocation;
                if (AnalysisUtils.getSink(fJoinAtSink, oadNewO2AssessmentDataOunceV6) ==
                    AnalysisUtils.getSource(fviJoinAtSource.fFinding, fviJoinAtSource.oadO2AssessmentDataOunceV6))
                {
                    aciCallInvocation = ciSourceNode.CallInvocation1;
                }
                else
                {
                    aciCallInvocation = new[] { ciSourceNode }
                };
                var lciTempNewCallInvocation = new List <CallInvocation>(); // used by the recursive function

                ciSinkNode.CallInvocation1 = updateAssessmentRunWithTraceReferences_recursive(
                    lciTempNewCallInvocation,
                    aciCallInvocation,
                    dNewStringIndex,
                    dNewFileIndex,
                    fviJoinAtSource.oadO2AssessmentDataOunceV6);


                return(true);
            }
Esempio n. 15
0
            public static void findSpringAttributes(TreeView tvRawData)
            {
                String  sFunctionSignature = "ModelMap.addAttribute";
                O2Timer tTimer             = new O2Timer("Resolving attribute based function: {0} ").start();

                Dictionary <AssessmentAssessmentFileFinding, O2AssessmentData_OunceV6> dMatches =
                    analyzer.getSinksFindingsThatMatchRegEx(tvRawData, sFunctionSignature);

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

                    // create a unique name for it:
                    String sSink = AnalysisUtils.getSink(fFinding, dMatches[fFinding]);
                    String sSinkWithAttributeName = sSink.Replace("(", "_" + sSpringParameter + "(");
                    // make sure we have not added this already
                    if (sSink.IndexOf(sSpringParameter) == -1)
                    {
                        //     String sSinkWithAttributeName = sSink.Replace("(", "_" + sSpringParameter + "(");
                        //      String sSinkWithAttributeName = sSpringParameter;
                        String sUniqueSignature = analyzer.getUniqueSignature(fFinding, TraceType.Known_Sink,
                                                                              dMatches[fFinding], true);
                        var otbO2TraceBlockOfThisFinding = (O2TraceBlock_OunceV6)tvRawData.Nodes[sUniqueSignature].Tag;

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

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


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