private void getSessionTokenTask_Completed(object result)
 {
     if (result != null)
     {
         uploadTask = new ThreadTask();
         uploadTask.RunTask += uploadTask_RunTask;
         uploadTask.Completed += uploadTask_Completed;
         uploadTask.Start(result);
     }
 }
        private void webClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            // Check if the file is actually an executable file.
            if (!_redirected)
            {
                _redirected = true;

                try
                {
                    bool isHtml = false;

                    using (var file = new BinaryReader(File.OpenRead(_fileName)))
                    {
                        if (!file.ReadChars(2).Equals("MZ".ToCharArray()))
                        {
                            isHtml = true;
                        }
                    }

                    if (isHtml)
                    {
                        string text = File.ReadAllText(_fileName);

                        // Assume this is from Ohloh.
                        int iframeIndex = text.IndexOf("window.delayed_iframe");

                        if (iframeIndex == -1)
                            return;

                        int httpIndex = text.IndexOf("http://", iframeIndex);

                        if (httpIndex == -1)
                            return;

                        int quoteIndex = text.IndexOf("'", httpIndex);

                        if (quoteIndex == -1)
                            return;

                        _webClient.DownloadFileAsync(new Uri(text.Substring(httpIndex, quoteIndex - httpIndex)), _fileName);

                        return;
                    }
                }
                catch (Exception ex)
                {
                    Logging.Log(ex);
                }
            }

            if (!e.Cancelled)
            {
                _verifyTask = new ThreadTask();
                _verifyTask.RunTask += verifyTask_RunTask;
                _verifyTask.Completed += verifyTask_Completed;
                _verifyTask.Start();
            }
            else
            {
                var webException = e.Error as WebException;

                if (webException != null && webException.Status != WebExceptionStatus.RequestCanceled)
                {
                    PhUtils.ShowException("Unable to download the update", webException);
                }
            }
        }
Example #3
0
        public static void SaveToFile(IWin32Window owner)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            // HTML Files (*.htm;*.html)|*.htm;*.html
            sfd.Filter = "Process Hacker Dump Files (*.phi)|*.phi|Text Files (*.txt;*.log)|*.txt;*.log|" + 
                "Comma-separated values (*.csv)|*.csv|All Files (*.*)|*.*";

            //if (Program.HackerWindow.SelectedPid == -1)
            //{
            //    sfd.FileName = "Process List.txt";
            //}
            //else
            //{
            //    string processName = Windows.GetProcessName(Program.HackerWindow.SelectedPid);

            //    if (processName != null)
            //        sfd.FileName = processName + ".txt";
            //    else
            //        sfd.FileName = "Process Info.txt";
            //}
            sfd.FileName = "phdump-" + DateTime.Now.ToString("ddMMyy") + ".phi";

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                FileInfo fi = new FileInfo(sfd.FileName);
                string ext = fi.Extension.ToLowerInvariant();

                if (ext == ".phi")
                {
                    ThreadTask dumpTask = new ThreadTask();

                    dumpTask.RunTask += delegate(object result, ref object param)
                    {
                        var mfs = Dump.BeginDump(fi.FullName, ProcessHacker.Native.Mfs.MfsOpenMode.OverwriteIf);

                        Dump.DumpProcesses(mfs, Program.ProcessProvider);
                        Dump.DumpServices(mfs);

                        mfs.Dispose();
                    };

                    ProgressWindow progressWindow = new ProgressWindow();

                    progressWindow.CloseButtonVisible = false;
                    progressWindow.ProgressBarStyle = ProgressBarStyle.Marquee;
                    progressWindow.ProgressText = "Creating the dump file...";

                    dumpTask.Completed += (result) =>
                    {
                        progressWindow.SetCompleted();

                        if (progressWindow.IsHandleCreated)
                            progressWindow.BeginInvoke(new MethodInvoker(progressWindow.Close));
                    };

                    dumpTask.Start();

                    if (dumpTask.Running)
                        progressWindow.ShowDialog(owner);

                    if (dumpTask.Exception != null)
                        PhUtils.ShowException("Unable to create the dump file", dumpTask.Exception);

                    return;
                }

                try
                {
                    using (StreamWriter sw = new StreamWriter(fi.FullName))
                    {
                        Program.HackerWindow.ProcessTree.Tree.ExpandAll();

                        if (ext == ".htm" || ext == ".html")
                        {

                        }
                        else if (ext == ".csv")
                        {
                            sw.Write(GetProcessTreeText(false));
                        }
                        else
                        {
                            sw.Write(GetEnvironmentInfo());
                            sw.WriteLine();
                            sw.Write(GetProcessTreeText(true));
                            sw.WriteLine();

                            if (Program.HackerWindow.SelectedPid != -1)
                            {
                                sw.Write(GetProcessDetailsText(Program.HackerWindow.SelectedPid));
                                sw.WriteLine();
                            }
                        }
                    }
                }
                catch (IOException ex)
                {
                    PhUtils.ShowException("Unable to save the process list", ex);
                }
            }
        }
        private void VirusTotalUploaderWindow_Load(object sender, EventArgs e)
        {
            labelFile.Text = string.Format("Uploading: {0}", processName);

            FileInfo finfo = new FileInfo(fileName);
            if (!finfo.Exists)
            {
                if (OSVersion.HasTaskDialogs)
                {
                    TaskDialog td = new TaskDialog
                    {
                        PositionRelativeToWindow = true,
                        Content = "The selected file doesn't exist or couldnt be found!", 
                        MainInstruction = "File Location not Available!", 
                        WindowTitle = "System Error", 
                        MainIcon = TaskDialogIcon.CircleX, 
                        CommonButtons = TaskDialogCommonButtons.Ok
                    };

                    td.Show(Program.HackerWindow.Handle);
                }
                else
                {
                    MessageBox.Show(
                       this, "The selected file doesn't exist or couldnt be found!",
                       "System Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation
                       );
                }

                this.Close();
            }
            else if (finfo.Length >= 20971520 /* 20MB */)
            {
                if (OSVersion.HasTaskDialogs)
                {
                    TaskDialog td = new TaskDialog
                    {
                        PositionRelativeToWindow = true,
                        Content = "This file is larger than 20MB, above the VirusTotal limit!", 
                        MainInstruction = "File is too large", 
                        WindowTitle = "VirusTotal Error", 
                        MainIcon = TaskDialogIcon.CircleX, 
                        CommonButtons = TaskDialogCommonButtons.Ok
                    };
                    td.Show(Program.HackerWindow.Handle);
                }
                else
                {
                     MessageBox.Show(
                        this, "This file is larger than 20MB and is above the VirusTotal size limit!",
                        "VirusTotal Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation
                        );
                }

                this.Close();
            }
            else
            {
                totalFileSize = finfo.Length;
            }

            uploadedLabel.Text = "Uploaded: Initializing";
            speedLabel.Text = "Speed: Initializing";

            ThreadTask getSessionTokenTask = new ThreadTask();

            getSessionTokenTask.RunTask += this.getSessionTokenTask_RunTask;
            getSessionTokenTask.Completed += this.getSessionTokenTask_Completed;
            getSessionTokenTask.Start();
        }
 private void getSessionTokenTask_Completed(object result)
 {
     if (result != null) //incase theres an expcetion getting sessiontoken
     {
         uploadTask = new ThreadTask();
         uploadTask.RunTask += uploadTask_RunTask;
         uploadTask.Completed += uploadTask_Completed;
         uploadTask.Start(result);
     }
 }