Example #1
0
 public void EntryPoint(ILeafUI ui, IDevice device, ICommandExecutor executor)
 {
     using (ui)
     {
         using (executor)
         {
             executor.OutputReceived += (s, e) => ui.WriteLineToDetails(e.Text);
             var text = ClassTextReaderCache.Acquire <EGCM>();
             ui.Show();
             if (device is NetDevice)
             {
                 ui.ShowMessage(text["isNet"]);
                 ui.EFinish();
             }
             else if (device is UsbDevice usbDevice)
             {
                 var endPoint = usbDevice.OpenNetDebugging(5555);
                 if (endPoint != null)
                 {
                     executor.Adb($"connect {endPoint}");
                 }
                 ui.Finish();
             }
             else
             {
                 ui.Finish(text["notsupport"]);
             }
         }
     }
 }
Example #2
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.RemoveAccounts();
             if (exitCode == 0 && ui.DoYN(text["reboot"]))
             {
                 device.Reboot2System();
             }
             ui.Finish(exitCode);
         }
     }
 }
Example #3
0
        public void Main(ILeafUI ui)
        {
            /*
             * 一定要进行using,此处是为了确保LeafUI被正确释放
             * 否则当该函数内发生异常,LeafUI将无法被关闭
             */
            using (ui)
            {
                //将LeafUI的图标设置为本模块的图标
                ui.Icon = this.GetIconBytes();
                //绑定LeafUI关闭事件
                ui.CloseButtonClicked += (s, e) =>
                {
                    /*
                     * 当用户点击停止按钮时发生
                     * 请在此处销毁你调用的资源
                     * 如果你不想你的模块被中途停止,请返回false
                     */
                    e.CanBeClosed = false;
                };
                //显示UI
                ui.Show();
                //在输出框打印东西
                ui.WriteLine("hello!");

                /*
                 * 一定要调用Finish函数,否则会出现严重的问题
                 * 另外,你也可以传入一个int数字,LeafUI会根据数字设置Tip
                 * ui.Finish(ERR);
                 * 或直接传入一个Tip
                 * ui.Finish("结束!");
                 */
                ui.Finish();
            }
        }
Example #4
0
 public void EntryPoint(ILeafUI ui, IDevice device, IClassTextManager text)
 {
     using (ui)
     {
         ui.Title = this.GetName();
         ui.Show();
         bool?  dialogResult = null;
         string seleFile     = null;
         ui.RunOnUIThread(() =>
         {
             Microsoft.Win32.OpenFileDialog fileDialog = new Microsoft.Win32.OpenFileDialog();
             fileDialog.Reset();
             fileDialog.Title       = text["title"];
             fileDialog.Filter      = text["filter"];
             fileDialog.Multiselect = false;
             dialogResult           = fileDialog.ShowDialog();
             seleFile = fileDialog.FileName;
         });
         if (dialogResult != true)
         {
             ui.EShutdown();
         }
         FileInfo        fileInfo = new FileInfo(seleFile);
         CommandExecutor executor = new CommandExecutor();
         executor.OutputReceived += (s, e) => ui.WriteLine(e.Text);
         var result = executor.Adb(device, $"push \"{fileInfo.FullName}\" \"/sdcard/{fileInfo.Name}\"");
         ui.Finish(result.ExitCode);
     }
 }
Example #5
0
        public void EntryPoint(IDevice device, ILeafUI ui, IStorage storage,
                               IAppManager app, ICommandExecutor executor)
        {
            using (ui)
            {
                //初始化LeafUI并展示
                executor.OutputReceived += (s, e) =>
                {
                    ui.WriteLineToDetails(e.Text);
                };
                ui.Closing += (s, e) =>
                {
                    executor.Dispose();
                    return(true);
                };

                ui.Show();

                var screencap = new ScreenCap(device, executor, storage.CacheDirectory.FullName);
                var file      = screencap.Cap();

                ui.WriteLineToDetails(file.FullName);
                ShowOnUI(app, file.FullName);
                //显示出来了,进度窗也没啥用了,直接关闭
                //ui.Finish();
                ui.Shutdown();
            }
        }
