示例#1
0
 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;
 }
        public static CallInvocation getCallInvocationObjectFromO2Trace(IO2Trace o2Trace, Dictionary <string, uint> dStringIndexes, Dictionary <string, uint> dFilesIndexes)
        {
            //  return new CallInvocation();
            var callInvocation = new CallInvocation
            {
                cn_id             = addTextToStringIndexes(o2Trace.clazz, dStringIndexes),
                column_number     = o2Trace.columnNumber,
                cxt_id            = addTextToStringIndexes(o2Trace.context, dStringIndexes),
                fn_id             = addTextToFileIndexes(o2Trace.file, dFilesIndexes),
                line_number       = o2Trace.lineNumber,
                mn_id             = addTextToStringIndexes(o2Trace.method, dStringIndexes),
                ordinal           = o2Trace.ordinal,
                sig_id            = addTextToStringIndexes(o2Trace.signature, dStringIndexes),
                taint_propagation = o2Trace.taintPropagation,
                Text       = o2Trace.text.ToArray(),
                trace_type = Convert.ToUInt32(o2Trace.traceType)
            };

            if (o2Trace.childTraces != null) // means there are child traces
            {
                var childCallInvocation = new List <CallInvocation>();
                foreach (O2Trace childO2trace in o2Trace.childTraces)
                {
                    childCallInvocation.Add(getCallInvocationObjectFromO2Trace(childO2trace, dStringIndexes, dFilesIndexes));
                }
                callInvocation.CallInvocation1 = childCallInvocation.ToArray();
            }
            return(callInvocation);
        }
        public static String getLineFromSourceCode(CallInvocation ciCallInvocation, O2AssessmentData_OunceV6 fadO2AssessmentDataOunceV6)
        {
            List <string> lsSourceCode =
                Files.loadSourceFileIntoList(
                    fadO2AssessmentDataOunceV6.arAssessmentRun.FileIndeces[ciCallInvocation.fn_id - 1].value);

            return(Files.getLineFromSourceCode(ciCallInvocation.line_number, lsSourceCode));
        }
示例#4
0
 public static void getListWithMethodsCalled_Recursive(CallInvocation[] cCallInvocations,
                                                       List<CallInvocation> lciMethodsCalled,
                                                       O2AssessmentData_OunceV6 fadO2AssessmentDataOunceV6,
                                                       Analysis.SmartTraceFilter stfSmartTraceFilter)
 {
     if (cCallInvocations != null)
         foreach (CallInvocation cCall in cCallInvocations)
         {
             lciMethodsCalled.Add(cCall);
             //lsMethodsCalled.Add(getTextFromFindingBySmartTraceFilter(cCall,fadO2AssessmentDataOunceV6,stfSmartTraceFilter));
             getListWithMethodsCalled_Recursive(cCall.CallInvocation1, lciMethodsCalled, fadO2AssessmentDataOunceV6,
                                                stfSmartTraceFilter);
         }
 }
示例#5
0
 public static bool doesIdExistInSmartTraceCall_Recursive(CallInvocation[] cCallInvocations,
                                                          UInt32 uSmartTraceCallID, TraceType tTraceType)
 {
     foreach (CallInvocation cCallInvocation in cCallInvocations)
     {
         if (cCallInvocation.sig_id == uSmartTraceCallID && cCallInvocation.trace_type == (int) tTraceType)
             return true;
         if (null != cCallInvocation.CallInvocation1)
         {
             bool bResult = doesIdExistInSmartTraceCall_Recursive(cCallInvocation.CallInvocation1,
                                                                  uSmartTraceCallID, tTraceType);
             if (bResult)
                 return bResult;
         }
     }
     return false;
 }
示例#6
0
 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);
         }
     }
 }
示例#7
0
 private String getSmartTraceCallName(AssessmentRun arAssessmentRun, CallInvocation[] cCallInvocation,
                                      TraceType tTraceType)
 {
     int iSmartTraceIndex = AnalysisSearch.findTraceTypeInSmartTrace_Recursive_returnSigId(cCallInvocation,
                                                                                           tTraceType);
     if (iSmartTraceIndex > 0)
         return arAssessmentRun.StringIndeces[iSmartTraceIndex - 1].value;
     else
         return "";
 }
