Пример #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            gViewer.SelectionChanged += new EventHandler(gViewer_SelectionChanged);
            gViewer.MouseUp          += new MouseEventHandler(gViewer_MouseUp);
            gViewer.MouseWheel       += new MouseEventHandler(gViewer_MouseWheel);

            ida = new ida_client(this.Handle);

            List <uint> Servers = ida.FindServers(); //remember IDASRVR does nto exist for x64 disasm yet...

            if (Servers.Count == 0)
            {
                debugLog("IDA not found...");
            }
            else if (Servers.Count == 1)
            {
                ida.IDA_HWND = (int)Servers[0];
                debugLog("IDA hwnd: " + ida.IDA_HWND);
                debugLog("IDA File: " + Path.GetFileName(ida.LoadedFileName()));
            }
            else
            {
                debugLog(Servers.Count + " IDA windows open, will scan..");
            }

            string[] tmp  = Environment.GetCommandLineArgs();
            string   last = Path.GetTempPath() + "lastGraph.txt";
            string   f    = "";

            this.Visible = true;

            if (false && System.Diagnostics.Debugger.IsAttached)
            {
                string testFile = Application.StartupPath + "\\test.txt";
                if (!File.Exists(testFile))
                {
                    testFile = testFile.Replace("\\bin\\Debug", "");
                }
                if (File.Exists(testFile))
                {
                    graph.LoadFile(testFile);
                }
            }
            else //load from command line or lastgraph if not..
            {
                for (int i = tmp.Length - 1; i > 0; i--)
                {
                    //MessageBox.Show(i + " " + tmp[i]);
                    if (File.Exists(tmp[i]))
                    {
                        f = tmp[i]; break;
                    }
                }

                if (File.Exists(f))
                {
                    try
                    {
                        try
                        {
                            if (File.Exists(last))
                            {
                                File.Delete(last);
                            }
                            File.Copy(f, last);
                        }
                        catch (Exception ex) { /*fu win7*/ }
                        debugLog("Loading " + f);
                        graph.LoadFile(f);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error loading: " + f + "\n\n" + ex.StackTrace);
                    }
                }
                else if (File.Exists(last))
                {
                    debugLog("Loading last graph");
                    graph.LoadFile(last);
                }
            }

            if (Servers.Count > 1)  //multiple IDA servers active, lets try to find the right one..
            {
                uint target = FindServerForGraph(Servers);
                if (target == 0)
                {
                    debugLog("No IDA match not found.");
                }
                else
                {
                    ida.IDA_HWND = (int)target;
                    debugLog("IDA hwnd: " + ida.IDA_HWND);
                    debugLog("IDA File: " + Path.GetFileName(ida.LoadedFileName()));
                }
            }

            if (gViewer.Graph != null)
            {
                lvNodes.Columns[0].Text = gViewer.Graph.NodeMap.Count + " Nodes";
            }
        }
Пример #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            gViewer.SelectionChanged += new EventHandler(gViewer_SelectionChanged);
            gViewer.MouseUp += new MouseEventHandler(gViewer_MouseUp);
            gViewer.MouseWheel += new MouseEventHandler(gViewer_MouseWheel);

            ida = new ida_client(this.Handle);

            List<uint> Servers = ida.FindServers();

            if (Servers.Count == 0)
            {
                debugLog("IDA not found...");
            }
            else if (Servers.Count == 1)
            {
                ida.IDA_HWND = (int)Servers[0];
                debugLog("IDA hwnd: " + ida.IDA_HWND);
                debugLog("IDA File: " + Path.GetFileName(ida.LoadedFileName()));
            }
            else
            {
               debugLog(Servers.Count + " IDA windows open, will scan..");
            }

            string[] tmp = Environment.GetCommandLineArgs();
            string last = "c:\\lastGraph.txt";
            string f = "";

            this.Visible = true;

            if (false && System.Diagnostics.Debugger.IsAttached)
            {
                string testFile = Application.StartupPath + "\\test.txt";
                if (!File.Exists(testFile)) testFile = testFile.Replace("\\bin\\Debug", "");
                if (File.Exists(testFile)) graph.LoadFile(testFile);
            }
            else //load from command line or lastgraph if not..
            {
                for (int i = tmp.Length - 1; i > 0; i--)
                {
                    //MessageBox.Show(i + " " + tmp[i]);
                    if (File.Exists(tmp[i])) { f = tmp[i]; break; }
                }

                if (File.Exists(f))
                {
                    try
                    {
                        if (File.Exists(last)) File.Delete(last);
                        File.Copy(f, last);
                        debugLog("Loading " + f);
                        graph.LoadFile(f);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error loading: " + f + "\n\n" + ex.StackTrace);
                    }
                }
                else if (File.Exists(last))
                {
                    debugLog("Loading last graph");
                    graph.LoadFile(last);
                }
            }

            if (Servers.Count > 1)  //multiple IDA servers active, lets try to find the right one..
            {
                uint target = FindServerForGraph(Servers);
                if (target == 0)
                {
                    debugLog("No IDA match not found.");
                }
                else
                {
                    ida.IDA_HWND = (int)target;
                    debugLog("IDA hwnd: " + ida.IDA_HWND);
                    debugLog("IDA File: " + Path.GetFileName(ida.LoadedFileName()));
                }
            }

            lvNodes.Columns[0].Text = gViewer.Graph.NodeMap.Count + " Nodes";
        }