コード例 #1
0
        public override async Task <bool> FileExists(string filename)
        {
            var exists = false;

            using (var process = CreateSUProcess())
                using (var input = new DataInputStream(process.InputStream))
                    using (var output = new DataOutputStream(process.OutputStream))
                    {
                        await output.WriteBytesAsync($"[ -f \"{filename}\" ] && echo 1 || echo 0\n");

                        await output.FlushAsync();

                        await output.WriteBytesAsync("exit\n");

                        await output.FlushAsync();

                        var res = await input.ReadLineAsync();

                        exists = res == "1";

                        await process.WaitForAsync();
                    }

            return(exists);
        }
コード例 #2
0
        public override async Task <bool> CheckDeviceRooted()
        {
            try
            {
                using (var process = CreateSUProcess())
                    using (var input = new DataInputStream(process.InputStream))
                        using (var output = new DataOutputStream(process.OutputStream))
                        {
                            await output.WriteBytesAsync("id\n");

                            await output.FlushAsync();

                            var id = await input.ReadLineAsync();

                            var res = id != null && id.Contains("uid=0");

                            await output.WriteBytesAsync("exit\n");

                            await output.FlushAsync();

                            await process.WaitForAsync();

                            return(res);
                        }
            }
            catch
            {
                return(false);
            }
        }
コード例 #3
0
        public override async Task ExecuteRootCommand(string cmd)
        {
            using (var process = CreateSUProcess())
                using (var output = new DataOutputStream(process.OutputStream))
                {
                    await output.WriteBytesAsync(cmd + "\n");

                    await output.FlushAsync();

                    await output.WriteBytesAsync("exit\n");

                    await output.FlushAsync();

                    await process.WaitForAsync();
                }
        }
コード例 #4
0
        public override async Task <Stream> OpenFile(string filename)
        {
            Stream outStream = null;

            using (var process = CreateSUProcess())
                using (var input = new DataInputStream(process.InputStream))
                    using (var output = new DataOutputStream(process.OutputStream))
                    {
                        await output.WriteBytesAsync($"[ -f \"{filename}\" ] && echo 1 || echo 0\n");

                        await output.FlushAsync();

                        var exists = await input.ReadLineAsync();

                        if (exists == "1")
                        {
                            var tempDirectory = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, "Android", "data", AppInfo.PackageName, "cache");
                            var outputFile    = Path.Combine(tempDirectory, Path.GetFileName(filename));

                            if (!Directory.Exists(tempDirectory))
                            {
                                Directory.CreateDirectory(tempDirectory);
                            }

                            await output.WriteBytesAsync($"cp {filename} {outputFile}\n");

                            await output.FlushAsync();

                            outStream = new FileInfo(outputFile).Open(FileMode.Open);
                        }

                        await output.WriteBytesAsync("exit\n");

                        await output.FlushAsync();

                        await process.WaitForAsync();
                    }

            return(outStream);
        }