/// <summary> /// Loads a plan into the lookup dictionary. /// </summary> /// <param name="plan">A <see cref="TrapPlan" />.</param> public void AddPlan(TrapPlan plan) { if (plan != null) { if (plan.API.Contains("*") || plan.Method.Contains("*")) { this.wildCardPlans.Add(plan); } else { string planId = plan.GetID(); if (this.nonwildCardPlans.ContainsKey(planId)) { if (plan.HitCounts != null) { this.nonwildCardPlans[planId].HitCounts.AddRange(plan.HitCounts); } } else { this.nonwildCardPlans[planId] = plan; } } } }
/// <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); }
/// <summary> /// Gets the identifier. /// </summary> /// <returns>System.String.</returns> public string GetID() { return(TrapPlan.GetID(this.API, this.Method, this.ILOffset)); }