Esempio n. 1
0
        private void dumpmenuDump_Click(object sender, EventArgs e)
        {
            bool anychecked = false;

            foreach (TreeNode n in treeView.Nodes)
            {
                if (n.Checked)
                {
                    anychecked = true;
                    break;
                }
            }

            if (!anychecked)
            {
                MessageBox.Show("No information was selected to be dumped", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            ToggleDump(false);

            string dir       = null;
            long   timestamp = 0;

            for (int i = 0; i < 5; i++)
            {
                timestamp = (long)Math.Round(Program.FormatUnixTimestamp(DateTime.UtcNow));
                dir       = Path.Combine(Program.Temp, timestamp.ToString()) + @"\";

                if (Directory.Exists(dir)) //This should never happen, but I'll account for it just in case.
                {
                    if (i >= 4)
                    {
                        MessageBox.Show("Could not create temporary folder", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    Thread.Sleep(1000);
                    continue;
                }

                break;
            }

            Directory.CreateDirectory(dir);

            dform       = new DumpForm();
            dform.Load += delegate
            {
                Async.RunAsync((Async.Action) delegate
                {
                    dumpdir = dir;
                    html    = new StringBuilder();
                    html.AppendLine("<!DOCTYPE html><html><head><style type=\"text/css\">a { text-decoration: none; color: #000AFF; }</style></head><body style=\"background-color: #FFFFFF; font-family: sans-serif; white-space: nowrap;\"><ul>");
                    for (int i = 0; i < treeView.Nodes.Count; i++)
                    {
                        if (treeView.Nodes[i].Checked)
                        {
                            DumpNode(treeView.Nodes[i], ref Modules[i].Nodes, new TitleInfo(Attribs[i].Name, Attribs[i].Description), InformationType.Title);
                        }
                    }
                    html.Append("</ul></body></html>");

                    FileStream fs = null;
                    try
                    {
                        fs = File.Open(dir + "index-tree.html", FileMode.Create, FileAccess.Write, FileShare.None);


                        byte[] data = Encoding.ASCII.GetBytes(html.ToString());
                        fs.Write(data, 0, data.Length);

                        File.WriteAllText(dir + "index.html", "<!DOCTYPE html><html><head><title>Clearbytes information dump</title><style type=\"text/css\">html, body { margin: 0; padding: 0; width: 100%; height: 100%; background-color: #CCC; font-family: sans-serif; overflow: hidden; } iframe { position: absolute; top: 0; height: 95%; border: none; background-color: #FFFFFF; }</style></head><body><div style=\"padding: 4px 8px; background-color: #F0F0F0; border-bottom: 1px solid #CCC; color: #888; font-size: 12px;\"><span style=\"font-weight: 600;\">Clearbytes info-dump</span><a href=\"../archives/" + timestamp.ToString() + ".zip\" style=\"float: right;\">Download as zip</a></div><div style=\"position: relative; height: 100%;\"><iframe src=\"index-tree.html\" style=\"left: 0; width: 25%;\"></iframe><iframe name=\"viewport\" src=\"\" style=\"right: 0; width: 73%; padding-left: 1.5%\"></iframe></div></body></html>");
                    }
                    finally
                    {
                        if (fs != null && fs.CanWrite)
                        {
                            fs.Dispose();
                        }

                        ZipFolder(dir, Program.Archives + timestamp.ToString() + ".zip");

                        string browser = (string)Microsoft.Win32.Registry.GetValue(@"HKEY_CLASSES_ROOT\http\shell\open\command", "", null);

                        if (browser != null)
                        {
                            string prog = browser.Split('"')[1];
                            Process.Start(prog, String.Format("\"file:///{0}\"", dir + "index.html"));
                        }

                        this.Invoke((Async.Action) delegate
                        {
                            treeView.CheckBoxes = false;
                            if (dform != null)
                            {
                                dform.Dispose();
                            }
                        });
                    }
                });
            };

            dform.ShowDialog();
        }
Esempio n. 2
0
        private void menuFileStart_Click(object sender, EventArgs e)
        {
            if (searchrunning || dumpmode)
            {
                searchcancel = true;
                return;
            }

            SearchParams sp = new SearchParams();

            sp.ShowDialog();
            if (sp.canceled)
            {
                sp.Dispose(); return;
            }

            menuFileDump.Enabled = false;

            SwitchPanel(InformationType.None);

            //Clear TreeView and release bitmap data
            treeView.Nodes.Clear();
            foreach (Image img in Bridge.ImageCache)
            {
                img.Dispose();
            }
            Bridge.ImageCache.Clear();
            Modules.Clear();
            Attribs.Clear();

            menuFileStart.Text = "Cancel search";
            this.Text          = "Clearbytes - Searching";

            ulong taskbarcount = (ulong)sp.Modules.Count;

            if (WinAPI.ISABOVEVISTA)
            {
                WinAPI.Taskbar.SetProgressState(this.Handle, WinAPI.TaskbarStates.Normal);
                WinAPI.Taskbar.SetProgressValue(this.Handle, 0, taskbarcount);
            }

            #region Reflect internal modules
            IntPtr mainhandle = this.Handle;
            Async.RunAsync(delegate
            {
                searchrunning = true;

                /*Type[] classes = Assembly.GetExecutingAssembly().GetTypes();
                 *
                 * foreach (Type c in classes)
                 * {
                 *  if (searchcancel) break;
                 *
                 *  if (c.BaseType != typeof(ClearbytesModule) || c.Namespace != "Clearbytes.Modules")
                 *      continue;
                 *
                 *  object[] mods = c.GetCustomAttributes(typeof(ClearbytesModuleAttributes), false);
                 *  if (mods.Length < 1) continue;
                 *
                 *  ClearbytesModuleAttributes attrib = (ClearbytesModuleAttributes)mods[0];
                 *  if (!attrib.Active) continue;
                 *
                 *  ClearbytesModule instance = (ClearbytesModule)Activator.CreateInstance(c);
                 *
                 *  Modules.Add(instance);
                 *  Attribs.Add(attrib);
                 *
                 *  TreeNode node = new TreeNode(attrib.Name);
                 *  //this.Invoke((Async.Action)delegate { treeView.Nodes.Add(node); });
                 *  instance.SetParent(node);
                 *  instance.SetParentTreeView(treeView);
                 *
                 *  //try
                 *  //{
                 *      instance.Search();
                 *  //}
                 *  //catch { node.Text += " (ERROR)"; }
                 * }*/

                ulong progress = 1;
                for (int i = 0; i < sp.Modules.Count; i++, progress++)
                {
                    if (searchcancel)
                    {
                        break;
                    }

                    ClearbytesModule instance = (ClearbytesModule)Activator.CreateInstance(sp.Modules[i]);

                    Modules.Add(instance);
                    Attribs.Add(sp.Attribs[i]);

                    TreeNode node = new TreeNode(sp.Attribs[i].Name);
                    //this.Invoke((Async.Action)delegate { treeView.Nodes.Add(node); });
                    instance.SetParent(node);
                    instance.SetParentTreeView(treeView);

                    try { instance.Search(); }
                    catch (Exception ex)
                    {
                        this.Invoke((Async.Action) delegate
                        {
                            node.Text += " (ERROR)";
                            sp.Attribs[i].Description = ex.ToString();
                        });
                    }

                    if (WinAPI.ISABOVEVISTA)
                    {
                        WinAPI.Taskbar.SetProgressValue(mainhandle, progress, taskbarcount);
                    }
                }

                searchrunning = false;

                this.Invoke((Async.Action) delegate
                {
                    sp.Dispose();
                    menuFileStart.Text = "Start search";
                    this.Text          = "Clearbytes";

                    if (treeView.Nodes.Count > 0)
                    {
                        menuFileDump.Enabled = true;
                    }

                    if (WinAPI.ISABOVEVISTA)
                    {
                        WinAPI.Taskbar.SetProgressState(this.Handle, WinAPI.TaskbarStates.NoProgress);
                    }
                });

                searchcancel = false;
            });
            #endregion
        }