public void calculateCustomRuleToAdd(CirData fadCirData)
 {
     var lsRulesToAdd = new List<string>();
     fromTreeNodeListCalculateRulesToAdd_recursive(tvCommandNameObjectFields.Nodes, lsRulesToAdd, fadCirData);
     lbRulesToAdd.Items.Clear();
     lbRulesToAdd.Items.AddRange(lsRulesToAdd.ToArray());
 }
 public void fromTreeNodeListCalculateRulesToAdd_recursive(TreeNodeCollection tncTreeNodes,
                                                           List<String> lsRulesToAdd, CirData fadCirData)
 {
     foreach (TreeNode tnTreeNode in tncTreeNodes)
     {
         if (fadCirData.dClasses_bySignature.ContainsKey(tnTreeNode.Text))
         {
             ICirClass ccCirClass = fadCirData.dClasses_bySignature[tnTreeNode.Text];
             foreach (ICirFunction cfCirFunction in ccCirClass.dFunctions.Values)
                 foreach (TreeNode tnChildNode in tnTreeNode.Nodes)
                 {
                     String sGetterVersion = tnChildNode.Text.Replace("set", "get");
                     if (new FilteredSignature(cfCirFunction.FunctionSignature).sFunctionName == sGetterVersion)
                     {
                         if (false == lsRulesToAdd.Contains(cfCirFunction.FunctionSignature))
                             lsRulesToAdd.Add(cfCirFunction.FunctionSignature);
                     }
                     if (tnChildNode.Nodes.Count > 0)
                         fromTreeNodeListCalculateRulesToAdd_recursive(tnChildNode.Nodes, lsRulesToAdd,
                                                                       fadCirData);
                 }
         }
         //   String sClass = tnTreeNode.Text;
     }
 }
        public void test_SaveAndLoadAllO2Modules()
        {
            var directoryToSaveCidDataFiles = Path.Combine(DI.config.O2TempDir, "_O2_CirData_Files");
            Files.checkIfDirectoryExistsAndCreateIfNot(directoryToSaveCidDataFiles);
            List<string> targetAssemblies = Files.getFilesFromDir_returnFullPath(DI.config.hardCodedO2LocalBuildDir, "*.exe");
            targetAssemblies.AddRange(Files.getFilesFromDir_returnFullPath(DI.config.hardCodedO2LocalBuildDir, "*.dll"));
            foreach (var assemblyToProcess in targetAssemblies)
            {
                DI.log.info("Processing file: {0}", Path.GetFileName(assemblyToProcess));
                ICirData cirData = new CirData();
                cirFactory.processAssemblyDefinition(cirData, assemblyToProcess);
                Assert.That(cirData.dClasses_bySignature.Count > 0 && cirData.dFunctions_bySignature.Count > 0,
                            "There we no CirData results for :" + assemblyToProcess);
                var savedCirDataFile = Path.Combine(directoryToSaveCidDataFiles,
                                                    Path.GetFileName(assemblyToProcess) + ".CirData");
                CirDataUtils.saveSerializedO2CirDataObjectToFile(cirData, savedCirDataFile);
                Assert.That(File.Exists(savedCirDataFile), "Saved CirData file Didn't exist: " + savedCirDataFile);

                ICirData cirData2 = CirLoad.loadFile(savedCirDataFile);
                Assert.That(cirData2 != null, "cirData2 was null");
                Assert.That(cirData.dClasses_bySignature.Count == cirData2.dClasses_bySignature.Count,
                            "dClasses_bySignature Count didnt match");
                Assert.That(cirData.dFunctions_bySignature.Count == cirData2.dFunctions_bySignature.Count,
                            "dFunctions_bySignature Count didnt match");
                // comment this to delete created files 
                //File.Delete(savedCirDataFile);                
            }
        }
 public void test_CreateCirDataFilesForDotNetFramework()
 {
     var dotNetFrameworkDirectory = @"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727";
     string directoryToSaveCidDataFiles = Path.Combine(DI.config.O2TempDir, "_CirDataFilesFor_DotNetFramework2_0_50727");
     Files.checkIfDirectoryExistsAndCreateIfNot(directoryToSaveCidDataFiles);    
     List<string> targetAssemblies = Files.getFilesFromDir_returnFullPath(dotNetFrameworkDirectory, "*.dll");
     //targetAssemblies.AddRange(Files.getFilesFromDir_returnFullPath(DI.hardCodedO2DeploymentDir, "*.dll"));
     ICirData cirDataWithAllAssemblies = new CirData();
     foreach (var assemblyToProcess in targetAssemblies)
     {
         if (CecilUtils.isDotNetAssembly(assemblyToProcess))
         {
             DI.log.info("Processing file: {0}", Path.GetFileName(assemblyToProcess));
             ICirData cirData = new CirData();
             cirFactory.processAssemblyDefinition(cirData, assemblyToProcess);
             cirFactory.processAssemblyDefinition(cirDataWithAllAssemblies, assemblyToProcess);
             var savedCirDataFile = Path.Combine(directoryToSaveCidDataFiles,
                                                 Path.GetFileName(assemblyToProcess) + ".CirData");
             CirDataUtils.saveSerializedO2CirDataObjectToFile(cirData, savedCirDataFile);
         }
     }
     DI.log.info("Almost there, now saving cirDataWithAllAssemblies ");
     var fileWithCirDataWithAllAssemblies = Path.Combine(directoryToSaveCidDataFiles, "cirDataWithAllAssemblies.CirData");
     CirDataUtils.saveSerializedO2CirDataObjectToFile(cirDataWithAllAssemblies, fileWithCirDataWithAllAssemblies);                
     DI.log.info("Done ..");
 }
 public static ascx_CirDataViewer show(this ICirClass cirClass)
 {
     var cirData = new CirData();
     cirData.dClasses_bySignature.Add(cirClass.Name, cirClass);
     var cirDataViewer = cirData.show(0);
     return cirDataViewer;
 }
