Exemple #1
0
 public DpmPro(ICommandExecutor executor, IEmbeddedFileManager emb, IStorage storage, IDevice device)
 {
     this.executor = executor ?? throw new ArgumentNullException(nameof(executor));
     this.emb      = emb ?? throw new ArgumentNullException(nameof(emb));
     this.storage  = storage ?? throw new ArgumentNullException(nameof(storage));
     this.device   = device ?? throw new ArgumentNullException(nameof(device));
 }
Exemple #2
0
 public DpmPro(CommandExecutor executor, IEmbeddedFileManager emb, ITemporaryFloder tmp, IDevice device)
 {
     this.executor = executor ?? throw new ArgumentNullException(nameof(executor));
     this.emb      = emb ?? throw new ArgumentNullException(nameof(emb));
     this.tmp      = tmp ?? throw new ArgumentNullException(nameof(tmp));
     this.device   = device ?? throw new ArgumentNullException(nameof(device));
 }
        public void EntryPoint(IDevice device, ILeafUI ui, TextAttrManager text, IEmbeddedFileManager emb, ITemporaryFloder tmp)
        {
            using (ui)
            {
                ui.Title = this.GetName();
                ui.Icon  = this.GetIconBytes();
                ui.Show();

                ui.Tip = text[EXTRACTING];
                tmp.Create();
                var filePath = Path.Combine(tmp.DirInfo.ToString(), "daemon");
                var tgtFile  = new FileInfo(filePath);
                var file     = emb.Get("daemon");

                ui.Tip = text[PUSHING];
                file.ExtractTo(tgtFile);

                ui.Tip = text[PUSHING];
                ICommandResult result = null;
                using (var executor = new CommandExecutor())
                {
                    executor.To(e => ui.WriteOutput(e.Text));
                    executor.Adb(device, $"push {tgtFile.FullName} /data/local/tmp/daemon");
                    executor.AdbShell(device, "chmod 777 /data/local/tmp/daemon");
                    result = executor.AdbShell(device, "./data/local/tmp/daemon &");
                }
                ui.Finish(result.ExitCode);
            }
        }
Exemple #4
0
        public void EntryPoint(ILeafUI _ui, IDevice device, IStorage storage, IEmbeddedFileManager emb, ICommandExecutor _executor)
        {
            //确保资源被正确释放
            using var ui       = _ui;
            using var executor = _executor;

            //显示UI后初始化一些细节
            ui.Show();
            InitUI(ui);

            //做出一系列警告与提示,只要一个不被同意,立刻再见
            if (!(DoAppCheck(ui, device, PackageName) && DoWarn(ui)))
            {
                ui.Shutdown(); //直接关闭UI
                return;        //退出函数
            }

            /* 正式开始流程 */

            //创建一个OutputBuilder
            OutputBuilder outputBuilder = new OutputBuilder();

            //接收并记录所有executor的输出
            outputBuilder.Register(executor);

            //将命令执行器输出定向到界面
            executor.OutputReceived += (s, e) => ui.WriteLineToDetails(e.Text);

            //构造一个dpmpro的控制器
            var dpmpro = new DpmPro(executor, emb, storage, device);

            //将dpmpro提取到临时目录
            SetProgress(ui, "Extract", 0);
            dpmpro.Extract();

            //推送dpmpro到设备
            SetProgress(ui, "Push", 20);
            dpmpro.PushToDevice();

            //移除账户
            SetProgress(ui, "RMAcc", 40);
            dpmpro.RemoveAccounts();

            //移除用户
            SetProgress(ui, "RMUser", 60);
            dpmpro.RemoveUsers();

            //使用可能的方式设置管理员,并记录结果
            SetProgress(ui, "SettingDpm", 80);

            var codeOfSetDeviceOwner = SetDeviceOwner(device, ui, ComponentName, executor, dpmpro).ExitCode;

            if (codeOfSetDeviceOwner == 0 &&      //如果设置成功并且
                (PackageName == "com.catchingnow.icebox" || //目标包名是冰箱
                 PackageName == "web1n.stopapp")) //小黑屋
            {
                //给予APPOPS权限
                executor.AdbShell(device, $"pm grant {PackageName} android.permission.GET_APP_OPS_STATS");
            }

            //使用输出解析器,对记录的输出进行解析
            DpmFailedMessageParser.Parse(codeOfSetDeviceOwner, outputBuilder.ToString(), out string tip, out string message);



            //在输出框写下简要信息与建议
            ui.WriteLineToDetails(message);
            ui.ShowMessage(message);

            //去除输出信息事件注册
            outputBuilder.Unregister(executor);

            //ui流程结束
            ui.Finish(tip);
        }
Exemple #5
0
        public void EntryPoint(ILeafUI _ui, IDevice device, ICommandExecutor _executor, IStorage storage, IEmbeddedFileManager emb)
        {
            using var ui             = _ui;
            using var executor       = _executor;
            executor.OutputReceived += (s, e) => ui.WriteLineToDetails(e.Text);

            ui.Show();
            ui.EAgree(this.RxGetClassText("warn"));
            ui.EAgree(this.RxGetClassText("warn"));
            ui.EAgree(this.RxGetClassText("warn"));

            var dpm = new DpmPro(executor, emb, storage, device);

            ui.WriteLineToDetails(this.RxGetClassText("extracting"));
            dpm.Extract();
            ui.WriteLineToDetails(this.RxGetClassText("pushing"));
            dpm.PushToDevice();
            ui.WriteLineToDetails(this.RxGetClassText("removing"));
            int exitCode = dpm.RemoveUsers();

            if (exitCode == 0 && ui.DoYN(this.RxGetClassText("reboot")))
            {
                device.Reboot2System();
            }
            ui.Finish(exitCode == 0 ? StatusMessages.Success : StatusMessages.Failed);
        }
