Exemplo n.º 1
0
        internal static string StringHashFromStackTrace(string stackTrace)
        {
            int    num    = 0;
            string result = "0";

            try
            {
                int             num2            = 0;
                int             num3            = 0;
                MatchCollection matchCollection = WatsonGenericReport.RegexFunctions.Matches(stackTrace);
                foreach (object obj in matchCollection)
                {
                    Match match = (Match)obj;
                    if (match.Groups.Count == 2)
                    {
                        string value = match.Groups[1].Value;
                        if (num == 0)
                        {
                            num3 = WatsonReport.ComputeHash(value, num3);
                        }
                        if (!value.Contains("Microsoft"))
                        {
                            continue;
                        }
                        num++;
                        num2 = WatsonReport.ComputeHash(value, num2);
                    }
                    if (num >= 10)
                    {
                        break;
                    }
                }
                if (num == 0)
                {
                    num2 = num3;
                }
                result = Convert.ToString(num2 & 65535, 16);
            }
            catch
            {
            }
            return(result);
        }
        protected override void PrepareBucketingParameters()
        {
            Exception baseException = null;
            string    s             = null;
            string    text          = null;
            string    text2         = null;
            string    text3         = null;
            Version   v             = null;
            int       num           = 0;
            int       num2          = 0;
            string    text4         = null;

            if (this.exception != null)
            {
                text2 = this.exception.GetType().ToString();
                WatsonExceptionReport.TryStringHashFromStackTrace(this.exception, base.IsFlagSet(ReportOptions.DeepStackTraceHash), out text3);
                baseException = this.exception.GetBaseException();
                try
                {
                    string text5 = (baseException == null) ? null : baseException.StackTrace;
                    if (!string.IsNullOrEmpty(text5))
                    {
                        MatchCollection matchCollection = WatsonExceptionReport.regexFunctions.Matches(text5);
                        foreach (object obj in matchCollection)
                        {
                            Match match = (Match)obj;
                            if (match.Groups.Count == 2)
                            {
                                if (text == null)
                                {
                                    text = match.Groups[1].Value;
                                }
                                if (match.Groups[1].Value.Contains("Microsoft."))
                                {
                                    text = match.Groups[1].Value;
                                    if (text.IndexOf("throw", StringComparison.OrdinalIgnoreCase) <= 0 && text.IndexOf("failfast", StringComparison.OrdinalIgnoreCase) <= 0 && text.IndexOf("assert", StringComparison.OrdinalIgnoreCase) <= 0 && text.IndexOf("error", StringComparison.OrdinalIgnoreCase) <= 0)
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (text != null)
                    {
                        string text6 = text;
                        try
                        {
                            int num3 = text.LastIndexOf(Type.Delimiter + ".");
                            if (num3 < 0)
                            {
                                num3 = text.LastIndexOf(Type.Delimiter);
                            }
                            text6 = text.Substring(0, num3);
                        }
                        catch
                        {
                        }
                        Type type = Type.GetType(text6);
                        if (type == null)
                        {
                            foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
                            {
                                type = assembly.GetType(text6);
                                if (type != null)
                                {
                                    break;
                                }
                            }
                        }
                        if (type != null)
                        {
                            if (WatsonReport.IsAssemblyDynamic(type.Assembly))
                            {
                                s = "[Dynamic Assembly]";
                                v = new Version(0, 0, 0, 0);
                            }
                            else
                            {
                                try
                                {
                                    s = Path.GetFileName(type.Assembly.Location);
                                }
                                catch
                                {
                                }
                                try
                                {
                                    object[] customAttributes = type.Assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false);
                                    if (customAttributes.Length == 1)
                                    {
                                        AssemblyFileVersionAttribute assemblyFileVersionAttribute = customAttributes[0] as AssemblyFileVersionAttribute;
                                        if (assemblyFileVersionAttribute != null)
                                        {
                                            v = new Version(assemblyFileVersionAttribute.Version);
                                        }
                                    }
                                }
                                catch
                                {
                                }
                            }
                        }
                    }
                    PropertyInfo propertyInfo = (baseException == null) ? null : baseException.GetType().GetProperty("DiagCtx");
                    if (propertyInfo != null)
                    {
                        MethodInfo getMethod = propertyInfo.GetGetMethod();
                        object     obj2      = getMethod.Invoke(baseException, null);
                        this.lids = obj2.ToString();
                        MatchCollection matchCollection2 = WatsonExceptionReport.regexLids.Matches(this.lids);
                        foreach (object obj3 in matchCollection2)
                        {
                            Match match2 = (Match)obj3;
                            if (match2.Groups.Count >= 2)
                            {
                                string value = match2.Groups[0].Value;
                                num  = WatsonReport.ComputeHash(value, num);
                                num2 = Convert.ToInt32(match2.Groups[1].Value);
                                if (match2.Groups.Count == 4)
                                {
                                    text4 = match2.Groups[3].Value;
                                }
                            }
                        }
                        num &= 65535;
                    }
                    if (ExWatson.MsInternal)
                    {
                        base.CrashDetails = WatsonReport.GetValidString(this.GetExWatsonCrashDetailsString());
                    }
                }
                catch
                {
                }
            }
            if (baseException != null && baseException.TargetSite != null)
            {
                this.baseExceptionTargetSite = base.EvaluateOrDefault <string>(delegate
                {
                    RuntimeMethodHandle methodHandle = baseException.TargetSite.MethodHandle;
                    IntPtr value2 = baseException.TargetSite.MethodHandle.Value;
                    return(baseException.TargetSite.MethodHandle.Value.ToString());
                }, "unknown");
                this.baseExceptionAssemblyName = base.EvaluateOrDefault <string>(delegate
                {
                    if (baseException.TargetSite.Module == null)
                    {
                        return("unknown");
                    }
                    return(baseException.TargetSite.Module.Name ?? "unknown");
                }, "unknown");
                this.baseExceptionMethodName = base.EvaluateOrDefault <string>(delegate
                {
                    string text7 = null;
                    if (baseException.TargetSite.ReflectedType != null)
                    {
                        text7 = baseException.TargetSite.ReflectedType.FullName;
                    }
                    string name = baseException.TargetSite.Name;
                    if (text7 == null || name == null)
                    {
                        return("unknown");
                    }
                    return(text7 + "." + name);
                }, "unknown");
            }
            else
            {
                this.baseExceptionTargetSite   = "unknown";
                this.baseExceptionAssemblyName = "unknown";
                this.baseExceptionMethodName   = "unknown";
            }
            try
            {
                if (this.lids != null)
                {
                    text3 = text3 + "-" + Convert.ToString(num, 16);
                    this.baseExceptionAssemblyName = this.baseExceptionAssemblyName + "-" + num2;
                    if (text4 != null)
                    {
                        text2 = text2 + "-" + text4;
                    }
                }
            }
            catch
            {
            }
            base.SetBucketingParameter <WatsonExceptionReport.BucketParamId>(WatsonExceptionReport.BucketParamId.ExceptionType, WatsonReport.GetValidString(text2));
            base.SetBucketingParameter <WatsonExceptionReport.BucketParamId>(WatsonExceptionReport.BucketParamId.AssemblyName, WatsonReport.GetValidString(s));
            base.SetBucketingParameter <WatsonExceptionReport.BucketParamId>(WatsonExceptionReport.BucketParamId.AssemblyVer, WatsonReport.ExchangeFormattedVersion(v));
            base.SetBucketingParameter <WatsonExceptionReport.BucketParamId>(WatsonExceptionReport.BucketParamId.ExMethodName, WatsonReport.GetValidString(text));
            base.SetBucketingParameter <WatsonExceptionReport.BucketParamId>(WatsonExceptionReport.BucketParamId.CallstackHash, WatsonReport.GetValidString(text3));
        }
Exemplo n.º 3
0
 public void UpdateHash(ref int hash)
 {
     hash = WatsonReport.ComputeHash(this.SanitizedFunctionName, hash);
     hash = WatsonReport.ComputeHash(this.FileName, hash);
 }
        internal static bool TryStringHashFromStackTrace(Exception exception, bool deep, out string stringHash)
        {
            bool result = false;
            int  num    = deep ? 50 : 10;

            stringHash = "0";
            try
            {
                int num2 = 0;
                int num3 = 0;
                int num4 = 0;
                while (exception != null)
                {
                    string stackTrace = exception.StackTrace;
                    if (!string.IsNullOrEmpty(exception.StackTrace))
                    {
                        MatchCollection matchCollection = WatsonExceptionReport.regexFunctions.Matches(stackTrace);
                        foreach (object obj in matchCollection)
                        {
                            Match match = (Match)obj;
                            if (match.Groups.Count == 2)
                            {
                                string value = match.Groups[1].Value;
                                if (num3 == 0)
                                {
                                    num4 = WatsonReport.ComputeHash(value, num4);
                                }
                                if (!value.Contains("Microsoft"))
                                {
                                    continue;
                                }
                                num3++;
                                num2 = WatsonReport.ComputeHash(value, num2);
                            }
                            if (num3 >= num)
                            {
                                break;
                            }
                        }
                        if (exception is SerializationException)
                        {
                            Match match2 = WatsonExceptionReport.regexSerialization.Match(exception.Message);
                            while (match2.Success)
                            {
                                string value2 = match2.Groups[1].Value;
                                num2   = WatsonReport.ComputeHash(value2, num2);
                                match2 = match2.NextMatch();
                            }
                        }
                    }
                    exception = exception.InnerException;
                }
                if (num3 == 0)
                {
                    num2 = num4;
                }
                stringHash = Convert.ToString(num2 & 65535, 16);
                result     = true;
            }
            catch
            {
            }
            return(result);
        }