Exemplo n.º 6
0
        public static List<IO2Finding> findParameterStaticValueInMethodX(CirData cirData)
        {
            string functionToFind = "System.Web.UI.WebControls.Button.add_Click(System.EventHandler):void";
            var createdO2Findings = new List<IO2Finding>();
            try
            {
                if (cirData.dFunctions_bySignature.ContainsKey(functionToFind))
                {
                    var function = cirData.dFunctions_bySignature[functionToFind];
                    foreach (CirFunction functionXRef in function.FunctionIsCalledBy)
                    {
                        //var functionXRef = cirData.dFunctions_bySignature[functionXRefName];
                        foreach (var basicBlock in functionXRef.lcfgBasicBlocks)
                        {
                            if (basicBlock != null && basicBlock.Items != null)
                                for (var i = 0; i < basicBlock.Items.Length; i++)
                                {
                                    var item = basicBlock.Items[i];
                                    if (item.GetType().Name == "ControlFlowGraphBasicBlockEvalExprStmt")
                                    {
                                        var evalExprStmt = (ControlFlowGraphBasicBlockEvalExprStmt)item;
                                        if (evalExprStmt.NaryCallVirtual != null && evalExprStmt.NaryCallVirtual.FunctionName == functionToFind)
                                        {
                                            // go to the previous block
                                            var evalExprStmtWithStaticParameterValue = (ControlFlowGraphBasicBlockEvalExprStmt)basicBlock.Items[i - 1];
                                            if (evalExprStmtWithStaticParameterValue.NaryCall != null && evalExprStmtWithStaticParameterValue.NaryCall.UnaryOprCast != null && evalExprStmtWithStaticParameterValue.NaryCall.UnaryOprCast.Length == 2)
                                            {

                                                string staticParameterValue =
                                                    evalExprStmtWithStaticParameterValue.NaryCall.UnaryOprCast[1].
                                                        ConstFunctionAddress.FunctionName;
                                                var o2Finding = new O2Finding(staticParameterValue, "Asp.NET Event Mapping") { o2Traces = new List<IO2Trace>{ new O2Trace(functionXRef.FunctionSignature, TraceType.Root_Call)} };
                                                var sourceTrace = new O2Trace(functionXRef.ParentClass.Signature, functionXRef.FunctionSignature, TraceType.Source);
                                                var sinkTrace = new O2Trace(staticParameterValue, TraceType.Known_Sink)
                                                                    {
                                                                        context =
                                                                            "this . HacmeBank_v2_Website.ascx.PostMessageForm.btnPostMessage_Click ( sender, e )"
                                                                    };
                                                sourceTrace.childTraces.Add(sinkTrace);
                                                o2Finding.o2Traces[0].childTraces.Add(sourceTrace);
                                                createdO2Findings.Add(o2Finding);
                                                DI.log.debug("{0} -- > {1}", functionXRef.FunctionSignature, staticParameterValue);
                                            }
                                        }
                                    }
                                }
                        }

                    }                  
                    return createdO2Findings;
                }
            }
            catch (Exception ex)
            {
                DI.log.debug("in findParameterStaticValueInMethodX :{0}:", ex.Message);
            }


            return null;
        }
 public void Test_getMemberFunction(CirData cirData, TypeDefinition testType, string methodToTest,
                                    Type[] methodParameters)
 {
     MethodDefinition cecilMethodDefinition = CecilUtils.getMethod(testType, methodToTest, methodParameters);
     Assert.IsNotNull(cecilMethodDefinition, "cecilMethodDefinition was null for method", methodToTest);
     ICirFunction cirFunction = cirFactory.processMethodDefinition(cirData, cecilMethodDefinition,null);
     Assert.IsNotNull(cirFunction, "cecilMethodDefinition was null for method", cecilMethodDefinition);
     Assert.That(CirCecilCompare.areEqual_MethodDefinitionAndCirFunction(cecilMethodDefinition, cirFunction),
                 "areEqual_MethodDefinitionAndCirFunction failed for method: " + cecilMethodDefinition);
 }