示例#8
0
 private String resolveSink(AssessmentRun arAssessmentRun, CallInvocation[] cCallInvocation)
 {
     String sSink = getSmartTraceCallName(arAssessmentRun, cCallInvocation, TraceType.Known_Sink);
     if (sSink != "") // LostSink case
         sSink = "Sink: " + sSink;
     else
         sSink = "LostSink: " +
                 getSmartTraceCallName(arAssessmentRun, cCallInvocation, TraceType.Lost_Sink);
     return sSink;
 }
示例#9
0
 private String resolveSource(AssessmentRun arAssessmentRun, CallInvocation[] cCallInvocation)
 {
     String sSource = "Source: " +
                      getSmartTraceCallName(arAssessmentRun, cCallInvocation, TraceType.Source);
     return sSource;
 }
        public static CallInvocation getCallInvocationObjectFromO2Trace(IO2Trace o2Trace, Dictionary<string, uint> dStringIndexes, Dictionary<string, uint> dFilesIndexes)
        {
          //  return new CallInvocation();
            var callInvocation = new CallInvocation
                                     {
                                         cn_id = addTextToStringIndexes(o2Trace.clazz, dStringIndexes),
                                         column_number = o2Trace.columnNumber,
                                         cxt_id = addTextToStringIndexes(o2Trace.context, dStringIndexes),
                                         fn_id = addTextToFileIndexes(o2Trace.file, dFilesIndexes),
                                         line_number = o2Trace.lineNumber,
                                         mn_id = addTextToStringIndexes(o2Trace.method, dStringIndexes),
                                         ordinal = o2Trace.ordinal,
                                         sig_id = addTextToStringIndexes(o2Trace.signature, dStringIndexes),
                                         taint_propagation = o2Trace.taintPropagation,
                                         Text = o2Trace.text.ToArray(),
                                         trace_type = Convert.ToUInt32(o2Trace.traceType)
                                     };

            if (o2Trace.childTraces != null) // means there are child traces
            {
                var childCallInvocation = new List<CallInvocation>();
                foreach (O2Trace childO2trace in o2Trace.childTraces)
                    childCallInvocation.Add(getCallInvocationObjectFromO2Trace(childO2trace, dStringIndexes, dFilesIndexes));
                callInvocation.CallInvocation1 = childCallInvocation.ToArray();
            }            
            return callInvocation;
        }
示例#11
0
 public static String getSmartTraceNameOfTraceType(CallInvocation[] cCallInvocations,
                                                   TraceType tTraceType,
                                                   O2AssessmentData_OunceV6 fadO2AssessmentDataOunceV6)
 {
     if (cCallInvocations != null)
     {
         int iActionObjectId = AnalysisSearch.findTraceTypeInSmartTrace_Recursive_returnSigId(cCallInvocations,
                                                                                              tTraceType);
         if (iActionObjectId > 0)
             return fadO2AssessmentDataOunceV6.arAssessmentRun.StringIndeces[iActionObjectId - 1].value;
     }
     return "";
 }