Exemple #6
0
        public void EntryPoint(ILeafUI _ui, IDevice device, ICommandExecutor _executor, IStorage storage, IEmbeddedFileManager emb)
        {
            using var ui       = _ui;
            using var executor = _executor;
            var text = ClassTextReaderCache.Acquire <EClearAccounts>();

            ui.Show();
            ui.EAgree(text["warn"]);
            ui.EAgree(text["warn"]);
            ui.EAgree(text["warn"]);
            executor.OutputReceived += (s, e) => ui.WriteLineToDetails(e.Text);
            var dpm = new DpmPro(executor, emb, storage, device);

            ui.WriteLineToDetails(text["extracting"]);
            dpm.Extract();
            ui.WriteLineToDetails(text["pushing"]);
            dpm.PushToDevice();
            ui.WriteLineToDetails(text["removing"]);
            int exitCode = dpm.RemoveAccounts();

            if (exitCode == 0 && ui.DoYN(text["reboot"]))
            {
                device.Reboot2System();
            }
            ui.Finish(exitCode == 0 ? StatusMessages.Success : StatusMessages.Failed);
        }
Exemple #7
0
 public void EntryPoint(ILeafUI ui, IDevice device, IClassTextManager text, ITemporaryFloder tmp, IEmbeddedFileManager emb)
 {
     using (ui)
     {
         ui.Icon  = this.GetIconBytes();
         ui.Title = this.GetName();
         ui.Show();
         ui.EAgree(text["warn"]);
         ui.EAgree(text["warn"]);
         ui.EAgree(text["warn"]);
         using (var executor = new CommandExecutor())
         {
             executor.To(e => ui.WriteOutput(e.Text));
             var dpm = new DpmPro(executor, emb, tmp, device);
             ui.WriteLine(text["extracting"]);
             dpm.Extract();
             ui.WriteLine(text["pushing"]);
             dpm.PushToDevice();
             ui.WriteLine(text["removing"]);
             int exitCode = dpm.RemoveUsers();
             if (exitCode == 0 && ui.DoYN(text["reboot"]))
             {
                 device.Reboot2System();
             }
             ui.Finish(exitCode);
         }
     }
 }
        public void EntryPoint(IStorage storage, IEmbeddedFileManager emb, ICommandExecutor _executor)
        {
            //using (UI)
            //{
            //    UI.Show();    //显示ui
            //    InitUI();   //初始化ui


            //    ////执行前的一些检查与提示
            //    //SetProgress("Checking", 10);
            //    //if (!DoAppCheck()) return;//进行APP安装检查
            //    //if (!DoWarn()) return;//进行一系列提示与警告

            //    //做出一系列警告与提示,只要一个不被同意,立刻再见
            //    if (!(DoAppCheck() && DoWarn()))
            //    {
            //        UI.Shutdown();//直接关闭UI
            //        return;//退出函数
            //    }

            //    /* 正式开始流程 */

            //    //构造一个命令执行器
            //    using (CommandExecutor executor = new CommandExecutor())
            //    {
            //        //创建一个OutputBuilder
            //        OutputBuilder outputBuilder = new OutputBuilder();

            //        //接收并记录所有executor的输出
            //        outputBuilder.Register(executor);

            //        //将命令执行器输出定向到界面
            //        executor.To(e => UI.WriteOutput(e.Text));

            //        //构造一个dpmpro的控制器
            //        var dpmpro = new DpmPro(executor, emb, storage, Device);

            //        //将dpmpro提取到临时目录
            //        SetProgress("Extract", 0);
            //        dpmpro.Extract();

            //        //推送dpmpro到设备
            //        SetProgress("Push", 20);
            //        dpmpro.PushToDevice();

            //        //移除账户
            //        SetProgress("RMAcc", 40);
            //        dpmpro.RemoveAccounts();

            //        //移除用户
            //        SetProgress("RMUser", 60);
            //        dpmpro.RemoveUsers();

            //        //使用可能的方式设置管理员,并记录结果
            //        SetProgress("SettingDpm", 80);
            //        var codeOfSetDeviceOwner = SetDeviceOwner(executor, dpmpro).ExitCode;

            //        if (codeOfSetDeviceOwner == 0 && //如果设置成功并且
            //            (PackageName == "com.catchingnow.icebox" //目标包名是冰箱
            //            || PackageName == "web1n.stopapp")) //小黑屋
            //        {
            //            //给予APPOPS权限
            //            executor.AdbShell(Device, $"pm grant {PackageName} android.permission.GET_APP_OPS_STATS");
            //        }

            //        //使用输出解析器,对记录的输出进行解析
            //        DpmFailedMessageParser.Parse(codeOfSetDeviceOwner, outputBuilder.ToString(), out string tip, out string message);



            //        //在输出框写下简要信息与建议
            //        UI.WriteLine(message);
            //        UI.ShowMessage(message);

            //        //去除输出信息事件注册
            //        outputBuilder.Unregister(executor);

            //        //ui流程结束
            //        UI.Finish(tip);
            //    }
            //}
        }