Exemplo n.º 8
0
 public static ICirData toCir(this string _string)
 {
     if (_string.isDotNet())
     {
         var cirData = new CirData();
         new CirFactory().processAssemblyDefinition(cirData, _string);
         cirData.remapXRefs();
         return cirData;
     }
     return null;
 }
 public void test_SaveCirDataFile()
 {
     ICirData cirData = new CirData();
     cirFactory.processAssemblyDefinition(cirData, DI.config.ExecutingAssembly);
     var savedCirDataFile = DI.config.getTempFileInTempDirectory("CirData");
     Assert.That(false   == File.Exists(savedCirDataFile), "savedCirDataFile shouldn't exist here");
     CirDataUtils.saveSerializedO2CirDataObjectToFile(cirData, savedCirDataFile);
     Assert.That(File.Exists(savedCirDataFile), "savedCirDataFile exist here");
     File.Delete(savedCirDataFile);
     Assert.That(false == File.Exists(savedCirDataFile), "savedCirDataFile Should be deleted");
     DI.log.info("all done");
 }
Exemplo n.º 10
0
 public static ICirClass toCir(this Type type)
 {
     var cirData = new CirData();
     var assemblyLocation = type.assemblyLocation();
     var assembly = CecilUtils.getAssembly(assemblyLocation);
     var cirFactory = new CirFactory();
     cirFactory.loadAndMapSymbols(assembly, assemblyLocation, false, "");
     var typeDefinition = CecilUtils.getType(assembly, type.Name);
     var cirType = cirFactory.processTypeDefinition(cirData, typeDefinition);
     cirData.remapXRefs();
     return cirType;
 }
