示例#1
0
        public Violation(
            MemoryAccessMethod method,
            string name = null,
            MemoryAccessParameterState baseState         = MemoryAccessParameterState.Unknown,
            MemoryAccessParameterState contentSrcState   = MemoryAccessParameterState.Unknown,
            MemoryAccessParameterState contentDstState   = MemoryAccessParameterState.Unknown,
            MemoryAccessParameterState displacementState = MemoryAccessParameterState.Unknown,
            MemoryAccessParameterState extentState       = MemoryAccessParameterState.Unknown
            )
        {
            Initialize();

            this.Method            = method;
            this.BaseState         = baseState;
            this.ContentSrcState   = contentSrcState;
            this.ContentDstState   = contentDstState;
            this.DisplacementState = displacementState;
            this.ExtentState       = extentState;
            this.Name = name;

            if (this.Method == MemoryAccessMethod.Execute)
            {
                this.DisplacementState = MemoryAccessParameterState.Nonexistant;
                this.ExtentState       = MemoryAccessParameterState.Nonexistant;
                this.AddressingMode    = MemoryAddressingMode.Absolute;
            }
            else if (this.Method == MemoryAccessMethod.Read)
            {
                this.ContentDstState = MemoryAccessParameterState.Nonexistant;
            }

            this.Guid = Guid.NewGuid();
        }
示例#2
0
        public Violation NewTransitiveViolation(
            MemoryAccessMethod method,
            string name = null,
            MemoryAccessParameterState baseState         = MemoryAccessParameterState.Unknown,
            MemoryAccessParameterState contentSrcState   = MemoryAccessParameterState.Unknown,
            MemoryAccessParameterState contentDstState   = MemoryAccessParameterState.Unknown,
            MemoryAccessParameterState displacementState = MemoryAccessParameterState.Unknown,
            MemoryAccessParameterState extentState       = MemoryAccessParameterState.Unknown
            )
        {
            Violation v = new Violation(method, name, baseState, contentSrcState, contentDstState, displacementState, extentState);

            v.PreviousViolationObject = this;

            v.AccessRequirement = this.AccessRequirement;
            v.ExecutionDomain   = this.ExecutionDomain;
            v.Locality          = this.Locality;

            //
            // Inherit the function's stack protection settings by default.
            //

            v.FunctionStackProtectionEnabled     = this.FunctionStackProtectionEnabled;
            v.FunctionStackProtectionEntropyBits = this.FunctionStackProtectionEntropyBits;
            v.FunctionStackProtectionVersion     = this.FunctionStackProtectionVersion;

            return(v);
        }
示例#3
0
 public List <TransitionChain> GetTransitionChains(MemoryAccessMethod method)
 {
     if (this.TransitionChains.ContainsKey(method))
     {
         return(this.TransitionChains[method]);
     }
     else
     {
         return(new List <TransitionChain>());
     }
 }
示例#4
0
文件: Enum.cs 项目: microsoft/exsim
        public static string GetAbbreviation(this MemoryAccessMethod method)
        {
            switch (method)
            {
            case MemoryAccessMethod.Read: return("r");

            case MemoryAccessMethod.Write: return("w");

            case MemoryAccessMethod.Execute: return("x");

            default: return("?");
            }
        }