Example #6
0
        public void EntryPoint(ILeafUI _ui, IDevice device, ICommandExecutor _executor)
        {
            using var ui       = _ui;
            using var executor = _executor;
            var text = ClassTextReaderCache.Acquire <EFilePusher>();

            ui.Show();
            bool?  dialogResult = null;
            string selectedFile = null;

            ui.RunOnUIThread(() =>
            {
                Microsoft.Win32.OpenFileDialog fileDialog = new Microsoft.Win32.OpenFileDialog();
                fileDialog.Reset();
                fileDialog.Title       = text["title"];
                fileDialog.Filter      = text["filter"];
                fileDialog.Multiselect = false;
                dialogResult           = fileDialog.ShowDialog();
                selectedFile           = fileDialog.FileName;
            });

            if (dialogResult != true)
            {
                ui.EShutdown();
            }
            FileInfo fileInfo = new FileInfo(selectedFile);

            executor.OutputReceived += (s, e) => ui.WriteLineToDetails(e.Text);
            var result = executor.Adb(device, $"push \"{fileInfo.FullName}\" \"/sdcard/{fileInfo.Name}\"");

            ui.Finish(result.ExitCode == 0 ? StatusMessages.Success : StatusMessages.Failed);
        }
 private void EntryPoint(ILeafUI ui, IDevice device, IClassTextDictionary texts)
 {
     using (ui)
     {
         ui.Title = this.GetName();
         ui.Show();
         var    dev  = (UsbDevice)device;
         ushort?port = null;
         do
         {
             var input = ui.InputString(texts["Hint"], "5555");
             if (input == null)
             {
                 return;
             }
             if (ushort.TryParse(input, out ushort _port))
             {
                 port = _port;
             }
             else
             {
                 ui.EWarn(texts["InputError"]);
             }
         } while (port == null);
         dev.OpenNetDebugging((ushort)port, true);
     }
 }
Example #8
0
        public void Run(ILeafUI ui, ICommandExecutor executor, IDevice device)
        {
            using (ui)
            {
                ui.Show();
                ui.Closing += (s, e) =>
                {
                    executor.Dispose();
                    return(true);
                };
                executor.OutputReceived += (s, e) => ui.WriteLineToDetails(e.Text);

                //Checking if device support A/B slot.
                CommandResult result = executor.Fastboot(device, "getvar current-slot 2");

                bool?crtSlot = GetCurrentSlot(result.Output.ToString());

                if (crtSlot != null || AskIfContinueWithMayNotSupport(ui))
                {
                    //Ask if continue
                    var targetSlot = (bool)crtSlot ? "b" : "a";
                    if (AskIfContinueToSwitch(ui))
                    {
                        executor.Fastboot(device, "--set-active=" + targetSlot);
                    }
                }
                else
                {
                    ui.Shutdown();
                }
            }
        }
        private void Main(ILeafUI ui, IDevice device)
        {
            //# Script to start "web1n's demon" on the device, which has a very rudimentary
            //# shell.
            //#
            //base=/system

            //path=`pm path web1n.stopapp`
            //path=${path:8}

            //export CLASSPATH=$path
            //exec app_process $base/bin com.web1n.stopapp.app_process.DemonStart "$@"
            using (ui)
            {
                ui.Show();
                using var shell = new AndroidShell(device);
                shell.To(e => ui.WriteLineToDetails(e.Text));
                shell.Open();
                shell.WriteLine("base=/system");
                shell.WriteLine("path=`pm path web1n.stopapp`");
                shell.WriteLine("path=${path:8}");
                shell.WriteLine("export CLASSPATH=$path");
                shell.WriteLine("exec app_process $base/bin com.web1n.stopapp.app_process.DemonStart \"$@\"");
                shell.WriteLine("exit $?");
                shell.WaitForExit();
                ui.WriteLineToDetails("exit code:" + shell.ExitCode);
                ui.Finish(shell.ExitCode == 0 ? StatusMessages.Success : StatusMessages.Failed);
            }
        }
