示例#1
0
        private void RunCommandNew(string sCommand)
        {
            try
            {
                if (!consoleControl1.IsProcessRunning)
                {
                    consoleControl1.ClearOutput();
                    consoleControl1.Focus();
                    consoleControl1.StartProcess(ADBRunner.FindADB(), sCommand);
                }

                if (consoleControl1.IsProcessRunning)
                {
                    if (!consoleControl1.Focused)
                    {
                        consoleControl1.Focus();
                    }
                    tbCommand.Enabled = false;
                }
                else
                {
                    tbCommand.Enabled = true;
                    tbCommand.Focus();
                }
            }
            catch (Exception)
            {
            }
        }
示例#2
0
        public ConsoleForm()
        {
            InitializeComponent();

            tbConsole.BackColor        = System.Drawing.SystemColors.Window;
            toolStripStatusLabel1.Text = ADBRunner.FindADB();
        }
示例#3
0
        public PreferencesForm()
        {
            InitializeComponent();

            DeviseAddr addr = new DeviseAddr();

            if (addr.IsValid())
            {
                tbIP.Text   = addr.IP;
                tbPort.Text = addr.PORT;
            }

            if (!string.IsNullOrEmpty(addr.ADBPath))
            {
                tbADB.Text = addr.ADBPath;
            }
            else
            {
                tbADB.Text = ADBRunner.FindADB();
            }

            if (!string.IsNullOrEmpty(addr.ConnectionType))
            {
                rbUSB.Checked = addr.ConnectionType.Equals("usb");
            }

            cbDevices.Items.Clear();
            ADBCommand    commandDev = new ADBCommand();
            CommandResult retDev     = commandDev.Devices();

            if (retDev.IsSuccess)
            {
                foreach (var str in retDev.Message.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (!string.IsNullOrEmpty(str))
                    {
                        string[] s = str.Split(' ');
                        if (s.Any())
                        {
                            cbDevices.Items.Add(s[0]);
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(addr.UsbDevice))
            {
                if (cbDevices.Items.Contains(addr.UsbDevice))
                {
                    cbDevices.SelectedItem = addr.UsbDevice;
                }
            }
        }
示例#4
0
        private void RunCommand(string sCommand)
        {
            strMessage = string.Empty;
            Process build  = new Process();
            string  strADB = ADBRunner.FindADB();

            build.StartInfo.WorkingDirectory = Path.GetDirectoryName(strADB);
            build.StartInfo.FileName         = strADB;
            build.StartInfo.Arguments        = sCommand;

            build.StartInfo.UseShellExecute        = false;
            build.StartInfo.RedirectStandardOutput = true;
            //build.StandardInput.AutoFlush = true;
            build.StartInfo.RedirectStandardInput = true;
            build.StartInfo.RedirectStandardError = true;
            build.StartInfo.CreateNoWindow        = true;
            build.ErrorDataReceived  += build_ErrorDataReceived;
            build.OutputDataReceived += build_ErrorDataReceived;
            build.EnableRaisingEvents = true;
            build.Start();

            StreamWriter inputWriter = build.StandardInput;

            //StreamReader outputReader = build.StandardOutput;

            build.BeginOutputReadLine();
            build.BeginErrorReadLine();

            foreach (ProcessThread thread in build.Threads)
            {
                if (thread.ThreadState == ThreadState.Wait &&
                    thread.WaitReason == ThreadWaitReason.UserRequest)
                {
                    inputWriter.WriteLine("exit");
                    //build.StandardInput.Close();

                    /*
                     * string ss = outputReader.ReadToEnd();
                     * ss = Encoding.UTF8.GetString(Encoding.Default.GetBytes(ss));
                     * AppendText(ss, tbConsole.ForeColor, true);
                     */
                }
            }

            build.WaitForExit();
        }
示例#5
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            lvResult.Items.Clear();

            bool   bRemount        = false;
            string sCommandRemount = null;

            ADBRunner runner = new ADBRunner();

            foreach (IFolderObject item in Items)
            {
                string spath = string.Format("/{0}", item.PathString);
                spath = spath.Replace(" ", "\\ ")
                        .Replace("(", "\\(")
                        .Replace(")", "\\)")
                        .Replace("'", "\\'")
                        .Replace("&", "\\&");

                string sAttr  = null;
                string sOwner = null;
                string sGroup = null;
                GetAttributeOwnerGroup(Items[0], ref sAttr, ref sOwner, ref sGroup);

                if (cbApplyOwnerGroup.Checked)
                {
                    if (!string.IsNullOrEmpty(cbOwner.Text) || !string.IsNullOrEmpty(cbGroup.Text))
                    {
                        if (!cbOwner.Text.Equals(sOwner) || !cbGroup.Text.Equals(sGroup))
                        {
                            string sCommandOwnerGroup = tbOwnerGroup.Text;
                            sCommandOwnerGroup = sCommandOwnerGroup.Replace("[DIR]", spath);
                            sCommandOwnerGroup = sCommandOwnerGroup.Replace("[OWNER]", !string.IsNullOrEmpty(cbOwner.Text) ? cbOwner.Text : sOwner);
                            sCommandOwnerGroup = sCommandOwnerGroup.Replace("[GROUP]", !string.IsNullOrEmpty(cbGroup.Text) ? cbGroup.Text : sGroup);
                            bool bret = runner.LaunchProcess(ADBCommand.SelectDevice(sCommandOwnerGroup), CommandDialog.None, false);
                            AddResult(string.Format("/{0}", item.PathString), sCommandOwnerGroup, runner.strMessage);
                            if ((cbRemount.Checked) && (runner.strMessage.Contains("Read-only file system")))
                            {
                                sCommandRemount = tbRemount.Text;
                                string sParrent = spath.Substring(0, spath.LastIndexOf('/') + 1);
                                sCommandRemount = sCommandRemount.Replace("[DIR]", sParrent);
                                bret            = runner.LaunchProcess(ADBCommand.SelectDevice(sCommandRemount), CommandDialog.None, false);
                                AddResult("Remount to RW", "", "");
                                AddResult(string.Format("/{0}", item.PathString), sCommandRemount, runner.strMessage);
                                if (string.IsNullOrEmpty(runner.strMessage))
                                {
                                    bRemount = true;
                                }
                                bret = runner.LaunchProcess(ADBCommand.SelectDevice(sCommandOwnerGroup), CommandDialog.None, false);
                                AddResult(string.Format("/{0}", item.PathString), sCommandOwnerGroup, runner.strMessage);
                            }
                        }
                        else
                        {
                            AddResult(string.Format("/{0}", item.PathString), "Owner & Group not changed", "Skeep");
                        }
                    }
                }

                if (cbApplyPerm.Checked)
                {
                    string sCommandPerm = tbPermissions.Text;
                    sCommandPerm = sCommandPerm.Replace("[DIR]", spath);
                    sCommandPerm = sCommandPerm.Replace("[OCTAL]", int.Parse(GetOctal()).ToString());
                    bool bret = runner.LaunchProcess(ADBCommand.SelectDevice(sCommandPerm), CommandDialog.None, false);
                    AddResult(string.Format("/{0}", item.PathString), sCommandPerm, runner.strMessage);
                    if ((cbRemount.Checked) && (runner.strMessage.Contains("Read-only file system")))
                    {
                        sCommandRemount = tbRemount.Text;
                        string sParrent = spath.Substring(0, spath.LastIndexOf('/') + 1);
                        sCommandRemount = sCommandRemount.Replace("[DIR]", sParrent);
                        bret            = runner.LaunchProcess(ADBCommand.SelectDevice(sCommandRemount), CommandDialog.None, false);
                        AddResult("Remount to RW", "", "");
                        AddResult(string.Format("/{0}", item.PathString), sCommandRemount, runner.strMessage);
                        if (string.IsNullOrEmpty(runner.strMessage))
                        {
                            bRemount = true;
                        }
                        bret = runner.LaunchProcess(ADBCommand.SelectDevice(sCommandPerm), CommandDialog.None, false);
                        AddResult(string.Format("/{0}", item.PathString), sCommandPerm, runner.strMessage);
                    }
                }
            }

            if (bRemount && !string.IsNullOrEmpty(sCommandRemount))
            {
                sCommandRemount = sCommandRemount.Replace(",rw ", ",ro ");
                bool bret = runner.LaunchProcess(ADBCommand.SelectDevice(sCommandRemount), CommandDialog.None, false);
                AddResult("Remount back to RO", sCommandRemount, runner.strMessage);
            }

            if (Items.Any())
            {
                if (_folderObj != null && _folderObj.ShellView != null)
                {
                    _folderObj.ShellView.Refresh();

                    foreach (IFolderObject item in Items)
                    {
                        List <byte[]> ls = new List <byte[]>();
                        ls.Add(item.PathData[item.PathData.Length - 1]);
                        int rt = _folderObj.ShellView.SelectItem(
                            ItemIdList.Create(null, (byte[][])ls.ToArray().Clone()).Ptr,
                            _SVSIF.SVSI_SELECT | _SVSIF.SVSI_SELECTIONMARK);
                    }
                }

                /*
                 * IntPtr pDelObj = ItemIdList.Create(null, Items[0].PathData).Ptr;
                 * Shell32.SHChangeNotify(ShellChangeEvents.Delete,
                 *  ShellChangeFlags.IdList | ShellChangeFlags.Flush,
                 *  pDelObj,
                 *  IntPtr.Zero);
                 * Marshal.FreeCoTaskMem(pDelObj);
                 */
                /*
                 * List<byte[]> bt = ((byte[][])(Items[0].PathData.Clone())).ToList();
                 * //bt.RemoveAt(bt.Count - 1);
                 * //bt.RemoveAt(bt.Count - 1);
                 * IntPtr pParrent = ItemIdList.Create(null, bt.ToArray()).Ptr;
                 * Shell32.SHChangeNotify(ShellChangeEvents.UpdateDir,
                 *           ShellChangeFlags.IdList | ShellChangeFlags.Flush,
                 *           pParrent,
                 *           IntPtr.Zero);
                 * Marshal.FreeCoTaskMem(pParrent);
                 */
            }

            MessageBox.Show("Operation Complete!\r\nClick 'Details' button to view result log", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

            //DialogResult = DialogResult.OK;

            //Close();
            //-s 127.0.0.1:62001 shell "su -c 'chmod 777 /data/local/tmp'"
            //-s 127.0.0.1:62001 shell "su -c 'chown root.root /data/local/tmp'"
            //-s 127.0.0.1:62001 shell "su -c 'mount -o remount,rw /'"
        }