示例#5
0
        /// <summary>
        /// Generates base violation profiles for a given method, set of parameters, and set of parameter states.
        /// </summary>
        /// <param name="method">The memory access method for the profiles.</param>
        /// <param name="parameters">The set of parameters.</param>
        /// <param name="parameterStates">The set of parameter states.</param>
        private void GenerateViolations(
            MemoryAccessMethod method,
            IEnumerable <MemoryAccessParameter> parameters,
            IEnumerable <MemoryAccessParameterState> parameterStates
            )
        {
            int statesCount = parameterStates.Count();

            int permutationCount = (int)Math.Pow(statesCount, parameters.Count());

            int stateBits = (int)Math.Round(Math.Log(statesCount, 2));

            int stateMask = (int)Math.Pow(2, stateBits) - 1;

            for (int permutation = 0; permutation < permutationCount; permutation++)
            {
                int pindex = 0;

                Violation violation = new Violation()
                {
                    Method = method
                };

                foreach (MemoryAccessParameter p in Enum.GetValues(typeof(MemoryAccessParameter)))
                {
                    violation.SetParameterState(p, MemoryAccessParameterState.Nonexistant);
                }

                foreach (MemoryAccessParameter p in parameters)
                {
                    int s = (permutation >> (pindex * stateBits)) & stateMask;

                    if (s >= statesCount)
                    {
                        break;
                    }

                    violation.SetParameterState(p, parameterStates.ElementAt(s));

                    pindex++;
                }

                if (pindex != parameters.Count())
                {
                    continue;
                }

                this.Profiles.Add(violation);
            }
        }
示例#6
0
        public bool IsTransitiveViolationComplete(MemoryAccessMethod method)
        {
            switch (method)
            {
            case MemoryAccessMethod.Read:
                return(this.TransitiveReadListIsComplete.GetValueOrDefault());

            case MemoryAccessMethod.Write:
                return(this.TransitiveWriteListIsComplete.GetValueOrDefault());

            case MemoryAccessMethod.Execute:
                return(this.TransitiveExecuteListIsComplete.GetValueOrDefault());

            default:
                throw new NotSupportedException();
            }
        }
示例#7
0
        public void SetTransitiveViolationComplete(MemoryAccessMethod method, bool complete)
        {
            switch (method)
            {
            case MemoryAccessMethod.Read:
                this.TransitiveReadListIsComplete = complete;
                break;

            case MemoryAccessMethod.Write:
                this.TransitiveWriteListIsComplete = complete;
                break;

            case MemoryAccessMethod.Execute:
                this.TransitiveExecuteListIsComplete = complete;
                break;

            default:
                throw new NotSupportedException();
            }
        }
示例#8
0
文件: Enum.cs 项目: microsoft/exsim
        public static MemoryAddress GetMemoryAddress(this MemoryAccessParameter parameter, MemoryAccessMethod method, MemoryRegionType?region = null)
        {
            MemoryContentDataType dataType;

            switch (parameter)
            {
            case MemoryAccessParameter.Base:
                if (method == MemoryAccessMethod.Read)
                {
                    dataType = MemoryContentDataType.ReadBasePointer;
                }
                else if (method == MemoryAccessMethod.Write)
                {
                    dataType = MemoryContentDataType.WriteBasePointer;
                }
                else
                {
                    throw new NotSupportedException();
                }
                break;

            case MemoryAccessParameter.Content:
                if (method == MemoryAccessMethod.Read)
                {
                    dataType = MemoryContentDataType.ReadContent;
                }
                else if (method == MemoryAccessMethod.Write)
                {
                    dataType = MemoryContentDataType.WriteContent;
                }
                else
                {
                    throw new NotSupportedException();
                }
                break;

            case MemoryAccessParameter.Displacement:
                if (method == MemoryAccessMethod.Read)
                {
                    dataType = MemoryContentDataType.ReadDisplacement;
                }
                else if (method == MemoryAccessMethod.Write)
                {
                    dataType = MemoryContentDataType.WriteDisplacement;
                }
                else
                {
                    throw new NotSupportedException();
                }
                break;

            case MemoryAccessParameter.Extent:
                if (method == MemoryAccessMethod.Read)
                {
                    dataType = MemoryContentDataType.ReadExtent;
                }
                else if (method == MemoryAccessMethod.Write)
                {
                    dataType = MemoryContentDataType.WriteExtent;
                }
                else
                {
                    throw new NotSupportedException();
                }
                break;

            default:
                throw new NotSupportedException();
            }

            return(new MemoryAddress(dataType, region));
        }