Exemplo n.º 11
0
 public void createCirDataObject()
 {
     var cirFactory = new CirFactory();
     ICirData cirData = new CirData();
     DI.log.info("using assembly:{0} and O2_Kernel.dll", Assembly.GetExecutingAssembly().Location);
     cirFactory.processAssemblyDefinition(cirData, Assembly.GetExecutingAssembly().Location);
     cirFactory.processAssemblyDefinition(cirData, DI.config.ExecutingAssembly);            
     Assert.That(cirData.dClasses_bySignature.Count > 0, "There were no classes in cirData object");
     Assert.That(cirData.dFunctions_bySignature.Count > 0, "There were no function in cirData object");
     O2Messages.setCirData(cirData);
     //CirFactoryUtils.showCirDataStats();
 }
        private void createCirDataForFile(string fileToProcess, bool deleteFileOnCompletion, bool decompileCodeIfNoPdb)
        {
            O2Thread.mtaThread(() =>
            {
                ICirData assemblyCirData = new CirData();
                new CirFactory().processAssemblyAndSaveAsCirDataFile(assemblyCirData, fileToProcess, directory_CreatedCirFiles.getCurrentDirectory(), decompileCodeIfNoPdb);
                if (deleteFileOnCompletion)
                {
                    File.Delete(fileToProcess);
                }
            })
            ;

            //new CirCreatorEngineForDotnet().createCirForAssembly(fileToProcess);
        }
 public static CirData loadFile(String sPathToFileToLoad)
 {
     CirData cirData;
     if (Path.GetExtension(sPathToFileToLoad) == ".CirData")
     {
         cirData = loadSerializedO2CirDataObject(sPathToFileToLoad);
     }
     else
     {
         DI.log.debug("Loading CirDumpFile file: {0}", sPathToFileToLoad);
         cirData = new CirData();
         // always resolve these xrefs since older o2CirData might have probs (note that this is a one time only effort (per O2 session)) 
         loadCirDumpXmlFile_andPopulateDictionariesWithXrefs(sPathToFileToLoad, cirData, false);
     }
     fixFunctionsCalledXRefs(cirData);       // required for the new objects added by the CirCreator.CirFactory funtionality
     return cirData;
 }
 public static bool createConsolidatedCirDataFile(String sPathToCirDumpFiles, String sTargetCirDataFile,
                                                  bool bStoreControlFlowBlockRawDataInsideCirDataFile)
 {
     DI.log.debug("Creating Consolidated CirData file");
     try
     {
         List<String> lsCirDumpFiles = Files.getFilesFromDir_returnFullPath(sPathToCirDumpFiles);
         var fcdCirData = new CirData
                              {
                                  bStoreControlFlowBlockRawDataInsideCirDataFile =
                                      bStoreControlFlowBlockRawDataInsideCirDataFile
                              };
         if (lsCirDumpFiles.Count == 0)
             DI.log.error("No CirDump to process (were created during scan?)");
         else
         {
             DI.log.debug("in loadCirDumpXmlFile_andPopulateDictionariesWithXrefs");
             foreach (String sFile in lsCirDumpFiles)
                 try
                 {
                     fcdCirData.dSymbols = new Dictionary<string, string>();
                     fcdCirData.dTemp_Functions_bySymbolDef = new Dictionary<string, ICirFunction>();
                     CirLoad.loadCirDumpXmlFile_andPopulateDictionariesWithXrefs(sFile, fcdCirData, true);
                 }
                 catch (Exception ex)
                 {
                     DI.log.error("In createConsolidatedCirDataFile, error while processing file {0}: {1}",
                                  sFile, ex.Message);
                 }
             DI.log.debug("in saveSerializedO2CirDataObjectToFile");
             CirDataUtils.saveSerializedO2CirDataObjectToFile(fcdCirData,sTargetCirDataFile);
             return true;
         }
     }
     catch (Exception ex)
     {
         DI.log.error("In createConsolidatedCirDataFile: {0}:", ex.Message);
     }
     return false;
 }
 public CirDataAnalysis createCirDataAnalysisObject(List<string> assembliesToLoad, bool decompileCodeIfNoPdb)
 {
     ICirData cirData = new CirData();            
     foreach(var assemblyToLoad in assembliesToLoad)
         processAssemblyDefinition(cirData, assemblyToLoad,decompileCodeIfNoPdb);
     if (cirData.dClasses_bySignature.Count >0)
     {
         return new CirDataAnalysis(cirData);
     }
     DI.log.error("in createCirDataAnalysisObject there were no clases in CirData file");
     return null;            
 }
 public string convertAssemblyIntoCirDataFile(string assemblyToProcess, string targetDirectory, bool decompileCodeIfNoPdb)
 {
     ICirData cirData = new CirData();
     return processAssemblyAndSaveAsCirDataFile(cirData, assemblyToProcess, targetDirectory, decompileCodeIfNoPdb);            
 }
Exemplo n.º 17
0
 private void lbO2CirDataFilesInSelectedDir_DoubleClick(object sender, EventArgs e)
 {
     lbO2CirDataFilesInSelectedDir.Enabled = false;
     Application.DoEvents();
     String sPathToFileToProcess = Path.Combine(sCurrentBaseDir, lbO2CirDataFilesInSelectedDir.Text);
     lbFileLoaded.Text = sPathToFileToProcess;
     CirData fcdLoadedCirData = CirLoad.loadSerializedO2CirDataObject(sPathToFileToProcess);
     if (fcdLoadedCirData != null)
     {
         if (cbOnSelectUpdateIsCalledByMappigns.Checked)
         {
             if (fcdCirData == null)
                 DI.log.error(
                     "in lbO2CirDataFilesInSelectedDir_DoubleClick: this.fcdCirData == null (you must a project first before consolidating");
             else
                 CirDataUtils.addIsCalledByMappings(fcdCirData,fcdLoadedCirData);
         }
         else
             fcdCirData = fcdLoadedCirData;
         if (cbCirAnaLyzer_DontUpdateOnLoad.Checked)
         {
             tvAllClassesAndMethods.Nodes.Clear();
             lbO2CirData_Functions.Items.Clear();
         }
         else
         {
             cbCirAnalyzer_TextFilter_Classes.Checked = false;
             cbCirAnalyzer_TextFilter_Functions.Checked = false;
             cbCirAnalyzer_TextFilter_MakesCallsTo.Checked = false;
             cbCirAnalyzer_TextFilter_Parameters.Checked = false;
             cbCirAnalyzer_TextFilter_RemoveMakesCallsTo.Checked = false;
             cbCirAnalyzer_TextFilter_SuperClass.Checked = false;
             showO2CirDataInTreeViewAndListBox(fcdCirData, tvAllClassesAndMethods, lbO2CirData_Functions);
         }
     }
     lbO2CirDataFilesInSelectedDir.Enabled = true;
     DI.log.info("Done loading CirDataFile");
 }
