Example #1
0
        private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            if (!Debugger.IsAttached)
            {
                var exception = e.ExceptionObject as Exception;

                LogTo.FatalException("Unhandled exception", exception);

                var result = MessageBox.Show($"{exception.GetType().FullName}: {exception.Message}\n" +
                                             "Create minidump? You can use this to report this issue to me.", "Unhandled exception",
                                             MessageBoxButton.YesNoCancel, MessageBoxImage.Error);

                if (result == MessageBoxResult.Yes)
                {
                    string date   = DateTime.UtcNow.ToString("yyyyMMddHHmmss");
                    string path   = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "dumps", $"dump_{date}.mdmp");
                    string folder = Path.GetDirectoryName(path);

                    if (!Directory.Exists(folder))
                    {
                        Directory.CreateDirectory(folder);
                    }

                    using (var fs = new FileStream(path, FileMode.Create, FileAccess.ReadWrite, FileShare.Write))
                    {
                        MiniDump.Write(fs.SafeFileHandle, MiniDump.Option.Normal | MiniDump.Option.WithIndirectlyReferencedMemory | MiniDump.Option.WithDataSegs, MiniDump.ExceptionInfo.Present);
                    }

                    using (var file = File.OpenWrite(path + ".zip"))
                        using (var zip = new ZipArchive(file, ZipArchiveMode.Create))
                        {
                            using (var dumpFile = File.OpenRead(path))
                                using (var entry = zip.CreateEntry(Path.GetFileName(path)).Open())
                                {
                                    dumpFile.CopyTo(entry);
                                }

                            using (var logFile = File.Open("logs/lrm.log", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                                using (var entry = zip.CreateEntry("log.txt").Open())
                                {
                                    logFile.CopyTo(entry);
                                }
                        }

                    File.Delete(path);

                    Process.Start("explorer.exe", $"/select, \"{path}.zip\"");
                }

                if (e.IsTerminating)
                {
                    Legendary_Rune_Maker.MainWindow.DisposeTaskbar();
                    Process.GetCurrentProcess().Kill();
                }
            }
        }
Example #2
0
 /// <summary>
 /// Dumps the contents of memory to a dumpfile.
 /// </summary>
 /// <param name="dumpFolder">Path to the folder to store the dump file.</param>
 /// <param name="e">The exception which is being handled.</param>
 private void WriteMemoryDump(string dumpFolder, Exception e)
 {
     //Open a file stream
     using (FileStream stream = new FileStream(Path.Combine(dumpFolder, MemoryDumpFileName),
                                               FileMode.OpenOrCreate, FileAccess.Write, FileShare.None))
     {
         //Store the exception information
         MiniDump.Dump(stream);
     }
 }
Example #3
0
        private static void HandleException(Exception exception)
        {
            if (exception == null)
            {
                return;
            }
            var zipFile = Path.Combine(ApplicationPath.AppData,
                                       $"{Application.ProductName}-crashlog-{DateTime.UtcNow.Date.Day}_{DateTime.UtcNow.Date.Month}_{DateTime.UtcNow.Date.Year}.zip");
            var exceptionMessage = exception.Message;

            if (exception.InnerException != null)
            {
                exceptionMessage += $"\n{exception.InnerException.Message}";
            }

            var message =
                $@"It seems {Application.ProductName} has crashed.

{exceptionMessage}

Do you want to save a log of the error that occurred?
This could be useful to fix bugs. Please post this file in the issues section
File Location: {zipFile}";
            var result = MessageBox.Show(message, $@"{Application.ProductName} crashed...", MessageBoxButtons.YesNo,
                                         MessageBoxIcon.Error);

            if (result == DialogResult.Yes)
            {
                using (new HourGlass())
                {
                    var fileName = Path.Combine(ApplicationPath.Default, Environment.MachineName + ".dmp");
                    using (
                        var fs = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite,
                                                FileShare.Write))
                    {
                        MiniDump.Write(fs.SafeFileHandle,
                                       MiniDump.Option.Normal | MiniDump.Option.WithThreadInfo | MiniDump.Option.WithHandleData |
                                       MiniDump.Option.WithDataSegs, MiniDump.ExceptionInfo.Present);
                    }

                    Log.Fatal(exception, "Exception Occurred ");

                    if (File.Exists(zipFile))
                    {
                        File.Delete(zipFile);
                    }

                    Log.CloseAndFlush();

                    ZipFile.CreateFromDirectory(ApplicationPath.Default, zipFile);
                }

                Process.Start("explorer.exe", "/select," + @zipFile);
            }
        }