示例#12
0
        /* public static CallInvocation findTraceTypeInSmartTrace_Recursive_returnCallInvocationBelowTraceFound(CallInvocation[] cCallInvocations, Analysis.TraceType tTraceType, CallInvocation ciPreviousCallInvocation)
        {
            if (cCallInvocations != null)
                foreach (CallInvocation cCallInvocation in cCallInvocations)
                {
                    if (cCallInvocation.trace_type == (int)tTraceType)
                    {
                        if (ciPreviousCallInvocation.CallInvocation1.Length == 1)
                        {
                             DI.log.error("in findTraceTypeInSmartTrace_Recursive_returnCallInvocationBelowTraceFound: trace of type {0} did not had a node below", tTraceType.ToString());
                            return ciPreviousCallInvocation.CallInvocation1[0];         // this is actually a bad case
                        }
                        else
                            // now that we found the trace we need to get the one below it
                            return ciPreviousCallInvocation.CallInvocation1[1];
                    }
                    if (null != cCallInvocation.CallInvocation1)
                    {
                        CallInvocation ciResult = findTraceTypeInSmartTrace_Recursive_returnCallInvocationBelowTraceFound(cCallInvocation.CallInvocation1, tTraceType, cCallInvocation);
                        if (ciResult != null)
                            return ciResult;
                    }
                }
            return null;
        }*/


        public static CallInvocation findTraceTypeAndSignatureInSmartTrace_Recursive_returnCallInvocation(
            CallInvocation[] cCallInvocations, TraceType tTraceType, String sSignature,
            O2AssessmentData_OunceV6 fadO2AssessmentDataOunceV6)
        {
            foreach (CallInvocation cCallInvocation in cCallInvocations)
            {
                if (cCallInvocation.trace_type == (int) tTraceType &&
                    sSignature == OzasmtUtils_OunceV6.getStringIndexValue(cCallInvocation.sig_id, fadO2AssessmentDataOunceV6))
                    return cCallInvocation;
                if (null != cCallInvocation.CallInvocation1)
                {
                    CallInvocation ciResult =
                        findTraceTypeAndSignatureInSmartTrace_Recursive_returnCallInvocation(
                            cCallInvocation.CallInvocation1, tTraceType, sSignature, fadO2AssessmentDataOunceV6);
                    if (ciResult != null)
                        return ciResult;
                }
            }
            return null;
        }
示例#13
0
 public static bool findTraceTypeInSmartTrace_Recursive_returnReverseListOfCallInvocation(
     CallInvocation[] cCallInvocations, TraceType tTraceType,
     List<CallInvocation> lcaReverseListOfCallInvocation)
 {
     if (cCallInvocations != null && lcaReverseListOfCallInvocation != null)
         foreach (CallInvocation cCallInvocation in cCallInvocations)
         {
             if (cCallInvocation.trace_type == (int) tTraceType) // when we found it start populating the list
             {
                 lcaReverseListOfCallInvocation.Add(cCallInvocation);
                 return true;
             }
             if (null != cCallInvocation.CallInvocation1)
             {
                 if (
                     findTraceTypeInSmartTrace_Recursive_returnReverseListOfCallInvocation(
                         cCallInvocation.CallInvocation1, tTraceType, lcaReverseListOfCallInvocation))
                 {
                     // means we had a match on a lower node so we need to add the current one
                     lcaReverseListOfCallInvocation.Add(cCallInvocation);
                     return true;
                 }
             }
         }
     return false;
 }
示例#14
0
 public static CallInvocation findTraceTypeInSmartTrace_Recursive_returnCallInvocation(
     CallInvocation[] cCallInvocations, TraceType tTraceType)
 {
     if (cCallInvocations != null)
         foreach (CallInvocation cCallInvocation in cCallInvocations)
         {
             if (cCallInvocation.trace_type == (int) tTraceType)
                 return cCallInvocation;
             if (null != cCallInvocation.CallInvocation1)
             {
                 CallInvocation ciResult =
                     findTraceTypeInSmartTrace_Recursive_returnCallInvocation(cCallInvocation.CallInvocation1,
                                                                              tTraceType);
                 if (ciResult != null)
                     return ciResult;
             }
         }
     return null;
 }
示例#15
0
        // trace_type values
        //    1 = root 
        //    2 = source
        //    3 = sink
        //    4 = ??
        //    5 = lost sink

        public static int findTraceTypeInSmartTrace_Recursive_returnSigId(CallInvocation[] cCallInvocations,
                                                                          TraceType tTraceType)
        {
            if (cCallInvocations != null)
                foreach (CallInvocation cCallInvocation in cCallInvocations)
                {
                    if (cCallInvocation.trace_type == (int) tTraceType)
                        return (int) cCallInvocation.sig_id;
                    if (null != cCallInvocation.CallInvocation1)
                    {
                        int iResult = findTraceTypeInSmartTrace_Recursive_returnSigId(cCallInvocation.CallInvocation1,
                                                                                      tTraceType);
                        if (iResult != -1)
                            return iResult;
                    }
                }
            return -1;
        }