Exemplo n.º 18
0
        public void runTextSearch(String sSuperClass, String sClassName, String sFunctionName, String sParameterType,
                                  String sMakesCallsTo, String sRemoveMakesCallsTo)
        {
            DI.log.debug("Running Cir Text Search on: ClassName={0} , FunctionName={1} , ParameterType={1}",
                         sClassName, sFunctionName, sParameterType);

            bool bOnlyProcessFunctionsWithControlFlowGraph = true;
            bool bVerbose = true;
            String sStringToSearch = tbCirAnalyszer_TextSearchFilter_SuperClass.Text;
            Dictionary<String, ICirClass> dMatches = CirDataUtils.analysis_getFunctionsThatMatchFilter(fcdCirData,
                sSuperClass, sClassName, sFunctionName, sParameterType, sMakesCallsTo, sRemoveMakesCallsTo,
                bOnlyProcessFunctionsWithControlFlowGraph, bVerbose);

            //    foreach (CirClass ccClass in dMatches.Values)
            //        DI.log.info(ccClass.FunctionSignature);

            var fcdResults = new CirData
                                 {
                                     dClasses_bySignature = dMatches,
                                     dSymbols = fcdCirData.dSymbols,
                                     lFiles = fcdCirData.lFiles
                                 };
            CirDataUtils.resolveDbId(fcdCirData);
            fcdResults.sDbId = fcdCirData.sDbId;
            /*
            foreach (CirClass ccCirClass in fcdCirData.dClasses.Values)
            {
                //String sResolvedClassName = fcdResults.getSymbol(sClassName);
    //            DI.log.info(ccCirClass.FunctionSignature);
                if (ccCirClass.FunctionSignature.ToUpper().IndexOf(sStringToSearch) > -1)      // case insensive search
                    fcdResults.dClasses.Add(ccCirClass.SymbolDef, ccCirClass);
            }*/
            showO2CirDataInTreeViewAndListBox(fcdResults, tvAllClassesAndMethods, lbO2CirData_Functions);
            DI.log.debug("Search completed");
        }
Exemplo n.º 19
0
 public void Test_processTypeDefinition()
 {
     ICirData cirData = new CirData();
     AssemblyDefinition testAssembly = getTestAssembly();
     TypeDefinition testTypeDefinition = CecilUtils.getType(testAssembly, "testType");
     ICirClass cirClass = cirFactory.processTypeDefinition(cirData, testTypeDefinition);
     Test_processTypeDefinition(cirData, cirClass);
 }
        public static void loadFileIntoCirDataAnalysisObject(string sFileToLoad, ICirDataAnalysis cirDataAnalysis, bool showNotSupportedExtensionError, bool useCachedVersionIfAvailable, bool runRemapXrefs, bool decompileCodeIfNoPdb)
        {
            try
            {
                switch (Path.GetExtension(sFileToLoad).ToLower())
                {
                    case ".cirdata":
                        addO2CirDataFile(cirDataAnalysis, sFileToLoad, useCachedVersionIfAvailable);
                        break;
                    case ".dll":
                    case ".exe":
                        if (CecilUtils.isDotNetAssembly(sFileToLoad, false))
                        {
                            ICirData assemblyCirData = new CirData();
                            new CirFactory().processAssemblyDefinition(assemblyCirData,
                                                                       CecilUtils.getAssembly(sFileToLoad), sFileToLoad, decompileCodeIfNoPdb);
                            if (assemblyCirData.dClasses_bySignature.Count == 0)
                                DI.log.error("There were no classes imporeted from the file: {0}", sFileToLoad);
                            else
                            {
                                var fileName = Path.GetFileName(sFileToLoad);
                                if (false == cirDataAnalysis.dCirDataFilesLoaded.ContainsKey(fileName))
                                {
                                    cirDataAnalysis.dCirDataFilesLoaded.Add(Path.GetFileName(sFileToLoad),
                                                                            assemblyCirData);
                                }
                                addO2CirDataFile(cirDataAnalysis, assemblyCirData, runRemapXrefs);
                            }
                        }
                        else
                            DI.log.error("Droped *.exe or *.dll file was not a .Net assembly: {0}", sFileToLoad);
                        break;
                    case "*.xml":
                        if (CirLoad.isFileACirDumpFile(sFileToLoad))
                            addO2CirDataFile(cirDataAnalysis, sFileToLoad,useCachedVersionIfAvailable);
                        break;
                    default:
                        if (showNotSupportedExtensionError)
                            DI.log.error(
                                "Could not process file dropped (it it not a CirData file or a .NET assembly: {0}",
                                sFileToLoad);
                        break;
                }

            }
            catch (Exception ex)
            {
                DI.log.error(
                    "in loadFileIntoCirDataAnalysisObject, error {0} while loading {1} : ", sFileToLoad, ex.Message);
            }

        }