Example #4
0
    private static void CurrentDomain_FirstChanceException(object sender, System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e)
    {
        var exceptionFullName = e.Exception?.GetType().FullName ?? string.Empty;
        var exceptionTypeName = Array.Find(Settings.ExceptionTypes ?? Array.Empty <string>(), item => exceptionFullName.Contains(item));

        if (exceptionTypeName != null)
        {
            if (Interlocked.CompareExchange(ref _miniDumpExecuted, 1, 0) == 0)
            {
                MiniDump.WriteDump(Process.GetCurrentProcess(), exceptionTypeName);
            }
        }
    }
Example #5
0
        private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var fileName = string.Format(@"turbofilmvpn_crash_{0}_{1}.mdmp", DateTime.Today.ToShortDateString(), DateTime.Now.Ticks);

            if (e.ExceptionObject != null)
            {
                string stackTrace = ((Exception)e.ExceptionObject).StackTrace;
            }
            using (var stream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite, FileShare.Write))
            {
                MiniDump.Write(stream.SafeFileHandle, MiniDump.Option.WithFullMemory, e.ExceptionObject != null ? MiniDump.ExceptionInfo.Present : MiniDump.ExceptionInfo.None);
            }
        }
Example #6
0
        /// <summary>写当前线程的MiniDump</summary>
        /// <param name="dumpFile">如果不指定,则自动写入日志目录</param>
        public static void WriteMiniDump(String dumpFile)
        {
            if (String.IsNullOrEmpty(dumpFile))
            {
                dumpFile = String.Format("{0:yyyyMMdd_HHmmss}.dmp", DateTime.Now);
                if (!String.IsNullOrEmpty(LogPath))
                {
                    dumpFile = Path.Combine(LogPath, dumpFile);
                }
            }

            MiniDump.TryDump(dumpFile, MiniDump.MiniDumpType.WithFullMemory);
        }
Example #7
0
        private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Exception ex = e.ExceptionObject as Exception;

            LogUtil.Error(ex.Message);
            LogUtil.Error(ex.StackTrace);
            string dateStr = DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss");
            var    option  = MiniDump.Option.WithFullMemory | MiniDump.Option.WithHandleData |
                             MiniDump.Option.WithUnloadedModules | MiniDump.Option.WithProcessThreadData |
                             MiniDump.Option.WithThreadInfo;

            MiniDump.TryDump(string.Format("log\\QSWMaintain_{0}.dmp", dateStr), option);
        }
Example #8
0
        private static void Main()
        {
            var args = Environment.GetCommandLineArgs();

            //Process command-line args
            processArgs(args);
            //Register minidump dumper only if the app isn't being debugged. No use filling up hard drives with s***e
            if (!System.Diagnostics.Debugger.IsAttached)
            {
                MiniDump.Register("crashdump-" + Guid.NewGuid().ToString("N") + ".dmp",
                                  fullDump
                                      ? MiniDump.MINIDUMP_TYPE.MiniDumpWithFullMemory
                                      : MiniDump.MINIDUMP_TYPE.MiniDumpNormal);
            }
            Application.Run(new MainWindow());
        }