示例#16
0
            public bool findTextInSmartTrace_Recursive(CallInvocation[] cCallInvocations,
                                                       SearchCriteria scSearchCriteria, List<CallInvocation> lciMatches,
                                                       AssessmentAssessmentFileFinding fFinding,
                                                       O2AssessmentData_OunceV6 fadO2AssessmentDataOunceV6)
            {
                if (cCallInvocations == null)
                    return false;
                foreach (CallInvocation ciCallInvocation in cCallInvocations)
                {
                    // execute searches
                    String sTextToSearch = "";
                    switch (scSearchCriteria.stSearchType)
                    {
                        case SearchType.Trace_Text:
                            sTextToSearch = OzasmtUtils_OunceV6.getStringIndexValue(ciCallInvocation.sig_id, fadO2AssessmentDataOunceV6);
                            break;
                        case SearchType.Trace_Context:
                            sTextToSearch = OzasmtUtils_OunceV6.getStringIndexValue(ciCallInvocation.cxt_id, fadO2AssessmentDataOunceV6);
                            break;
                        case SearchType.Trace_SourceCode:
                            if (ciCallInvocation.line_number > 0)
                                sTextToSearch = OzasmtUtils_OunceV6.getLineFromSourceCode(ciCallInvocation, fadO2AssessmentDataOunceV6);
                            break;
                    }

                    if (scSearchCriteria.bNegativeSearch)
                    {
                        if (RegEx.execRegExOnText_hasMatches(scSearchCriteria.reRegex, sTextToSearch))
                            // if we have a match remove this trace
                            return true;
                    }
                    else if (sTextToSearch != "")
                    {
                        searchInStringAndAddFindingResult(sTextToSearch, scSearchCriteria, fFinding, fadO2AssessmentDataOunceV6);
                        //  // stop searching when we have a match                            
                    }
                    // transverse the other call
                    if (null != ciCallInvocation.CallInvocation1)
                        if (findTextInSmartTrace_Recursive(ciCallInvocation.CallInvocation1, scSearchCriteria,
                                                           lciMatches, fFinding, fadO2AssessmentDataOunceV6))
                            return true;
                }
                return false;
            }