Exemplo n.º 21
0
 public void showO2CirDataInListBox(CirData fcdCirData, ListBox lbTargetListBox, List<String> lsFunctionsAdded)
 {
     int iItemsProcessed = 0;
     lbTargetListBox.Items.Clear();
     //ascx_RulesCreator1.clearTargetslist();            
     foreach (String sSignature in lsFunctionsAdded)
     {
         if (fcdCirData.dFunctions_bySignature.ContainsKey(sSignature))
         {
             ICirFunction cfCirFunction = fcdCirData.dFunctions_bySignature[sSignature];
             cfCirFunction.OnlyShowFunctionNameInToString = !cbViewByFunction_FullSignature.Checked;
             if (false == lbTargetListBox.Items.Contains(cfCirFunction))
                 lbTargetListBox.Items.Add(cfCirFunction);
         }
         else if (false == lbTargetListBox.Items.Contains(sSignature))
             lbTargetListBox.Items.Add("*" + sSignature);
         if (iItemsProcessed++ < iMaxItemsToShowOnMainTreeView)
         {
             DI.log.error("MaxItemsToShow reached {0}, aborting", iMaxItemsToShowOnMainTreeView);
             break;
         }
     }
     lbTargetListBox.Sorted = true;
     /*
     if (fcdCirData.dClasses_bySignature != null)
         foreach (CirClass ccCirClass in fcdCirData.dClasses_bySignature.Values)
             if (ccCirClass.bClassHasMethodsWithControlFlowGraphs && ccCirClass.dFunctions.Count > 0)       //only Classes with methods with ControlFlowGraphs
                 foreach (CirFunction cfCirFunction in ccCirClass.dFunctions.Values)
                     if (cfCirFunction.HasControlFlowGraph)
                     {
                         cfCirFunction.OnlyShowFunctionNameInToString = !cbViewByFunction_FullSignature.Checked;
                         lbTargetListBox.Items.Add(cfCirFunction);
                     }
                 */
 }
Exemplo n.º 22
0
 public void showO2CirDataInTreeView(CirData fcdCirData)
 {
     showO2CirDataInTreeView(fcdCirData, tvAllClassesAndMethods, new List<string>());
 }
Exemplo n.º 23
0
 public void showO2CirDataInTreeViewAndListBox(CirData fcdCirData, TreeView tvTargetTreeView,
                                               ListBox lbTargetListBox)
 {
     var lsFunctionsAdded = new List<string>();
     showO2CirDataInTreeView(fcdCirData, tvTargetTreeView, lsFunctionsAdded);
     showO2CirDataInListBox(fcdCirData, lbTargetListBox, lsFunctionsAdded);
 }
Exemplo n.º 24
0
 public void Test_ProcessingO2Kernel()
 {
     DI.log.info("Testing with O2Kernel");
     ICirData cirData = new CirData();
     string O2KernelExe = DI.config.ExecutingAssembly; // this gets O2_Kernel.Exe
     Test_LoadingAssembly(cirData, O2KernelExe, true /*verify*/, false /*verbose*/);
     CirFactoryUtils.showCirDataStats(cirData);
 }
 public CirDataAnalysis createCirDataAnalysisObject(List<MethodInfo> methodInfos)
 {
     var assemblyDefinitions = new Dictionary<Assembly,AssemblyDefinition>();
     ICirData cirData = new CirData();
     //foreach(var assemblyToLoad in assembliesToLoad)
     foreach (MethodInfo methodInfo in methodInfos)
     {
         var assembly = methodInfo.DeclaringType.Assembly;
         if (false == assemblyDefinitions.ContainsKey(assembly))
         {
             var assemblyDefinition = CecilUtils.getAssembly(assembly.Location);
             if (assemblyDefinition != null)
                 assemblyDefinitions.Add(assembly, assemblyDefinition);
         }
         if (assemblyDefinitions.ContainsKey(assembly))
         {
             var methodDefinition = CecilConvert.getMethodDefinitionFromMethodInfo(methodInfo, assemblyDefinitions[assembly]);
             if (methodDefinition != null)
                 processMethodDefinition(cirData,methodDefinition,null);
         } 
     }
     return new CirDataAnalysis(cirData);
 }