Example #10
0
        public void EntryPoint(ILeafUI _ui, IDevice device, ICommandExecutor _executor)
        {
            //确保能够在正确的时机释放
            using var ui       = _ui;
            using var executor = _executor;

            //展现UI
            ui.Show();

            //注册输出事件
            executor.OutputReceived += (s, e) => ui.WriteLineToDetails(e.Text);

            //判断脚本是否释放
            if (executor.AdbShell(device, $"cat {SH_PATH}").ExitCode != 0)
            {
                //提醒用户打开黑域以释放脚本
                ui.ShowMessage(this.RxGetClassText("first_msg"));
                //再等一会儿
                Thread.Sleep(2000);
            }

            //执行脚本
            if (executor.AdbShell(device, $"sh {SH_PATH}").ExitCode != 0)
            {
                ui.Finish(StatusMessages.Failed);
            }
            else
            {
                ui.Finish(StatusMessages.Success);
            }
        }
 private void EntryPoint(ILeafUI ui, TextAttrManager texts)
 {
     using (ui)
     {
         ui.Title = this.GetName();
         ui.Show();
         if (TryGetInputEndPoint(ui, texts, out IPEndPoint endpoint))
         {
             using (var executor = new CommandExecutor())
             {
                 ui.Tip = texts["ConnectingDevice"];
                 ui.WriteLine(texts["ConnectingDevice"]);
                 executor.To(e => ui.WriteOutput(e.Text));
                 var result = executor.Adb($"connect {endpoint.Address}:{endpoint.Port}");
                 if (result.Output.Contains("fail", true))
                 {
                     ui.WriteLine(texts["fail"]);
                     ui.Finish(texts["Fail"]);
                 }
                 else
                 {
                     ui.Finish(result.ExitCode);
                 }
             }
         }
         else
         {
             ui.Shutdown();
         }
     }
 }
        private bool TryGetInputEndPoint(ILeafUI ui, TextAttrManager texts, out IPEndPoint endPoint)
        {
            Task <object> dialogTask = null;

            do
            {
                if (dialogTask?.Result is bool)
                {
                    ui.ShowMessage(texts["PleaseInputRightIP"]);
                }
                dialogTask = ui.ShowDialogById("inputIpEndPoint");
                dialogTask.Wait();
            } while (dialogTask.Result is bool);
            if (dialogTask.Result is IPEndPoint endPointResult)
            {
                endPoint = endPointResult;
                return(true);
            }
            else if (dialogTask.Result is string str && str == "iloveyou")
            {
                //我喜欢你,曹娜(*^▽^*)
                System.Diagnostics.Process.Start("https://lovecaona.cn");
            }
            endPoint = null;
            return(false);
        }
        private void Main(ILeafUI ui, IDevice device)
        {
            //            # Script to start "web1n's demon" on the device, which has a very rudimentary
            //# shell.
            //#
            //base=/system

            //path=`pm path web1n.stopapp`
            //path=${path:8}

            //export CLASSPATH=$path
            //exec app_process $base/bin com.web1n.stopapp.app_process.DemonStart "$@"
            using (ui)
            {
                var info = this.GetInformations();
                ui.Icon  = info.Icon;
                ui.Title = info.Name;
                ui.Show();
                using (var shell = new AndroidShell(device))
                {
                    shell.To(e => ui.WriteOutput(e.Text));
                    shell.Open();
                    shell.WriteLine("base=/system");
                    shell.WriteLine("path=`pm path web1n.stopapp`");
                    shell.WriteLine("path=${path:8}");
                    shell.WriteLine("export CLASSPATH=$path");
                    shell.WriteLine("exec app_process $base/bin com.web1n.stopapp.app_process.DemonStart \"$@\"");
                    shell.WriteLine("exit $?");
                    shell.WaitForExit();
                    ui.WriteOutput("exit code:" + shell.ExitCode);
                    ui.Finish(shell.ExitCode == 0 ? AutumnBoxExtension.OK : AutumnBoxExtension.ERR);
                }
            }
        }
Example #14
0
 /// <summary>
 /// 进行是否抉择
 /// </summary>
 /// <param name="ui"></param>
 /// <param name="msg"></param>
 /// <param name="btnYes"></param>
 /// <param name="btnNo"></param>
 /// <returns></returns>
 public static void EAgree(this ILeafUI ui, string msg, string btnYes = null, string btnNo = null)
 {
     if (!ui.DoYN(msg, btnYes, btnNo))
     {
         ui.EShutdown();
     }
 }
        private SunsetLake GetSepLake(Dictionary <string, object> args)
        {
            SunsetLake s_lake = new SunsetLake();

            s_lake.RegisterSingleton <ILogger>(LoggerFactory.Auto(this.GetType().Name));
            s_lake.RegisterSingleton <ClassTextReader>(() =>
            {
                return(ClassTextReaderCache.Acquire(this.GetType()));
            });
            s_lake.RegisterSingleton <IExtensionInfo>(() =>
            {
                return(this.GetExtensionInfo());
            });
            s_lake.RegisterSingleton <ILeafUI>(() =>
            {
                ILeafUI leafUI     = this.lake !.Get <ILeafUI>();
                IExtensionInfo inf = this.GetExtensionInfo();
                leafUI.Title       = inf.Name();
                leafUI.Icon        = inf.Icon();
                return(leafUI);
            });
            s_lake.RegisterSingleton <IStorage>(() =>
            {
                return(this.lake !.Get <IStorageManager>().Open(this.GetType().FullName));
            });
            s_lake.RegisterSingleton <Dictionary <string, object> >(() =>
            {
                return(args ?? new Dictionary <string, object>());
            });
            return(s_lake);
        }
