示例#1
0
        public SliceBuilder(
            string name,
            IEnumerable <Method> methods,
            Assembly containingAssembly,
            IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder,
            IDecodeContracts <Local, Parameter, Method, Field, Type> contractDecoder,
            Func <Method, IMethodDriver <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, SymbolicValue, ILogOptions> > getMethodDriver,
            bool includeOtherMethodsInTheType)
            : base(name, containingAssembly, mdDecoder, contractDecoder)
        {
            Contract.Requires(methods != null);
            Contract.Requires(containingAssembly != null);
            Contract.Requires(contractDecoder != null);
            Contract.Requires(mdDecoder != null);
            Contract.Requires(getMethodDriver != null);

            this.getMethodDriver = getMethodDriver;

            foreach (var m in methods)
            {
                this.AddMethod(m);
            }

            if (includeOtherMethodsInTheType)
            {
                foreach (var m in this.OtherMethodsInTheSameType)
                {
                    Touch(m);
                }
            }
        }
        public SlicerWorker(
            GeneralOptions options,
            ISimpleLineWriter outputLineWriter,
            ISlicerEnvironment <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> environment
            )
        {
            this.options         = options;
            this.environment     = environment;
            this.mdDecoder       = environment.MetaDataDecoder;
            this.contractDecoder = environment.ContractDecoder;
            this.fieldsDB        = new FieldsDB <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly>(this.mdDecoder);

            this.output = new TextWriterOutputWithPrefix(outputLineWriter.AsTextWriter(), options, "[SlicerWorker] "); // TODO

            var basicDriver = new BasicAnalysisDriver <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, ILogOptions>(this.mdDecoder, this.contractDecoder, this.output, options);

            this.driver = new OldAnalysisDriver <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, ILogOptions, IMethodResult <SymbolicValue> >(basicDriver);

            this.OptionsData = OptionsHashing.GetOptionsData(environment.MethodAnalyzers, environment.ClassAnalyzers, options);

            EGraphStats.IncrementalJoin = options.incrementalEgraphJoin; // used in OptimisticHeapAnalysis

            // TODO: initialize analysis needed by the slicer, but not more

            // TODO: is that it?
        }
        protected BaseSlicerEnvironment(
            GeneralOptions options,
            IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> metadataDecoder,
            IDecodeContracts <Local, Parameter, Method, Field, Type> contractDecoder,
            Dictionary <string, IMethodAnalysis> methodAnalyzers,
            Dictionary <string, IClassAnalysis> classAnalyzers)
        {
            this.options         = options;
            this.metadataDecoder = metadataDecoder;
            this.contractDecoder = contractDecoder;
            this.methodAnalyzers = methodAnalyzers;
            this.classAnalyzers  = classAnalyzers;

            // set shared contract library
            this.metadataDecoder.SharedContractClassAssembly = options.cclib;
            this.SetTargetPlatform(options.framework, options.platform, options.resolvedPaths, options.libPaths);

            this.LoadAssemblies(options.ContractAssemblies, errorHandler: null, onSuccess: null, onError: null);
            // TODO: report environment loading errors
            //output.WriteLine("Cannot load contract assembly '{0}'", contractAssembly);
            //options.AddError();

            this.assembliesUnderAnalysis.AddRange(this.options.Assemblies.Select(Path.GetFileNameWithoutExtension));

            this.LoadAssemblies(options.Assemblies, errorHandler: null /* this.output.EmitError */, onSuccess: this.assembliesToAnalyze.Add, onError: null);
            // Console.WriteLine("Cannot load assembly '{0}'", assembly);
            // this.options.AddError();
        }
        public static InferredExpr <Field, Method> GetInferredExpr <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly>(
            this Microsoft.Research.CodeAnalysis.Caching.Models.Method @this,
            Method currentMethod,
            IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder,
            IDecodeContracts <Local, Parameter, Method, Field, Type> contractDecoder,
            bool trace
            )
        {
            if (@this.InferredExpr == null)
            {
                return(default(InferredExpr <Field, Method>));
            }
            if (@this.InferredExprHash == null)
            {
                throw new SerializationException("Cannot check deserialization, hash null");
            }

            var state             = StreamingContextStates.File | StreamingContextStates.Persistence;
            var streamingContext  = new StreamingContext(state);
            var surrogateSelector = Serializers.SurrogateSelectorFor(streamingContext, currentMethod, mdDecoder, contractDecoder, trace);
            var formatter         = new BinaryFormatter(surrogateSelector, streamingContext);
            var stream            = new System.IO.MemoryStream(@this.InferredExpr);

            try
            {
                // Fix for SerializationException below. Somehow deserialization does not find certain assemblies, so we help out
                // the resolver to find currently loaded assemblies.
                AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(DeserializeAssemblyResolve);
                var result  = (InferredExpr <Field, Method>)formatter.Deserialize(stream);
                var newHash = DummyExpressionHasher.Hash(result, trace);
                if (@this.InferredExprHash.ContentEquals(newHash))
                {
                    return(result);
                }
                throw new SerializationException(String.Format("Deserialization failed: hash differs. Expected '{0}', got '{1}'.", @this.InferredExprString, result.ToString()));
            }
            catch (SerializationException)
            {
                // "Unable to find assembly 'ClousotMain, Version=1.1.1.1, Culture=neutral, PublicKeyToken=188286aac86319f9'." just means the Clousot has been recompiled (its version number should have changed)
                // must not happen, please, please, please! ('cause the method hasn't changed)

                // this happens because there are some types in ClousotMain that get serialized. But when we build an installer, these types are actually in cccheck.exe
                // so a cache populated using Clousot does not interact well with a cache used with cccheck.
                throw;
            }
            catch (NotImplementedException e)
            {
                throw new SerializationException("Some deserialization implementation is missing, see inner exception", e);
            }
            catch (Exception e)
            {
                // ArgumentException "Object of type '<type>' cannot be converted to type '<type>'." just means the type has changed
                throw new SerializationException("Random exception while deserializing, see inner exception", e);
            }
            finally
            {
                AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(DeserializeAssemblyResolve);
            }
        }