Exemplo n.º 26
0
        public void showO2CirDataInTreeView(CirData fcdCirData, TreeView tvTargetTreeView, List<String> lsFunctionsAdded)
        {
            clearViewers();
            // make it not visible for performance reasons:
            tvTargetTreeView.Visible = false;
            // add list of files process to ListBox        
            lbCirAnalyzer_Files.Visible = false;

            foreach (String sFile in fcdCirData.lFiles)
                lbCirAnalyzer_Files.Items.Add(sFile);
            lbCirAnalyzer_Files.Visible = true;
            // add data to ClassesAndMethod Tree View

            tvTargetTreeView.Sort();
            if (fcdCirData.dClasses_bySignature != null)
                foreach (CirClass ccCirClass in fcdCirData.dClasses_bySignature.Values)
                {
                    if (ccCirClass.bClassHasMethodsWithControlFlowGraphs && ccCirClass.dFunctions.Count > 0)
                        //only Classes with methods with ControlFlowGraphs
                    {
                        bool bFunctionAdded = false;
                        TreeNode tnClass = O2Forms.newTreeNode(ccCirClass.Signature, "", 0, null);
                        // add SuperClasses
                        foreach (String sSuperClass in ccCirClass.dSuperClasses.Keys)
                            tnClass.Nodes.Add(O2Forms.newTreeNode(CirDataUtils.getSymbol(fcdCirData,sSuperClass), "", 5, null));
                        foreach (String sIsSuperClassedBy in ccCirClass.dIsSuperClassedBy.Keys)
                            tnClass.Nodes.Add(
                                O2Forms.newTreeNode("IsSuperClassedBy:" + CirDataUtils.getSymbol(fcdCirData,sIsSuperClassedBy), "", 5,
                                                    null));

                        // add fields
                        if (rbShowFieldsAndVariables.Checked)
                        {
                            foreach (FieldClass fsFieldClass in ccCirClass.dField_Class.Values)
                                tnClass.Nodes.Add(
                                    O2Forms.newTreeNode(
                                        String.Format("fc: {0} {1} - {2}", fsFieldClass.Signature, fsFieldClass.Name,
                                                      fsFieldClass.Signature), "", 4, null));
                            foreach (FieldMember fsFieldMember in ccCirClass.dField_Member.Values)
                                tnClass.Nodes.Add(
                                    O2Forms.newTreeNode(
                                        String.Format("fm: {0} {1}", fsFieldMember.PrintableType, fsFieldMember.Name),
                                        "", 4, null));
                        }
                        // add methods in code, its variables, who it calls
                        foreach (CirFunction cfCirFunction in ccCirClass.dFunctions.Values)
                        {
                            if (processFunctionAndAddItToNode(tnClass.Nodes, cfCirFunction, lsFunctionsAdded))
                                bFunctionAdded = true;
                        }

                        if (bFunctionAdded && tnClass.Nodes.Count > 0)
                            tvTargetTreeView.Nodes.Add(tnClass);
                    }
                    /*  // for C++ files  (handles with the NonClassFunctions)
                    foreach (CirFunction cfCirFunction in fcdCirData.dFunctions.Values)
                    { 
                        processFunctionAndAddItToNode(tvTargetTreeView.Nodes, cfCirFunction);
                    }*/
                    Application.DoEvents(); // refresh GUI
                }

            //tvAllClassesAndMethods.ExpandAll();
            //     if (tvAllClassesAndMethods.Nodes.Count > 0 )
            //         tvAllClassesAndMethods.Nodes[0].Expand();
            //     if (cbCirAnalyzer_TextFilter_MakesCallsTo.Checked || cbCirAnalyzer_TextFilter_Functions.Checked || cbCirAnalyzer_TextFilter_RemoveMakesCallsTo.Checked)
            //         tvTargetTreeView.ExpandAll();
            tvTargetTreeView.Visible = true;
        }
