Пример #1
0
        public BasicMethodDriver(Method method, IBasicAnalysisDriver parent)
        {
            this.method = method;
            this.parent = parent;

            RawLayer = CodeLayerFactory.Create(
                this.parent.SubroutineFacade.GetControlFlowGraph(method).GetDecoder(parent.MetaDataProvider),
                parent.MetaDataProvider,
                parent.ContractProvider, dummy => "", dummy => "");

            if (DebugOptions.Debug)
            {
                Console.WriteLine("-----APC based CFG-----");
                RawLayer.ILDecoder.ContextProvider.MethodContext.CFG.Print(Console.Out, RawLayer.Printer, null, null);
            }

            StackLayer = CodeLayerFactory.Create(
                StackDepthFactory.Create(RawLayer.ILDecoder, RawLayer.MetaDataProvider),
                RawLayer.MetaDataProvider,
                RawLayer.ContractProvider, (i => "s" + i.ToString()), i => "s" + i.ToString()
                );

            if (DebugOptions.Debug)
            {
                Console.WriteLine("-----Stack based CFG-----");
                StackLayer.ILDecoder.ContextProvider.MethodContext.CFG.Print(Console.Out, StackLayer.Printer, null, null);
            }
        }
Пример #2
0
            public void RunHeapAndExpressionAnalyses()
            {
                if (this.heap_analysis != null)
                {
                    return;
                }

                this.heap_analysis = new HeapAnalysis.HeapAnalysis(StackLayer);
                StackLayer.CreateForward(this.heap_analysis) (this.heap_analysis.InitialValue());

                ValueLayer = CodeLayerFactory.Create(
                    this.heap_analysis.GetDecoder(StackLayer.ILDecoder), StackLayer.MetaDataProvider, StackLayer.ContractProvider,
                    source => source.ToString(), dest => dest.ToString());
                var expressionAnalysis = new ExpressionAnalysisFacade <SymbolicValue, IValueContextProvider <SymbolicValue>, IImmutableMap <SymbolicValue, LispList <SymbolicValue> > >
                                             (ValueLayer, this.heap_analysis.IsUnreachable);

                ValueLayer.CreateForward(expressionAnalysis.CreateExpressionAnalysis()) (expressionAnalysis.InitialValue(SymbolicValue.GetUniqueKey));

                if (DebugOptions.Debug)
                {
                    Console.WriteLine("------------Value based CFG-----------------");
                    ValueLayer.ILDecoder.ContextProvider.MethodContext.CFG.Print(Console.Out, ValueLayer.Printer, null, null);
                }

                IILDecoder
                <APC, LabeledSymbol <APC, SymbolicValue>, SymbolicValue, IExpressionContextProvider <LabeledSymbol <APC, SymbolicValue>, SymbolicValue>, IImmutableMap <SymbolicValue, LispList <SymbolicValue> > >
                decoder = expressionAnalysis.GetDecoder(ValueLayer.ILDecoder);

                this.expr2String = ExpressionPrinterFactory.Printer(decoder.ContextProvider, this);
                ExpressionLayer  = CodeLayerFactory.Create(decoder, ValueLayer.MetaDataProvider, ValueLayer.ContractProvider,
                                                           this.expr2String, ValueLayer.VariableToString);

                if (DebugOptions.Debug)
                {
                    Console.WriteLine("------------Expression based CFG-------------");
                    ExpressionLayer.ILDecoder.ContextProvider.MethodContext.CFG.Print(Console.Out, ExpressionLayer.Printer, null, null);
                }

                HybridLayer = CodeLayerFactory.Create(ValueLayer.ILDecoder, ValueLayer.MetaDataProvider, ValueLayer.ContractProvider,
                                                      ValueLayer.ExpressionToString,
                                                      ValueLayer.VariableToString, ExpressionLayer.Printer);
            }