コード例 #1
0
ファイル: Program.cs プロジェクト: brownbelt/Sourcey-Jack
        static void Main(string[] args)
        {
            bool createdNew = false;

            System.Threading.Mutex m = new System.Threading.Mutex(false, "{BE450405-C3CF-45D3-A1F4-29F0C0A0E02D}", out createdNew);

            if (args.Length > 0)
            {
                try
                {
                    if (createdNew)
                    {
                        m.Dispose();
                        Process p = Process.Start(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);

                        p.WaitForInputIdle(10000);
                    }

                    Thread.Sleep(10000);

                    string dllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SJackHook.dll");

                    List <string> argList = new List <string>();

                    for (int i = 1; i < args.Length; ++i)
                    {
                        if (args[i].Contains(" "))
                        {
                            argList.Add(String.Format("\"{0}\"", args[i]));
                        }
                        else
                        {
                            argList.Add(args[i]);
                        }
                    }

                    string cmdLine = argList.Count > 0 ? String.Join(" ", argList) : null;

                    Detours.CreateProcessWithDll(args[0], cmdLine, dllPath);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }
            else
            {
                if (createdNew)
                {
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new MainForm());
                }
                else
                {
                    MessageBox.Show("Already a copy running");
                }
            }
        }
コード例 #2
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            string exe = textBoxExe.Text.Trim();

            if (UpdateMap())
            {
                if (String.IsNullOrEmpty(exe))
                {
                    MessageBox.Show(this, "Must specify an executable file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    try
                    {
                        string dllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SJackHook.dll");
                        Detours.CreateProcessWithDll(exe, String.IsNullOrWhiteSpace(textBoxCmdLine.Text) ? null : textBoxCmdLine.Text, dllPath);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString());
                    }
                }
            }
        }