Exemplo n.º 1
0
        /// <summary>
        /// Set aliases to current snapshot entry. Aliases can be set even to those entries
        /// that doesn't belongs to any variable, field,..
        /// </summary>
        /// <param name="context">Context snapshot where operation is proceeded</param>
        /// <param name="aliasedEntry">Snapshot entry which will be aliased from current entry</param>
        protected override void setAliases(SnapshotBase context, ReadSnapshotEntryBase aliasedEntry)
        {
            Snapshot snapshot = ToSnapshot(context);

            SnapshotLogger.append(context, "set alias: " + this.ToString() + " from: " + aliasedEntry.ToString());

            if (snapshot.CurrentMode == SnapshotMode.InfoLevel)
            {
                return;
            }

            ICopyModelSnapshotEntry entry = ToEntry(aliasedEntry);
            AliasData data = entry.CreateAliasToEntry(snapshot);

            AssignCollector collector = new AssignCollector(snapshot);

            collector.AliasesProcessing = AliasesProcessing.BeforeCollecting;
            collector.ProcessPath(path);

            AssignAliasWorker worker = new AssignAliasWorker(snapshot);

            worker.AssignAlias(collector, data);

            data.Release(snapshot);
        }
Exemplo n.º 2
0
        private PropagationInfo getPropagation(ReadSnapshotEntryBase lValue)
        {
            var variable = lValue.GetVariableIdentifier(Input);

            if (!variable.IsDirect)
            {
                throw new NotImplementedException();
            }

            var info = lValue.ReadMemory(Output);

            if (info.Count != 1)
            {
                throw new NotImplementedException();
            }

            var infoValue = info.PossibleValues.First();

            if (infoValue is UndefinedValue)
            {
                //variable hasn't been propagated nowhere already
                return(new PropagationInfo(variable.DirectName.Value));
            }
            else
            {
                //we have propagation info from previous steps
                var result = ((InfoValue <PropagationInfo>)infoValue).Data;
                return(result);
            }
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        protected override void setAliases(SnapshotBase context, ReadSnapshotEntryBase aliasedEntry)
        {
            var snapshot     = C(context);
            var aliasEntries = aliasedEntry.Aliases(context);

            snapshot.SetAliases(Storages, aliasEntries);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Set aliases to current snapshot entry. Aliases can be set even to those entries
        /// that doesn't belongs to any variable, field,..
        /// </summary>
        /// <param name="context">Context snapshot where operation is proceeded</param>
        /// <param name="aliasedEntry">Snapshot entry which will be aliased from current entry</param>
        protected override void setAliases(SnapshotBase context, ReadSnapshotEntryBase aliasedEntry)
        {
            Snapshot snapshot = SnapshotEntry.ToSnapshot(context);

            snapshot.Factories.Logger.Log(context, "set aliases - " + this.ToString());

            getTemporary(context).SetAliases(context, aliasedEntry);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Returns the VariableIdentifier of given snapshot entry or null if it does not exist
 /// </summary>
 /// <param name="b">variable identifier or null</param>
 /// <returns></returns>
 private VariableIdentifier getVariableIdentifier(ReadSnapshotEntryBase b)
 {
     try
     {
         return(b.GetVariableIdentifier(Output));
     }
     catch (System.Exception e)
     {
         return(null);
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Converts base snapshot entry variable into copy memory model snapshot entry.
        /// </summary>
        /// <param name="entry">The entry.</param>
        /// <returns>Given entry parameter converted into copy memory model entry.</returns>
        /// <exception cref="System.ArgumentException">Entry parametter is not of type Weverca.MemoryModels.CopyMemoryModel.ICopyModelSnapshotEntry</exception>
        internal static ICopyModelSnapshotEntry ToEntry(ReadSnapshotEntryBase entry)
        {
            ICopyModelSnapshotEntry copyEntry = entry as ICopyModelSnapshotEntry;

            if (copyEntry != null)
            {
                return(copyEntry);
            }
            else
            {
                throw new ArgumentException("Entry parametter is not of type Weverca.MemoryModels.CopyMemoryModel.ICopyModelSnapshotEntry");
            }
        }
Exemplo n.º 7
0
        private List <Value> GetValues(ReadSnapshotEntryBase variable)
        {
            MemoryEntry memoryEntry = variable.ReadMemory(valueFactory.Snapshot);

            if (memoryEntry != null && memoryEntry.PossibleValues != null)
            {
                var values = new List <Value>(memoryEntry.PossibleValues.Count());
                values.AddRange(memoryEntry.PossibleValues);
                return(values);
            }

            return(null);
        }
Exemplo n.º 8
0
        /// <inheritdoc />
        protected override void flowThrough()
        {
            var entries = new ReadSnapshotEntryBase[_variables.Length];

            for (var i = 0; i < _variables.Length; ++i)
            {
                entries[i] = _variables[i].LValue;
            }

            var values = Services.Evaluator.IssetEx(entries);
            var value  = new MemoryEntry(values);

            Value = OutSet.CreateSnapshotEntry(value);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Set aliases to current snapshot entry. Aliases can be set even to those entries
        /// that doesn't belongs to any variable, field,..
        /// </summary>
        /// <param name="context">Context snapshot where operation is proceeded</param>
        /// <param name="aliasedEntry">Snapshot entry which will be aliased from current entry</param>
        protected override void setAliases(SnapshotBase context, ReadSnapshotEntryBase aliasedEntry)
        {
            Snapshot snapshot = ToSnapshot(context);

            snapshot.Factories.Logger.Log(snapshot, "set alias: " + this.ToString() + " from: " + aliasedEntry.ToString());
            snapshot.Factories.Benchmark.StartOperation(snapshot);

            ICopyModelSnapshotEntry entry = ToEntry(aliasedEntry);

            snapshot.Factories.Benchmark.StartAlgorithm(snapshot, AlgorithmType.SET_ALIAS);
            snapshot.Algorithms.AssignAlgorithm.AssignAlias(snapshot, path, entry.GetPath(snapshot));
            snapshot.Factories.Benchmark.FinishAlgorithm(snapshot, AlgorithmType.SET_ALIAS);

            snapshot.Factories.Benchmark.FinishOperation(snapshot);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initializes the given object depending on the given type declaration
        /// </summary>
        /// <param name="createdObject">A new object to be initialized</param>
        /// <param name="typeDeclaration">Type declaration used to initialize the given object</param>
        public void InitializeObject(ObjectValue createdObject, ClassDecl typeDeclaration)
        {
            Debug.Assert(thisObject == null, "Created object must be selected after enter to method");

            try
            {
                thisObject = createdObject;
                Debug.Assert(thisObject != null, "Initialized object must stay until end of initialization");
                ReadSnapshotEntryBase objectEntry = OutSet.CreateSnapshotEntry(new MemoryEntry(createdObject));

                List <QualifiedName> classHierarchy = new List <QualifiedName>(typeDeclaration.BaseClasses);
                classHierarchy.Add(typeDeclaration.QualifiedName);
                Dictionary <VariableName, FieldInfo> currentClassFields = new Dictionary <VariableName, FieldInfo>();

                foreach (var className in classHierarchy)
                {
                    foreach (var entry in typeDeclaration.Fields.Where(a => a.Key.ClassName.Equals(className)))
                    {
                        if (entry.Value.IsStatic == false)
                        {
                            currentClassFields[entry.Key.Name] = entry.Value;
                        }
                    }
                }

                foreach (var entry in currentClassFields.Values)
                {
                    var fieldEntry = objectEntry.ReadField(OutSet.Snapshot, new VariableIdentifier(entry.Name.Value));
                    if (entry.InitValue != null)
                    {
                        fieldEntry.WriteMemory(OutSet.Snapshot, entry.InitValue);
                    }
                    else if (entry.Initializer != null)
                    {
                        entry.Initializer.VisitMe(this);
                        fieldEntry.WriteMemory(OutSet.Snapshot, initializationValue);
                    }
                    else
                    {
                        fieldEntry.WriteMemory(OutSet.Snapshot, new MemoryEntry(OutSet.UndefinedValue));
                    }
                }
            }
            finally
            {
                thisObject = null;
            }
        }
Exemplo n.º 11
0
        public override MemoryEntry InitializeObject(ReadSnapshotEntryBase newObject, MemoryEntry[] arguments)
        {
            var newObjectValue = newObject.ReadMemory(InSnapshot);

            Flow.Arguments    = arguments;
            Flow.CalledObject = newObjectValue;

            var ctorName = new QualifiedName(new Name("__construct"));
            var ctors    = resolveMethod(newObject, ctorName);

            if (ctors.Count > 0)
            {
                setCallBranching(ctors);
            }

            return(newObjectValue);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Determines whether variable may be undefined or null
        /// </summary>
        /// <param name="variable">variable to check</param>
        /// <returns>true if variable may be undefined or null</returns>
        private bool hasPossibleNullValue(ReadSnapshotEntryBase variable)
        {
            bool nullValue = false;

            OutputSet.Snapshot.SetMode(SnapshotMode.MemoryLevel);
            var values = variable.ReadMemory(OutputSet.Snapshot).PossibleValues;

            foreach (Value value in values)
            {
                if (value is UndefinedValue)
                {
                    nullValue = true;
                    break;
                }
            }
            OutputSet.Snapshot.SetMode(SnapshotMode.InfoLevel);
            return(nullValue);
        }
Exemplo n.º 13
0
        private Dictionary <object, FunctionValue> resolveMethod(ReadSnapshotEntryBase thisObject, QualifiedName methodName)
        {
            NativeAnalyzerMethod analyzer;
            var result = new Dictionary <object, FunctionValue>();

            if (_nativeAnalyzers.TryGetValue(methodName.Name.Value, out analyzer))
            {
                //we have native analyzer - create it's program point graph
                var function = OutSet.CreateFunction(methodName.Name, new NativeAnalyzer(analyzer, Flow.CurrentPartial));
                result[function.DeclaringElement] = function;
            }
            else
            {
                var methods = thisObject.ResolveMethod(OutSnapshot, methodName);
                foreach (var method in methods)
                {
                    result[method.DeclaringElement] = method;
                }
            }

            return(result);
        }
Exemplo n.º 14
0
        /// <inheritdoc />
        protected override void flowThrough()
        {
            PrepareArguments();

            MemoryEntry value;

            //Create object according to class name
            if (Name == null)
            {
                value = Services.Evaluator.CreateObject(
                    NewEx.ClassNameRef.GenericQualifiedName.QualifiedName);
            }
            else
            {
                value = Services.Evaluator.IndirectCreateObject(Name.Value.ReadMemory(OutSnapshot));
            }

            //initialize created object
            var objectEntry       = OutSet.CreateSnapshotEntry(value);
            var initializedObject = Services.FunctionResolver.InitializeObject(objectEntry, Flow.Arguments);

            Value = OutSet.CreateSnapshotEntry(initializedObject);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Set aliases to current snapshot entry. Aliases can be set even to those entries
        /// that doesn't belongs to any variable, field,..
        /// </summary>
        /// <param name="context">Context snapshot where operation is proceeded</param>
        /// <param name="aliasedEntry">Snapshot entry which will be aliased from current entry</param>
        protected override void setAliases(SnapshotBase context, ReadSnapshotEntryBase aliasedEntry)
        {
            SnapshotLogger.append(context, "set aliases - " + this.ToString());

            getTemporary(context).SetAliases(context, aliasedEntry);
        }
Exemplo n.º 16
0
 /// <summary>
 /// Builds program point extension for static method call of given name and arguments
 /// via flow controller
 /// </summary>
 /// <param name="calledObject">Object which method is called</param>
 /// <param name="name">Values indirectly representing name of called static method</param>
 /// <param name="arguments">Arguments of call</param>
 public abstract void IndirectStaticMethodCall(ReadSnapshotEntryBase calledObject, MemoryEntry name,
                                               MemoryEntry[] arguments);
Exemplo n.º 17
0
 public override ReadWriteSnapshotEntryBase ResolveField(ReadSnapshotEntryBase objectValue, VariableIdentifier field)
 {
     return(objectValue.ReadField(OutSnapshot, field));
 }
Exemplo n.º 18
0
 /// <inheritdoc />
 public override void IndirectStaticMethodCall(ReadSnapshotEntryBase calledObject, MemoryEntry name, MemoryEntry[] arguments)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 19
0
 /// <summary>
 /// Is called when new object is created
 /// </summary>
 /// <param name="newObject">Entry of possible new objects created after construction</param>
 /// <param name="arguments">Arguments passed to constructor when creating a new object</param>
 /// <returns>Entry of objects, the same as <paramref name="newObject"/></returns>
 public abstract MemoryEntry InitializeObject(ReadSnapshotEntryBase newObject, MemoryEntry[] arguments);
Exemplo n.º 20
0
        public override void MethodCall(ReadSnapshotEntryBase calledObject, QualifiedName name, MemoryEntry[] arguments)
        {
            var methods = resolveMethod(calledObject, name);

            setCallBranching(methods);
        }
Exemplo n.º 21
0
 public override void AliasAssign(ReadWriteSnapshotEntryBase target, ReadSnapshotEntryBase aliasedValue)
 {
     target.SetAliases(OutSnapshot, aliasedValue);
 }
Exemplo n.º 22
0
 public override ReadWriteSnapshotEntryBase ResolveIndex(ReadSnapshotEntryBase arrayValue, MemberIdentifier index)
 {
     return(arrayValue.ReadIndex(OutSnapshot, index));
 }
Exemplo n.º 23
0
 /// <summary>
 /// Resolves value at indexedValue[index]
 /// </summary>
 /// <param name="indexedValue">Value which index is resolved</param>
 /// <param name="index">Specifier of an index</param>
 /// <returns>Possible values obtained from resolving given index</returns>
 public abstract ReadWriteSnapshotEntryBase ResolveIndex(ReadSnapshotEntryBase indexedValue,
                                                         MemberIdentifier index);
Exemplo n.º 24
0
 /// <summary>
 /// Assign possible aliases to given target
 /// </summary>
 /// <param name="target">Target variable specifier</param>
 /// <param name="aliasedValue">Possible aliases to be assigned</param>
 public abstract void AliasAssign(ReadWriteSnapshotEntryBase target,
                                  ReadSnapshotEntryBase aliasedValue);
Exemplo n.º 25
0
 /// <summary>
 /// Resolves value, determined by given field specifier
 /// </summary>
 /// <param name="objectValue">Object value which field is resolved</param>
 /// <param name="field">Specifier of resolved field</param>
 /// <returns>Possible values obtained from resolving given field</returns>
 public abstract ReadWriteSnapshotEntryBase ResolveField(ReadSnapshotEntryBase objectValue,
                                                         VariableIdentifier field);
Exemplo n.º 26
0
        private bool getTaint(ReadSnapshotEntryBase lValue)
        {
            var info = lValue.ReadMemory(Output);

            return(mergeTaint(info.PossibleValues));
        }
Exemplo n.º 27
0
 /// <inheritdoc />
 protected override void setAliases(SnapshotBase context, ReadSnapshotEntryBase aliasedEntry)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 28
0
 /// <summary>
 /// Builds program point extension for static method call of given name and arguments
 /// via flow controller
 /// </summary>
 /// <param name="calledObject">Object which method is called</param>
 /// <param name="name">Name of called static method</param>
 /// <param name="arguments">Arguments of call</param>
 public abstract void StaticMethodCall(ReadSnapshotEntryBase calledObject, QualifiedName name,
                                       MemoryEntry[] arguments);
Exemplo n.º 29
0
        /// <inheritdoc />
        protected override void setAliases(SnapshotBase context, ReadSnapshotEntryBase aliasedEntry)
        {
            var value = aliasedEntry.ReadMemory(context);

            writeMemory(context, value, true);
        }