示例#17
0
        /* public void showFindingInWebBrowser(WebBrowser wbTargetWebBrowser, UInt32 uLineNumber)
        {

            if (uLineNumber > 0)
            {
                uLineNumber--;
                if (uLineNumber > lsSourceCode.Count)
                {
                     DI.log.error("In showFindingInWebBrowser uLineNumber > lsSourceCode.Count");
                    return;
                }
                else
                {
                    lsSourceCode[(int)uLineNumber] = "<font color='red'><b>" + lsSourceCode[(int)uLineNumber] + "</b></font>";
                    int iNumberOfLinesToShowBefore = 15;
                    int iNumberOfLinesToShowAfter = 20;
                    int iNumberOfLinesToShow = iNumberOfLinesToShowBefore + iNumberOfLinesToShowAfter;
                    String sConvertedSourceCode = "";
                    int iStartSection = ((int)uLineNumber - iNumberOfLinesToShowBefore > 0) ? (int)uLineNumber - iNumberOfLinesToShowBefore : 0;
                    int iSectionLength = (lsSourceCode.Count - ((int)uLineNumber + iNumberOfLinesToShow) < 1) ? lsSourceCode.Count - (int)uLineNumber + iNumberOfLinesToShowBefore : iNumberOfLinesToShow;
                    if (iSectionLength > lsSourceCode.Count - iStartSection)
                        iSectionLength = lsSourceCode.Count - iStartSection - 1;
                    for (int i = iStartSection; i < (iStartSection + iSectionLength); i++)
                    {
                        int iIndexOfComment = lsSourceCode[i].IndexOf("//");
                        if (iIndexOfComment != -1)
                            lsSourceCode[i] = lsSourceCode[i].Substring(0, iIndexOfComment) + "<font color='darkgreen'>" + lsSourceCode[i].Substring(iIndexOfComment) + "</font>";
                        int iIndexOfDot = lsSourceCode[i].IndexOf('.');
                        if (iIndexOfDot != -1)
                        {
                            int iIndexOfParentis = lsSourceCode[i].Substring(iIndexOfDot).IndexOf('(');
                            if (iIndexOfParentis != -1)
                            {
                                String sToReplace = lsSourceCode[i].Substring(iIndexOfDot, iIndexOfParentis);
                                lsSourceCode[i] = lsSourceCode[i].Replace(sToReplace, "<b>" + sToReplace + "</b>");
                            }
                        }

                    }
                    for (int i = iStartSection; i < (iStartSection + iSectionLength); i++)
                        sConvertedSourceCode += i.ToString() + "  :  " + lsSourceCode[i].Replace("\t", "&nbsp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;") + "<br/>";

                    // apply global formating (this should be done in a complete different way (at least RegEx should be used :)  )
                    sConvertedSourceCode = "<font face='Verdana' size='1'>" + sConvertedSourceCode + "</font>";
                    sConvertedSourceCode = sConvertedSourceCode.Replace("{", "<font color='gray'>{</font>").Replace("}", "<font color='gray'>}</font>");
                    sConvertedSourceCode = sConvertedSourceCode.Replace("try", "<font color='darkblue'><b>try</b></font>");
                    sConvertedSourceCode = sConvertedSourceCode.Replace("catch", "<font color='darkblue'><b>catch</b></font>");
                    sConvertedSourceCode = sConvertedSourceCode.Replace("public", "<font color='darkblue'><b>public</b></font>");
                    sConvertedSourceCode = sConvertedSourceCode.Replace("private", "<font color='darkblue'><b>private</b></font>");
                    wbSourceCodeSnippet_Finding.DocumentText = sConvertedSourceCode;
                }
            }
            else
            {
                 DI.log.error("In showFindingInWebBrowser uLineNumber was <1 ");
                wbSourceCodeSnippet_Finding.DocumentText = "";
            }
        }
        */

        public void showSmartTraceInTreeView(TreeView tvTargetTreeView, CallInvocation[] cCallInvocations,
                                             AssessmentAssessmentFileFinding fSelectedFinding)
        {
            tvTargetTreeView.Nodes.Clear();
            //String sNodeText = (fSelectedFinding.caller_name != null) ? fSelectedFinding.caller_name : Analysis.getStringIndexValue(UInt32.Parse(fSelectedFinding.caller_name_id), oadAssessmentData); 
            String sNodeText = "O2 Trace";
            var tnRootNode = new TreeNode(sNodeText);
            tnRootNode.Tag = fSelectedFinding;
            AnalysisUtils.addCallsToNode_Recursive(cCallInvocations, tnRootNode, oadAssessmentData, stfSmartTraceFilter);
            tvTargetTreeView.Nodes.Add(tnRootNode.Nodes[0]);
            tvTargetTreeView.ExpandAll();
        }
示例#18
0
        // 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 String getLineFromSourceCode(CallInvocation ciCallInvocation, O2AssessmentData_OunceV6 fadO2AssessmentDataOunceV6)
 {
     List<string> lsSourceCode =
         Files_WinForms.loadSourceFileIntoList(
             fadO2AssessmentDataOunceV6.arAssessmentRun.FileIndeces[ciCallInvocation.fn_id - 1].value);
     return Files.getLineFromSourceCode(ciCallInvocation.line_number, lsSourceCode);
 }
示例#20
0
 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 List<IO2Trace> getO2TraceFromCallInvocation(CallInvocation[] callInvocations,
                                                                  AssessmentRun assessmentRun)
        {
            var o2Traces = new List<IO2Trace>();
            if (callInvocations != null)
            {
                foreach (CallInvocation callInvocation in callInvocations)
                {
                    var o2Trace = new O2Trace
                                      {
                                          clazz = getStringIndexValue(callInvocation.cn_id, assessmentRun),
                                          columnNumber = callInvocation.column_number,
                                          context = getStringIndexValue(callInvocation.cxt_id, assessmentRun),
                                          file = getFileIndexValue(callInvocation.fn_id, assessmentRun),
                                          lineNumber = callInvocation.line_number,
                                          method = getStringIndexValue(callInvocation.mn_id, assessmentRun),
                                          ordinal = callInvocation.ordinal,
                                          // for the signature try to use the sig_id and if that is 0 then use mn_id
                                          signature = getStringIndexValue((callInvocation.sig_id != 0) ? callInvocation.sig_id : callInvocation.mn_id, assessmentRun),
                                          taintPropagation = callInvocation.taint_propagation,
                                          traceType =
                                              (TraceType)
                                              Enum.Parse(typeof(TraceType),
                                                         callInvocation.trace_type.ToString())
                                      };
                    if (callInvocation.Text != null)
                        o2Trace.text = new List<string>(callInvocation.Text);

                    //if (callInvocation.CallInvocation1 != null) // means there are child traces
                    //{
                    o2Trace.childTraces = getO2TraceFromCallInvocation(callInvocation.CallInvocation1, assessmentRun);
                    /*new List<O2Trace>();
                    
                    foreach (CallInvocation childCallInvocation in callInvocation.CallInvocation1)
                        o2Trace.childTraces.Add(getO2TraceFromCallInvocation(childCallInvocation, assessmentRun));*/
                    //}
                    o2Traces.Add(o2Trace);
                }
            }
            return o2Traces;
        }
