/// <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); }
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); } }
/// <inheritdoc /> protected override void setAliases(SnapshotBase context, ReadSnapshotEntryBase aliasedEntry) { var snapshot = C(context); var aliasEntries = aliasedEntry.Aliases(context); snapshot.SetAliases(Storages, aliasEntries); }
/// <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); }
/// <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); } }
/// <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"); } }
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); }
/// <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); }
/// <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); }
/// <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; } }
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); }
/// <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); }
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); }
/// <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); }
/// <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); }
/// <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);
public override ReadWriteSnapshotEntryBase ResolveField(ReadSnapshotEntryBase objectValue, VariableIdentifier field) { return(objectValue.ReadField(OutSnapshot, field)); }
/// <inheritdoc /> public override void IndirectStaticMethodCall(ReadSnapshotEntryBase calledObject, MemoryEntry name, MemoryEntry[] arguments) { throw new NotImplementedException(); }
/// <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);
public override void MethodCall(ReadSnapshotEntryBase calledObject, QualifiedName name, MemoryEntry[] arguments) { var methods = resolveMethod(calledObject, name); setCallBranching(methods); }
public override void AliasAssign(ReadWriteSnapshotEntryBase target, ReadSnapshotEntryBase aliasedValue) { target.SetAliases(OutSnapshot, aliasedValue); }
public override ReadWriteSnapshotEntryBase ResolveIndex(ReadSnapshotEntryBase arrayValue, MemberIdentifier index) { return(arrayValue.ReadIndex(OutSnapshot, index)); }
/// <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);
/// <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);
/// <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);
private bool getTaint(ReadSnapshotEntryBase lValue) { var info = lValue.ReadMemory(Output); return(mergeTaint(info.PossibleValues)); }
/// <inheritdoc /> protected override void setAliases(SnapshotBase context, ReadSnapshotEntryBase aliasedEntry) { throw new NotImplementedException(); }
/// <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);
/// <inheritdoc /> protected override void setAliases(SnapshotBase context, ReadSnapshotEntryBase aliasedEntry) { var value = aliasedEntry.ReadMemory(context); writeMemory(context, value, true); }