Example #16
0
 private void EntryPoint(ILeafUI ui, IDevice device, TextAttrManager texts)
 {
     using (ui)
     {
         ui.Title = this.GetName();
         ui.Show();
         if (device is UsbDevice usbDevice)
         {
             Task <object> dialogTask = null;
             ui.ShowDialogById("portInputView");
             dialogTask.Wait();
             if (ushort.TryParse(dialogTask.Result?.ToString(), out ushort result))
             {
                 try
                 {
                     usbDevice.OpenNetDebugging(result, true);
                 }
                 catch (AdbCommandFailedException e)
                 {
                     ui.WriteOutput(e.Message);
                     ui.ShowMessage(texts["Failed"]);
                 }
             }
         }
         else
         {
             ui.ShowMessage("ERROR!");
         }
         ui.Shutdown();
     }
 }
        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);
            }
        }
Example #18
0
        public void EntryPoint(ILeafUI _ui, IDevice device, ICommandExecutor _executor)
        {
            using var ui       = _ui;
            using var executor = _executor;
            var text = ClassTextReaderCache.Acquire(this.GetType());

            ui.Show();
            ui.EAgree(text["notice"]);
            Version androidVersion = new DeviceBuildPropGetter(device).GetAndroidVersion();

            executor.OutputReceived += (s, e) => ui.WriteLineToDetails(e.Text);
            ui.WriteLineToDetails("Accessibility service run-on-demand || Aggressive Doze on Android 7.0+ (non-root)");
            var result = executor.AdbShell(device, GRANT_PRE, WRITE_SECURE_SETTINGS);

            Count(result);

            ui.WriteLineToDetails("Doze on the Go || Aggressive Doze");
            result = executor.AdbShell(device, GRANT_PRE, DUMP);
            Count(result);

            ui.WriteLineToDetails("Wake-up Tracker");
            result = executor.AdbShell(device, GRANT_PRE, READ_LOGS);
            Count(result);

            ui.WriteLineToDetails("Background-free enforcement on Android 8+ (non-root)");
            if (androidVersion != null && androidVersion >= new Version("8.0"))
            {
                result = executor.AdbShell(device, GRANT_PRE, GET_APP_OPS_STATS);
                Count(result);
            }
            result = executor.AdbShell(device, "am force-stop", PKG_NAME);
            Count(result);
            ui.WriteLineToDetails($"successed: {successed} failed:{error}");
            ui.Finish(text["tip"]);
        }
Example #19
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);
        }
Example #20
0
        /// <summary>
        /// 设置进度信息,与核心代码无关
        /// </summary>
        /// <param name="keyOfTip"></param>
        /// <param name="progress"></param>
        static void SetProgress(ILeafUI ui, string keyOfTip, int progress)
        {
            string tip = text[keyOfTip] ?? keyOfTip;

            ui.StatusInfo = tip;
            ui.Progress   = progress;
            ui.WriteLineToDetails(tip);
        }
Example #21
0
 public void EntryPoint(ILeafUI _ui, IDevice device)
 {
     using var ui = _ui;
     throw new Exception("F**k");
     ui.Show();
     ui.ShowMessage(device.GetVar("product"));
     ui.ShowMessage(device.GetVar("unlocked"));
 }
Example #22
0
        /// <summary>
        /// 请在UI线程操作,获取LeafUI DialogHost(MaterialDesignInXaml)
        /// </summary>
        /// <param name="ui"></param>
        /// <returns></returns>
        public static object GetDialogHost(this ILeafUI ui)
        {
#if !SDK
            return(ui._GetDialogHost());
#else
            throw new Exception();
#endif
        }
        public void EntryPoint(ILeafUI ui, IDevice device, ICommandExecutor executor)
        {
            using (ui)
            {
                ui.Show();
                if (device is UsbDevice usbDevice)
                {
                    string input = null;
                    ushort port  = 0;
                    do
                    {
                        input = ui.InputString(this.RxGetClassText("input_hint"), "5555");
                        if (input == null)
                        {
                            ui.EShutdown();
                        }
                    } while (!ushort.TryParse(input, out port));
                    ui.StatusInfo = this.RxGetClassText("stauts_enabling");
                    IPEndPoint endPoint = null;
                    try
                    {
                        endPoint = usbDevice.OpenNetDebugging(port);
                    }
                    catch (AdbCommandFailedException e)
                    {
                        ui.WriteLineToDetails($"exit code : {e.ExitCode}");
                        ui.EShutdown();
                    }

                    ui.WriteLineToDetails($"Device's IPEndPoint: {endPoint?.ToString() ?? "Can not read"}");
                    if (endPoint != null)
                    {
                        if (ui.DoYN(this.RxGetClassText("yn_try_to_connect")))
                        {
                            ui.StatusInfo = this.RxGetClassText("status_connecting");
                            Thread.Sleep(1500);
                            string msg = executor.Adb($"connect {endPoint}").ExitCode == 0 ? StatusMessages.Success : StatusMessages.Failed;
                            ui.Finish(msg);
                        }
                        else
                        {
                            ui.Finish(StatusMessages.Success);
                        }
                    }
                    else
                    {
                        ui.ShowMessage(this.RxGetClassText("can_not_read_ip"));
                        ui.Finish(StatusMessages.Success);
                    }
                }
                else
                {
                    ui.ShowMessage(this.RxGetClassText("is_not_usb_device"));
                    ui.Shutdown();
                }
            }
        }