Example #9
0
        static void EngineFailed(string allText, string title)
        {
#if !DEBUG
            MiniDump.Write();
#endif
            MessageBox.Show(
                allText,
                title,
                MessageBoxButtons.OK,
                MessageBoxIcon.Error
                );
            Critical.NoThrow(() =>
            {
                GameAPI.I.Core.Log.Error("--- " + title);
                GameAPI.I.Core.Log.Error(allText);
                GameAPI.I.Core.Log.End();
            });
        }
Example #10
0
        private static string DumpProcess(bool isFirstChance = false)
        {
            var time = DateTime.Now;

            string fileName;

            if (isFirstChance)
            {
                fileName = Path.Combine(DumpDirectory, "tank_inspector_previous_first_chance.dmp");
            }
            else
            {
                fileName = Path.Combine(DumpDirectory, $"tank_inspector_{time.ToString("yyyy_MM_dd_HH_mm_ss")}.dmp");
            }

            using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite, FileShare.Write))
            {
                MiniDump.Write(fs.SafeFileHandle, MiniDump.Option.Normal);
            }
            _hasDumped = true;
            return(fileName);
        }
Example #11
0
        static void Main()
        {
            try
            {
                //初始化MiniDump
                MiniDump.Init();

                //SplashScreenForm.ShowSplash();


                //SplashScreenForm.CloseSplash();

                MobilityForm mobilityForm = SpringHelper.GetObject <MobilityForm>("mobilityForm");
                Application.Run(mobilityForm);
                //MainForm mainForm = SpringHelper.GetObject<MainForm>("mainForm");
                //ControlForm controlForm = SpringHelper.GetObject<ControlForm>("controlForm");
                //Application.Run(controlForm);
            }
            catch (Exception e)
            {
            }
        }
Example #12
0
        public void Error(Type callingType, string message, Exception exception)
        {
            var logger = LogManager.GetLogger(callingType);

            if (logger == null)
            {
                return;
            }

            var dump = false;

            if (IsTimeoutThreadAbortException(exception))
            {
                message += "\r\nThe thread has been aborted, because the request has timed out.";

                // dump if configured, or if stacktrace contains Monitor.ReliableEnter
                dump = UmbracoConfig.For.CoreDebug().DumpOnTimeoutThreadAbort || IsMonitorEnterThreadAbortException(exception);

                // dump if it is ok to dump (might have a cap on number of dump...)
                dump &= MiniDump.OkToDump();
            }

            if (dump)
            {
                try
                {
                    var dumped = MiniDump.Dump(withException: true);
                    message += dumped
                        ? "\r\nA minidump was created in App_Data/MiniDump"
                        : "\r\nFailed to create a minidump";
                }
                catch (Exception e)
                {
                    message += string.Format("\r\nFailed to create a minidump ({0}: {1})", e.GetType().FullName, e.Message);
                }
            }

            logger.Error(message, exception);
        }