示例#5
0
 /// <summary>
 /// CodeProvider independent code
 /// </summary>
 public static void CallGraphMain <Local, Parameter, Method, Field, Property, Type, Attribute, Assembly>(
     string[] args,
     IDecodeMetaData <Local, Parameter, Method, Field, Property, Type, Attribute, Assembly> mdDecoder,
     IDecodeContracts <Local, Parameter, Method, Field, Type> contractDecoder
     )
 {
     new TypeBinder <Local, Parameter, Method, Field, Property, Type, Attribute, Assembly>(args, mdDecoder, contractDecoder).Analyze();
 }
示例#6
0
 public ProtectionBasedMethodOrder(
     IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> md,
     IDecodeContracts <Local, Parameter, Method, Field, Type> cd,
     FieldsDB <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> fieldsDB,
     CancellationToken cancellationToken)
     : base(md, cd, fieldsDB)
 {
     this.cancellationToken = cancellationToken;
 }
示例#7
0
 public CodeLayer(IDecodeMSIL <APC, Local, Parameter, Method, Field, Type, Expression, Variable, ContextData, EdgeData> ildecoder, IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder, IDecodeContracts <Local, Parameter, Method, Field, Type> ctDecoder,
                  Converter <Expression, string> expression2String, Converter <Variable, string> variable2String,
                  Func <Variable, Variable, bool> newerThan)
 {
     this.ildecoder         = ildecoder;
     this.mdDecoder         = mdDecoder;
     this.ctDecoder         = ctDecoder;
     this.expression2String = expression2String;
     this.variable2String   = variable2String;
     this.newerThan         = newerThan;
 }
示例#8
0
        protected BaseMethodOrder(
            IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> md,
            IDecodeContracts <Local, Parameter, Method, Field, Type> cd,
            FieldsDB <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> fieldsDB)
        {
            Contract.Requires(fieldsDB != null);

            this.md       = md;
            this.cd       = cd;
            this.fieldsDB = fieldsDB;
        }
示例#9
0
 public ConstructorsFirstAndTheCallGraphMethodOrder(
     bool constructorsFirst,
     IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> md,
     IDecodeContracts <Local, Parameter, Method, Field, Type> cd,
     Set <string> underAnalysis,
     FieldsDB <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> fieldsDB,
     CancellationToken cancellationToken)
     : base(constructorsFirst, md, cd, underAnalysis, fieldsDB, cancellationToken)
 {
     this.constructors = new List <Method>();
 }
示例#10
0
        static public ISurrogateSelector SurrogateSelectorFor <Local, Parameter, Method, Field, Property, Event, Typ, Attribute, Assembly>(
            StreamingContext context,
            Method currentMethod,
            IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Typ, Attribute, Assembly> mdDecoder,
            IDecodeContracts <Local, Parameter, Method, Field, Typ> contractDecoder,
            bool trace)
        {
            Contract.Requires(currentMethod != null);
            Contract.Requires(mdDecoder != null);

            return(Serializers <Local, Parameter, Method, Field, Property, Event, Typ, Attribute, Assembly> .SurrogateSelectorFor(context, currentMethod, mdDecoder, contractDecoder, trace));
        }
示例#11
0
            public TypeBinder(
                string[] args,
                IDecodeMetaData <Local, Parameter, Method, Field, Property, Type, Attribute, Assembly> mdDecoder,
                IDecodeContracts <Local, Parameter, Method, Field, Type> contractDecoder
                )
            {
                this.mdDecoder = mdDecoder;
                options        = GeneralOptions.ParseCommandLineArguments(args);

                if (options.HasErrors)
                {
                    GeneralOptions.PrintUsageAndExit();
                }
            }
示例#12
0
 public CallGraphOrder(
     bool constructorsFirst,
     IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> md,
     IDecodeContracts <Local, Parameter, Method, Field, Type> cd,
     Set <string> underAnalysis,
     FieldsDB <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> fieldsDB,
     CancellationToken cancellationToken)
     : base(md, cd, fieldsDB)
 {
     this.constructorsFirst       = constructorsFirst;
     this.callGraph               = new SingleEdgeGraph <Node, Unit>(null, new Node.EqualityComparer(md));
     this.assembliesUnderAnalysis = underAnalysis;
     this.contractConsumer        = new ContractConsumer(this);
     this.cancellationToken       = cancellationToken;
 }