Example #24
0
        public void EntryPoint(ILeafUI _ui, IDevice device, ICommandExecutor _executor)
        {
            using var ui = _ui;
            ui.Show();
            using var executor       = _executor;
            executor.OutputReceived += (s, e) => ui.Println(e.Text);
            var result = executor.AdbShell(device, "sh /storage/emulated/0/Android/data/com.web1n.permissiondog/files/starter.sh");

            ui.Finish(result.ExitCode == 0 ? StatusMessages.Success : StatusMessages.Failed);
        }
 public void Main(ILeafUI ui, ICommandExecutor executor, IDevice device)
 {
     using (ui) {
         ui.Title = "流体手势激活器";
         ui.Show();
         executor.OutputReceived += (s, e) => ui.WriteOutput(e.Text);
         executor.AdbShell(device, "");
         ui.Finish();
     }
 }
Example #26
0
 public void Main(IDevice device, IUx ux, ILeafUI ui)
 {
     using (ui)
     {
         ui.Show();
         foreach (var kv in device.GetAllVar())
         {
             ui.Println($"{kv.Key}:{kv.Value}");
         }
         ui.Finish();
     }
 }
Example #27
0
        /// <summary>
        /// 显示对话
        /// </summary>
        /// <param name="ui"></param>
        /// <param name="viewId"></param>
        /// <returns></returns>
        public static Task <object> ShowDialogById(this ILeafUI ui, string viewId)
        {
            Task <object> dialogTask = null;

            ui.RunOnUIThread(() =>
            {
#if !SDK
                dialogTask = ui.ShowDialog(GetViewById(viewId));
#endif
            });
            return(dialogTask);
        }
Example #28
0
        /// <summary>
        /// 在LeafUI显示对话
        /// </summary>
        /// <param name="ui">LeafUI</param>
        /// <param name="content">内容,推荐为一个View</param>
        /// <returns>对话任务</returns>
        public static Task <object> ShowDialog(this ILeafUI ui, object content)
        {
            Task <object> dialogTask = null;

            ui.RunOnUIThread(() =>
            {
#if !SDK
                dialogTask = ui._ShowDialog(content);
#endif
            });
            return(dialogTask);
        }
Example #29
0
 public void EntryPoint(ILeafUI ui, ILogger logger)
 {
     logger.Warn("Run");
     using (ui)
     {
         ui.Title = this.GetName();
         ui.Icon  = this.GetIcon();
         ui.Show();
         ui.WriteLine("Hello world!");
         ui.Finish();
     }
 }
Example #30
0
        /// <summary>
        /// 用所有可能的方法设置设备管理员,并返回结果
        /// </summary>
        /// <param name="device"></param>
        /// <param name="executor"></param>
        /// <param name="dpmpro"></param>
        /// <returns></returns>
        static CommandResult SetDeviceOwner(IDevice targetDevice, ILeafUI ui, string componentName, ICommandExecutor executor, DpmPro dpmpro)
        {
            //先用自带dpm进行设置
            CommandResult result = executor.AdbShell(targetDevice, "dpm set-device-owner", componentName);

            //如果返回值为127,也就是说这设备连dpm都阉割了,就询问用户是否用dpmpro来设置设备管理员
            if (result.ExitCode == 127 && ui.DoYN(text["UseDpmPro"]))
            {
                //用dpmpro设置设备管理员,并记录结果(覆盖普通dpm设置器的记录)
                result = dpmpro.SetDeviceOwner(componentName);
            }
            return(result);
        }