Exemplo n.º 27
0
        public static ICirData createCirDataFromXmlFileWithJavaMetadata(string xmlFileWithJavaMetadata)
        {
            var cirData = new CirData();
            try
            {
                DI.log.info("createCirDataFromXmlFileWithJavaMetadata for {0}", xmlFileWithJavaMetadata);
                var javaMetadata =
                    (JavaAttributeMappings)
                    Serialize.getDeSerializedObjectFromXmlFile(xmlFileWithJavaMetadata, typeof (JavaAttributeMappings));
                if (javaMetadata == null || javaMetadata.@class == null)
                {
                    DI.log.error(
                        "in createCirDataFromXmlFileWithJavaMetadata, could not convert file into JavaMetadata XSD-drive .Net class: {0}",
                        xmlFileWithJavaMetadata);
                    return null;
                }

                foreach (var _class in javaMetadata.@class)
                {
                    var cirClass = (CirClass) cirData.addClass(_class.name);
                    if (cirClass != null)
                    {
                        cirClass.bClassHasMethodsWithControlFlowGraphs = true;
                        cirClass.File = _class.sourceFile;
                        cirClass.FileLine = "0";                        

                        // map superclasses and Interfaces (which in the current version of the the CirData are all stored on the same location
                        if (_class.superclass != null)
                            foreach (var superClass in _class.superclass)
                                //CirDataUtils.addSuperClassMapping(cirData, cirClass,superClass.name);
                                cirClass.dSuperClasses.Add(superClass.name, null);//cirData.getClass(superClass.name));
                        if (_class.@interface != null)
                            foreach (var @interface in _class.@interface)
                                //CirDataUtils.addSuperClassMapping(cirData,cirClass, @interface.name);
                                cirClass.dSuperClasses.Add(@interface.name, null); //cirData.getClass(@interface.name));
                        if (_class.method != null)
                            foreach (var _method in _class.method)
                            {
                                var functionSignature = createSignatureFromMethodData(_class.name, _method.name, _method.descriptor);
                                var cirFunction = (CirFunction)cirClass.addFunction(functionSignature);
                                cirFunction.File = _class.sourceFile;
                                cirFunction.FileLine = _method.lineNumber.ToString();
                                if (_method.methodCalled != null)
                                {
                                    cirFunction.HasControlFlowGraph = true;
                                    foreach (var _calledMethod in _method.methodCalled)
                                    {
                                        var calledFunctionSignature = createSignatureFromMethodData(_calledMethod.@class,
                                                                                                    _calledMethod.name,
                                                                                                    _calledMethod.descriptor);
                                        cirFunction.addCalledFunction(calledFunctionSignature, cirFunction.File, _calledMethod.lineNumber);
                                    }
                                }
                            }                        
                    }
                }
                //cirData.remapXRefs();
            }
            catch (Exception ex)
            {
                DI.log.error("in createCirDataFromXmlFileWithJavaMetadata:{0}",ex.Message);
            }
            return cirData;
        }
Exemplo n.º 28
0
 private void btCirAnalyzer_LoadCirDataFile_Click(object sender, EventArgs e)
 {
     CirData fcdLoadedCirData =
         CirLoad.loadSerializedO2CirDataObject(tbCirAnalyzer_PathToSavedCirDataFile.Text);
     if (fcdLoadedCirData != null)
     {
         fcdCirData = fcdLoadedCirData;
         showO2CirDataInTreeViewAndListBox(fcdCirData, tvAllClassesAndMethods, lbO2CirData_Functions);
     }
 }
 public static ICirData createCirDataFromCirDataAnalysis(ICirDataAnalysis cirDataAnalysis)
 {
     if (cirDataAnalysis == null)
         return null;
     var cirData = new CirData
                       {
                           dClasses_bySignature = cirDataAnalysis.dCirClass_bySignature,
                           dFunctions_bySignature = cirDataAnalysis.dCirFunction_bySignature,                                  
                       };
     
     return cirData;
 }
Exemplo n.º 30
0
        public void Test_processMethodDefinition()
        {
            var cirData = new CirData();
            AssemblyDefinition testAssembly = getTestAssembly();
            TypeDefinition testType = CecilUtils.getType(testAssembly, "testType");


            Test_getMemberFunction(cirData, testType, "testMethodA", new Type[0]);
            Test_getMemberFunction(cirData, testType, "testMethodC", new[] {typeof (string)});
            Test_getMemberFunction(cirData, testType, "testMethodD", new[] {typeof (string), typeof (Type)});
        }