示例#13
0
        protected Slice(
            string name,
            Assembly containingAssembly,
            IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder,
            IDecodeContracts <Local, Parameter, Method, Field, Type> contractDecoder)
        {
            Contract.Requires(containingAssembly != null);
            Contract.Requires(contractDecoder != null);
            Contract.Requires(mdDecoder != null);

            this.name = name;
            this.containingAssembly     = containingAssembly;
            this.containingAssemblyName = mdDecoder.Name(containingAssembly);
            this.mdDecoder       = mdDecoder;
            this.contractDecoder = contractDecoder;
        }
示例#14
0
 Create <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable, ContextData, EdgeData>(
     IDecodeMSIL <APC, Local, Parameter, Method, Field, Type, Expression, Variable, ContextData, EdgeData> ildecoder,
     IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder,
     IDecodeContracts <Local, Parameter, Method, Field, Type> ctDecoder,
     Converter <Expression, string> expression2String,
     Converter <Variable, string> variable2String,
     Func <Variable, Variable, bool> newerThan
     )
     where Type : IEquatable <Type>
     where ContextData : IMethodContext <Field, Method>
 {
     return(new CodeLayer <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly, Expression, Variable, ContextData, EdgeData>(
                ildecoder, mdDecoder, ctDecoder,
                expression2String, variable2String,
                newerThan
                ));
 }
示例#15
0
        public BasicAnalysisDriver(
            IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder,
            IDecodeContracts <Local, Parameter, Method, Field, Type> contractDecoder,
            IOutput output,
            LogOptions options
            )
        {
            Contract.Requires(mdDecoder != null);
            Contract.Requires(contractDecoder != null);
            Contract.Requires(output != null);
            Contract.Requires(options != null);

            this.methodCache     = new MethodCache <Local, Parameter, Type, Method, Field, Property, Event, Attribute, Assembly>(mdDecoder, contractDecoder, output.WriteLine);
            this.mdDecoder       = mdDecoder;
            this.contractDecoder = contractDecoder;
            this.output          = output;
            this.options         = options;
        }
示例#16
0
            static public XSS For(
                Method currentMethod,
                IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Typ, Attribute, Assembly> mdDecoder,
                IDecodeContracts <Local, Parameter, Method, Field, Typ> contractDecoder,
                bool trace = false)
            {
                Contract.Requires(currentMethod != null);

                var x = new XSS();

                x.CurrentMethod       = currentMethod;
                x.mdDecoder           = mdDecoder;
                x.contractDecoder     = contractDecoder;
                x.currentAssembly     = mdDecoder.DeclaringAssembly(currentMethod);
                x.currentAssemblyName = mdDecoder.Name(x.currentAssembly);
                x.Trace = trace;
                return(x);
            }
        public static void SetInferredExpr <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly>(
            this Microsoft.Research.CodeAnalysis.Caching.Models.Method @this,
            InferredExpr <Field, Method> value,
            Method currentMethod,
            IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder,
            IDecodeContracts <Local, Parameter, Method, Field, Type> contractDecoder,
            bool trace,
            bool traceHashing)
        {
            // To make the serialization happy
            var state            = StreamingContextStates.File | StreamingContextStates.Persistence;
            var streamingContext = new StreamingContext(state);

            // We do not want to serialize CCI types directly. We want the Serialization to call us and ask if we have a better way of serializing
            var surrogateSelector = Serializers.SurrogateSelectorFor(streamingContext, currentMethod, mdDecoder, contractDecoder, trace);

            // Create the serializer
            var formatter = new BinaryFormatter(surrogateSelector, streamingContext);
            var stream    = new System.IO.MemoryStream();

            try
            {
                // Now do the work!
                formatter.Serialize(stream, value);
            }
            catch (SerializationException)
            {
                throw;
            }
            catch (NotImplementedException e)
            {
                throw new SerializationException("Some serialization implementation is missing, see inner exception", e);
            }
            catch (Exception e)
            {
                throw new SerializationException("Random exception while serializing, see inner exception", e);
            }
            @this.InferredExpr     = stream.ToArray();
            @this.InferredExprHash = DummyExpressionHasher.Hash(value, traceHashing);
            if (trace)
            {
                @this.InferredExprString = value.ToString();
            }
        }
示例#18
0
 public CodeLayer(IDecodeMSIL <APC, Local, Parameter, Method, Field, Type, Expression, Variable, ContextData, EdgeData> ildecoder, IDecodeMetaData <Local, Parameter, Method, Field, Property, Event, Type, Attribute, Assembly> mdDecoder, IDecodeContracts <Local, Parameter, Method, Field, Type> ctDecoder,
                  Converter <Expression, string> expression2String, Converter <Variable, string> variable2String,
                  ILPrinter <APC> printer, Func <Variable, Variable, bool> newerThan)
     : this(ildecoder, mdDecoder, ctDecoder, expression2String, variable2String, newerThan)
 {
     this.printer = printer;
 }