示例#22
0
 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;
 }
示例#23
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;
            }
示例#24
0
        public static void addCallsToNode_Recursive(CallInvocation[] cCallInvocations, TreeNode tnTargetNode,
                                                    O2AssessmentData_OunceV6 fadO2AssessmentDataOunceV6,
                                                    Analysis.SmartTraceFilter stfSmartTraceFilter)
        {
            if (cCallInvocations != null)
                foreach (CallInvocation cCall in cCallInvocations)
                {
                    String sNodeText = "";
                    if (cCall.mn_id > fadO2AssessmentDataOunceV6.arAssessmentRun.StringIndeces.Length ||
                        cCall.sig_id > fadO2AssessmentDataOunceV6.arAssessmentRun.StringIndeces.Length)
                        DI.log.error(
                            "In addCallsToNode_Recursive cCall.sig_id or cCall.cxt_id or fadO2AssessmentDataOunceV6.arAssessmentRun.StringIndeces.Length ");
                    else
                    {
                        sNodeText =
                            getTextFromFindingBySmartTraceFilter(cCall, fadO2AssessmentDataOunceV6, stfSmartTraceFilter).Trim();
                        /*switch (stfSmartTraceFilter)
                        {
                            case Analysis.SmartTraceFilter.MethodName:
                                sNodeText = (cCall.sig_id == 0) ? "" : fadO2AssessmentDataOunceV6.arAssessmentRun.StringIndeces[cCall.sig_id - 1].value;
                                break;
                            case Analysis.SmartTraceFilter.Context:
                                sNodeText = (cCall.cxt_id == 0) ? "" : fadO2AssessmentDataOunceV6.arAssessmentRun.StringIndeces[cCall.cxt_id - 1].value;
                                break;
                            case Analysis.SmartTraceFilter.SourceCode:
                                List<String> lsSourceCode = forms.loadSourceFileIntoList(fadO2AssessmentDataOunceV6.arAssessmentRun.FileIndeces[cCall.fn_id - 1].value);
                                sNodeText = getLineFromSourceCode(cCall.line_number, lsSourceCode);
                                sNodeText = sNodeText.Replace("\t", "");
                                break;
                        }*/
                    }

                    var tnCallNode = new TreeNode(sNodeText) {Tag = cCall};
                    switch (cCall.trace_type)
                    {
                        case 1: // Analysis.TraceType.Root_Call:                        
                            tnCallNode.ForeColor = Color.DarkBlue;
                            break;
                        case 5: // Analysis.TraceType.Lost_Sink:
                            tnCallNode.ForeColor = Color.DarkOrange;
                            break;
                        case 2: // Analysis.TraceType.Source:
                            tnCallNode.ForeColor = Color.DarkRed;
                            break;
                        case 3: // Analysis.TraceType.Known_Sink:
                            tnCallNode.ForeColor = Color.Red;
                            break;
                        case 4: // Analysis.TraceType.Type_4:
                            tnCallNode.ForeColor = Color.Green;
                            break;
                        default:
                            break;
                    }

                    addCallsToNode_Recursive(cCall.CallInvocation1, tnCallNode, fadO2AssessmentDataOunceV6, stfSmartTraceFilter);
                    tnTargetNode.Nodes.Add(tnCallNode);
                }
        }