public void ShouldDetectIfDirectoryIsWritable(string directory)
        {
            var filename = directory + "cryoprison";

            using (var gel = new GlobalLock())
            {
                var env = gel.Env;

                env.System.IO.Directory.Exists = (path) => {
                    return(path == directory);
                };

                env.System.IO.File.Exists = (path) => {
                    return(path == filename);
                };

                env.System.IO.File.Open = (path, mode, access, share) =>
                {
                    if (path == filename)
                    {
                        return(new System.IO.MemoryStream(new byte[100]));
                    }
                    throw new AccessViolationException();
                };

                var jbd = new Cryoprison.Android.JailbreakDetector(env, simulatorFriendly: false);

                Assert.True(jbd.IsJailbroken);
            }
        }
        public void ShouldNotClaimThatTheDeviceIsJailbrokenByDefault()
        {
            using (var gel = new GlobalLock())
            {
                var jbd = new Cryoprison.Android.JailbreakDetector(gel.Env, simulatorFriendly: false);

                Assert.False(jbd.IsJailbroken);
            }
        }
        public void ShouldDetectIfKernelHasBeenCompiledByThirdParty(string key)
        {
            using (var gel = new GlobalLock())
            {
                var jbd = new Cryoprison.Android.JailbreakDetector(gel.Env, simulatorFriendly: false);

                A.OS.Build.Tags = key;

                Assert.True(jbd.IsJailbroken);
            }
        }
        public void ShouldDetectIfDangerousAppsAreInstalled(string package)
        {
            using (var gel = new GlobalLock())
            {
                var jbd = new Cryoprison.Android.JailbreakDetector(gel.Env, simulatorFriendly: false);

                A.App.Application.Context.PackageManager.MockPackages = new System.Collections.Generic.Dictionary <string, A.Content.PM.PackageInfo>
                {
                    { package, new A.Content.PM.PackageInfo() }
                };

                Assert.True(jbd.IsJailbroken);
            }
        }
        public void ShouldDetectIfExecutableCanBeLocated(string executable)
        {
            var locations = Cryoprison.Android.JailbreakDetector.CommonExecutableRootDirectories;

            var index    = randomizer.Next(locations.Length);
            var location = locations[index];

            using (var gel = new GlobalLock())
            {
                gel.Env.System.IO.File.Exists = (path) => {
                    return(path == location + executable);
                };

                var jbd = new Cryoprison.Android.JailbreakDetector(gel.Env, simulatorFriendly: false);

                Assert.True(jbd.IsJailbroken);
            }
        }
        public void ShouldDetectIfSuHasBeenInstalled(string executable)
        {
            using (var gel = new GlobalLock())
            {
                var jbd = new Cryoprison.Android.JailbreakDetector(gel.Env, simulatorFriendly: false);

                Java.Lang.Runtime.MockRuntime.MockExec = (parms) => {
                    if (parms.Count() == 2 && parms[0] == "which" && parms[1] == executable)
                    {
                        var process = new Process();
                        process.MockExecArgs  = parms;
                        process.MockStdOutput = new[] {
                            "/asdf/" + executable
                        };
                        return(process);
                    }
                    return(null);
                };

                Assert.True(jbd.IsJailbroken);
            }
        }
        public void ShouldDetectIfPropertyHasSpecificValue(string stdout)
        {
            using (var gel = new GlobalLock())
            {
                var jbd = new Cryoprison.Android.JailbreakDetector(gel.Env, simulatorFriendly: false);

                Java.Lang.Runtime.MockRuntime.MockExec = (parms) => {
                    if (parms.Count() == 1 && parms[0] == "getprop")
                    {
                        var process = new Process();
                        process.MockExecArgs  = parms;
                        process.MockStdOutput = new[] {
                            stdout
                        };
                        return(process);
                    }
                    return(null);
                };

                Assert.True(jbd.IsJailbroken, $"Did not detect a jailbreak via: {stdout}");
            }
        }