Example #13
0
    private void DumpThreadAborts(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
    {
        if (!IsTimeoutThreadAbortException(logEvent.Exception))
        {
            return;
        }

        var message = "The thread has been aborted, because the request has timed out.";

        // dump if configured, or if stacktrace contains Monitor.ReliableEnter
        var dump = _coreDebugSettings.DumpOnTimeoutThreadAbort ||
                   IsMonitorEnterThreadAbortException(logEvent.Exception);

        // dump if it is ok to dump (might have a cap on number of dump...)
        dump &= MiniDump.OkToDump(_hostingEnvironment);

        if (!dump)
        {
            message += ". No minidump was created.";
            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ThreadAbortExceptionInfo", message));
        }
        else
        {
            try
            {
                var dumped = MiniDump.Dump(_marchal, _hostingEnvironment, withException: true);
                message += dumped
                    ? ". A minidump was created in App_Data/MiniDump."
                    : ". Failed to create a minidump.";
                logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ThreadAbortExceptionInfo", message));
            }
            catch (Exception ex)
            {
                message = "Failed to create a minidump. " + ex;
                logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ThreadAbortExceptionInfo", message));
            }
        }
    }
Example #14
0
        public App()
        {
            try
            {
                InitializeComponent();
                InitException();
                //  this.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown;
                Startup += Application_Startup;
                Exit    += Application_Exit;

                // ThemesHelper.InitResource();

                ThemesHelper.InitSkinData();

                ThemesHelper.SetSkin("Default");
            }
            catch (Exception ex)
            {
                LogHelper.Instance.WirteErrorMsg(string.Format("App Error,Msg:{0}", ex.Message));
                LogHelper.Instance.WirteErrorMsg(string.Format("App Error,Msg:{0}", ex.StackTrace));
                MiniDump.TryDump(String.Format("{0}MiniDmp.dmp", DateTime.Now.ToString()));
            }
        }
Example #15
0
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            string dumpFile = System.IO.Path.Combine(System.Environment.CurrentDirectory, string.Format("thread-dump-{0}.dmp", DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss")));

            MiniDump.Write(dumpFile);
        }
Example #16
0
        public static void parse(byte[] bytes)
        {
            MiniDump minidump = new MiniDump();

            using (BinaryReader fileBinaryReader = new BinaryReader(new MemoryStream(bytes)))
            {
                // parse header && streams
                minidump.fileBinaryReader = fileBinaryReader;
                minidump.header           = Header.ParseHeader(minidump);
                List <Streams.Directory.MINIDUMP_DIRECTORY> directories = Streams.Directory.ParseDirectory(minidump);
                Parse.parseMM(ref minidump, directories);
                //Helpers.PrintProperties(minidump.header);
                //Helpers.PrintProperties(minidump.sysinfo);
                //Helpers.PrintProperties(minidump.modules);
                //Helpers.PrintProperties(minidump.MinidumpMemory64List);

                minidump.sysinfo.msv_dll_timestamp = 0;
                foreach (ModuleList.MinidumpModule mod in minidump.modules)
                {
                    if (mod.name.Contains("lsasrv.dll"))
                    {
                        minidump.sysinfo.msv_dll_timestamp = (int)mod.timestamp;
                        break;
                    }
                }

                // parse lsa
                minidump.lsakeys = LsaDecryptor.choose(minidump, lsaTemplate.get_template(minidump.sysinfo));
                //Console.WriteLine(Helpers.ByteArrayToString(minidump.lsakeys.iv));
                //Console.WriteLine(Helpers.ByteArrayToString(minidump.lsakeys.des_key));
                //Console.WriteLine(Helpers.ByteArrayToString(minidump.lsakeys.aes_key));

                // parse sessions
                minidump.logonlist  = LogonSessions.FindSessions(minidump, msv.get_template(minidump.sysinfo));
                minidump.klogonlist = KerberosSessions.FindSessions(minidump, (kerberos.get_template(minidump.sysinfo)));

                //parse credentials
                try
                {
                    Msv1_.FindCredentials(minidump, msv.get_template(minidump.sysinfo));
                }
                catch (Exception e)
                {
                    Console.WriteLine($"MSV failed: {e.Message}");
                }

                try
                {
                    WDigest_.FindCredentials(minidump, wdigest.get_template(minidump.sysinfo));
                }
                catch (Exception e)
                {
                    Console.WriteLine($"WDigest failed: {e.Message}");
                }

                try
                {
                    Kerberos_.FindCredentials(minidump, kerberos.get_template(minidump.sysinfo));
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Kerberos failed: {e.Message}");
                }

                try
                {
                    Tspkg_.FindCredentials(minidump, tspkg.get_template(minidump.sysinfo));
                }
                catch (Exception e)
                {
                    Console.WriteLine($"TsPkg failed: {e.Message}");
                }

                try
                {
                    Credman_.FindCredentials(minidump, credman.get_template(minidump.sysinfo));
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Credman failed: {e.Message}");
                }

                try
                {
                    Ssp_.FindCredentials(minidump, ssp.get_template(minidump.sysinfo));
                }
                catch (Exception e)
                {
                    Console.WriteLine($"SSP failed: {e.Message}");
                }

                //try
                //{
                //    LiveSsp_.FindCredentials(minidump, livessp.get_template(minidump.sysinfo));
                //}
                //catch (Exception e)
                //{
                //    Console.WriteLine($"LiveSSP failed: {e.Message}");
                //}

                try
                {
                    Cloudap_.FindCredentials(minidump, cloudap.get_template(minidump.sysinfo));
                }
                catch (Exception e)
                {
                    Console.WriteLine($"CloudAP failed: {e.Message}");
                }

                try
                {
                    Dpapi_.FindCredentials(minidump, dpapi.get_template(minidump.sysinfo));
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Dpapi failed: {e.Message}");
                }

                foreach (Logon log in minidump.logonlist)
                {
                    try
                    {
                        if (log.Wdigest != null || log.Msv != null || log.Kerberos != null || log.Tspkg != null || log.Credman != null || log.Ssp != null || log.LiveSsp != null || log.Dpapi != null || log.Cloudap != null)
                        {
                            Console.WriteLine("=====================================================================");
                            //Helpers.PrintProperties(log);
                            Console.WriteLine($"[*] LogonId:     {log.LogonId.HighPart}:{log.LogonId.LowPart}");
                            if (!string.IsNullOrEmpty(log.LogonType))
                            {
                                Console.WriteLine($"[*] LogonType:   {log.LogonType}");
                            }
                            Console.WriteLine($"[*] Session:     {log.Session}");
                            if (log.LogonTime.dwHighDateTime != 0)
                            {
                                Console.WriteLine($"[*] LogonTime:   {Helpers.ToDateTime(log.LogonTime):yyyy-MM-dd HH:mm:ss}");
                            }
                            Console.WriteLine($"[*] UserName:    {log.UserName}");
                            if (!string.IsNullOrEmpty(log.SID))
                            {
                                Console.WriteLine($"[*] SID:         {log.SID}");
                            }
                            if (!string.IsNullOrEmpty(log.LogonDomain))
                            {
                                Console.WriteLine($"[*] LogonDomain: {log.LogonDomain}");
                            }
                            if (!string.IsNullOrEmpty(log.LogonServer))
                            {
                                Console.WriteLine($"[*] LogonServer: {log.LogonServer}");
                            }
                        }
                        if (log.Msv != null)
                        {
                            Helpers.PrintProperties(log.Msv, "[*] Msv", 4);
                        }
                        if (log.Kerberos != null)
                        {
                            Helpers.PrintProperties(log.Kerberos, "[*] Kerberos", 4);
                        }
                        if (log.Wdigest != null)
                        {
                            foreach (WDigest wd in log.Wdigest)
                            {
                                Helpers.PrintProperties(wd, "[*] Wdigest", 4);
                            }
                        }
                        if (log.Ssp != null)
                        {
                            foreach (Ssp s in log.Ssp)
                            {
                                Helpers.PrintProperties(s, "[*] Ssp", 4);
                            }
                        }
                        if (log.Tspkg != null)
                        {
                            foreach (Tspkg ts in log.Tspkg)
                            {
                                Helpers.PrintProperties(ts, "[*] TsPkg", 4);
                            }
                        }
                        if (log.Credman != null)
                        {
                            foreach (CredMan cm in log.Credman)
                            {
                                Helpers.PrintProperties(cm, "[*] CredMan", 4);
                            }
                        }
                        if (log.Dpapi != null)
                        {
                            foreach (Dpapi dpapi in log.Dpapi)
                            {
                                Helpers.PrintProperties(dpapi, "[*] Dpapi", 4);
                            }
                        }
                        if (log.Cloudap != null)
                        {
                            foreach (Cloudap cap in log.Cloudap)
                            {
                                Helpers.PrintProperties(cap, "[*] CloudAp", 4);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"{e.Message}");
                    }
                }
            }
        }