コード例 #1
0
        /// <summary>
        /// Finds a matching <see cref="TrapPlan" />.
        /// </summary>
        /// <param name="interceptionPoint">CUrrent InterceptionPoint.</param>
        /// <param name="globalHitcountWindow">Global hitcount window.</param>
        /// <param name="localHitcountWindow">Local hitcount window.</param>
        /// <returns>A matching <see cref="TrapPlan" />.</returns>
        public TrapPlan FindMatchingPlan(InterceptionPoint interceptionPoint, int globalHitcountWindow = 20, int localHitcountWindow = 5)
        {
            if (interceptionPoint == null || interceptionPoint.API == null)
            {
                return(null);
            }

            var planId = TrapPlan.GetID(interceptionPoint.API, interceptionPoint.Method, interceptionPoint.ILOffset);

            if (this.nonwildCardPlans.ContainsKey(planId))
            {
                var  plan    = this.nonwildCardPlans[planId];
                bool isMatch = (plan.ThreadId == null || string.Equals(plan.ThreadId, interceptionPoint.ThreadId)) &&
                               (plan.HitCounts == null || plan.HitCounts.Count(x => x.IsMatch(interceptionPoint.LocalHitcount, localHitcountWindow, interceptionPoint.GLobalHitCount, globalHitcountWindow)) > 0);

                return(isMatch ? plan : null);
            }

            foreach (var plan in this.wildCardPlans)
            {
                if (!SignatureMatchUtils.IsWildcardMatch(interceptionPoint.API, plan.API))
                {
                    continue;
                }

                if (plan.Method != null && !SignatureMatchUtils.IsWildcardMatch(interceptionPoint.Method, plan.Method))
                {
                    continue;
                }

                if (plan.ILOffset >= 0 && plan.ILOffset != interceptionPoint.ILOffset)
                {
                    continue;
                }

                if (plan.ThreadId != null && !string.Equals(plan.ThreadId, interceptionPoint.ThreadId))
                {
                    continue;
                }

                if (plan.HitCounts != null && plan.HitCounts.Count(x => x.IsMatch(interceptionPoint.LocalHitcount, localHitcountWindow, interceptionPoint.GLobalHitCount, globalHitcountWindow)) > 0)
                {
                    continue;
                }

                return(plan);
            }

            return(null);
        }
コード例 #2
0
ファイル: TSVDParameters.cs プロジェクト: microsoft/TSVD
        /// <summary>
        /// Get thread safety group details of the InterceptionPoint.
        /// </summary>
        /// <param name="interceptionPoint">InterceptionPoint.</param>
        /// <returns>Thread safety InterceptionPoint.</returns>
        private ThreadSafetyInterceptionPoint GetThreadSafetyInterceptionPoint(InterceptionPoint interceptionPoint)
        {
            if (this.threadSafetyInterceptionPointCache.ContainsKey(interceptionPoint.API))
            {
                return(this.threadSafetyInterceptionPointCache[interceptionPoint.API]);
            }

            foreach (ThreadSafetyGroup threadSafetyGroup in this.configuration.ThreadSafetyGroups)
            {
                foreach (string writeAPI in threadSafetyGroup.WriteAPIs)
                {
                    if (SignatureMatchUtils.IsWildcardMatch(interceptionPoint.API, writeAPI))
                    {
                        var tsInterceptionPoint = new ThreadSafetyInterceptionPoint()
                        {
                            ThreadSafetyGroup = threadSafetyGroup,
                            IsWriteAPI        = true,
                        };
                        this.threadSafetyInterceptionPointCache[interceptionPoint.API] = tsInterceptionPoint;
                        return(tsInterceptionPoint);
                    }
                }

                foreach (string readAPI in threadSafetyGroup.ReadAPIs)
                {
                    if (SignatureMatchUtils.IsWildcardMatch(interceptionPoint.API, readAPI))
                    {
                        var tsInterceptionPoint = new ThreadSafetyInterceptionPoint()
                        {
                            ThreadSafetyGroup = threadSafetyGroup,
                            IsWriteAPI        = false,
                        };
                        this.threadSafetyInterceptionPointCache[interceptionPoint.API] = tsInterceptionPoint;
                        return(tsInterceptionPoint);
                    }
                }
            }

            return(null);
        }
コード例 #3
0
        /// <summary>
        /// Get thread safety group details of the InterceptionPoint.
        /// </summary>
        /// <param name="threadSafetyGroups">The thread safety groups.</param>
        /// <param name="interceptionPoint">InterceptionPoint.</param>
        /// <returns>Thread safety InterceptionPoint.</returns>
        public static ThreadSafetyInterceptionPoint GetThreadSafetyInterceptionPoint(List <ThreadSafetyGroup> threadSafetyGroups, InterceptionPoint interceptionPoint)
        {
            if (threadSafetyGroups == null)
            {
                return(null);
            }

            foreach (ThreadSafetyGroup threadSafetyGroup in threadSafetyGroups)
            {
                foreach (string writeAPI in threadSafetyGroup.WriteAPIs)
                {
                    if (SignatureMatchUtils.IsWildcardMatch(interceptionPoint.API, writeAPI))
                    {
                        return(new ThreadSafetyInterceptionPoint()
                        {
                            ThreadSafetyGroup = threadSafetyGroup,
                            IsWriteAPI = true,
                        });
                    }
                }

                foreach (string readAPI in threadSafetyGroup.ReadAPIs)
                {
                    if (SignatureMatchUtils.IsWildcardMatch(interceptionPoint.API, readAPI))
                    {
                        return(new ThreadSafetyInterceptionPoint()
                        {
                            ThreadSafetyGroup = threadSafetyGroup,
                            IsWriteAPI = false,
                        });
                    }
                }
            }

            return(null);
        }