Beispiel #1
0
 /// <summary>
 /// Check that su exists with "which su" command.
 /// </summary>
 /// <returns><c>true</c>, if su exists, <c>false</c> otherwise.</returns>
 private bool CheckSuExists()
 {
     Java.Lang.Process process = null;
     try
     {
         process = Runtime.GetRuntime().Exec(new string[] { "/system/xbin/which", "su" });
         Java.IO.BufferedReader input = new Java.IO.BufferedReader(
             new Java.IO.InputStreamReader(process.InputStream));
         if (input.ReadLine() != null)
         {
             return(true);
         }
         return(false);
     }
     catch (Throwable)
     {
         return(false);
     }
     finally
     {
         if (process != null)
         {
             process.Destroy();
         }
     }
 }
Beispiel #2
0
        private static string ExecuteTop()
        {
            Java.Lang.Process p = null;
            BufferedReader    reader;
            string            returnString = null;

            try
            {
                p      = Runtime.GetRuntime().Exec("top -n 1");
                reader = new BufferedReader(new InputStreamReader(p.InputStream));
                while (returnString == null || returnString.Equals(""))
                {
                    returnString = reader.ReadLine();
                }
            }
            catch (System.IO.IOException e)
            {
            }
            finally
            {
                try
                {
                    //reader.Close();
                    p.Destroy();
                }
                catch (System.IO.IOException e)
                {
                    //Log.e("executeTop",
                    //        "error in closing and destroying top process");
                    //e.printStackTrace();
                }
            }
            return(returnString);
        }
Beispiel #3
0
 private bool CheckPresenceOfSuspiciousAPKs()
 {
     Java.Lang.Process process = null;
     try
     {
         process = Runtime.GetRuntime().Exec(new string[] { "/system/xbin/which", "su" });
         BufferedReader br = new BufferedReader(new InputStreamReader(process.OutputStream));
         if (br.ReadLine() != null)
         {
             return(true);
         }
         return(false);
     }
     catch (System.Exception)
     {
         return(false);
     }
     finally
     {
         if (process != null)
         {
             process.Dispose();
         }
     }
 }
Beispiel #4
0
        public string getDescription()
        {
            string description = "";

            try
            {
                Java.Lang.Process process = Runtime.GetRuntime().Exec("logcat -d HockeyApp:D *:S");

                BufferedReader bufferedReader =
                    new BufferedReader(new InputStreamReader(process.InputStream));

                Java.Lang.StringBuilder log = new Java.Lang.StringBuilder();
                string line;
                while ((line = bufferedReader.ReadLine()) != null)
                {
                    log.Append(line);
                    log.Append(System.Environment.NewLine);
                }
                bufferedReader.Close();

                description = log.ToString();
            }
            catch (IOException e)
            {
            }
            return(description);
        }
Beispiel #5
0
        void StartNode()
        {
            Trace.WriteLine("Node starting ...");

            // Light client
            nodeProcess = StartProcess($"{nodeBinPath} -d {nodeBasePath} --chain={nodeChainSpecPath} --light --no-prometheus --no-telemetry");
            // Full node - Should give the possibility to run either light or full node in the UI
            //nodeProcess = StartProcess($"{nodeBinPath} -d {nodeBasePath} --chain={nodeChainSpecPath} --no-prometheus --no-telemetry");

            _ = Task.Factory.StartNew(async() =>
            {
                using var input  = new InputStreamReader(nodeProcess.ErrorStream);
                using var reader = new BufferedReader(input);

                bool ready = false;
                string line;
                while (!string.IsNullOrEmpty((line = reader.ReadLine())))
                {
                    if (!ready && line.Contains("idle", StringComparison.InvariantCultureIgnoreCase))
                    {
                        Toast.ShowShortToast("Node is ready.");
                        EventAggregator.GetEvent <NodeStatusEvent>().Publish(NodeStatus.NodeReady);
                        ready = true;
                    }
                    logs.OnNext(line);
                }
                reader.Close();
                await nodeProcess.WaitForAsync();
            }, TaskCreationOptions.LongRunning);
        }
Beispiel #6
0
        protected override async void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);



            File appDirectory = GetExternalFilesDir(null);
            File logDirectory = new File(appDirectory + "/log");
            File logFile      = new File(logDirectory + "/BBW_Inspect.Mobile_Logging_" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt");

            if (!logDirectory.Exists())
            {
                logDirectory.Mkdir();
            }

            Java.Lang.Process process = Runtime.GetRuntime().Exec("logcat -c");
            process = Runtime.GetRuntime().Exec("logcat -f " + logFile + " -v time");

            AndroidEnvironment.UnhandledExceptionRaiser += AndroidEnvironment_UnhandledExceptionRaiser;

            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            Xamarin.Forms.Forms.Init(this, bundle);

            var app = new App();

            // Register the third-party plugins
            PluginConfig.Register(app, this, bundle);
            LoadApplication(new App());
        }
Beispiel #7
0
        private async Task <bool> PingGoogleServer()
        {
            try
            {
                mIpAddrProcess = runtime.Exec("/system/bin/ping -c 1 8.8.8.8");
                int mExitValue = await mIpAddrProcess.WaitForAsync();

                if (mExitValue == 0)
                {
                    Dismiss();
                    return(true);
                }
                else
                {
                    progress.Visibility = ViewStates.Invisible;
                    btnRetry.Enabled    = true;
                    btnRetry.SetText(retryText1);
                    noNetHeader.SetText(headerText1);
                    noNetSub.SetText(subTitle1);
                    return(false);
                }
            }
            catch (InterruptedException)
            {
            }
            catch (IOException)
            {
            }
            return(false);
        }
Beispiel #8
0
        private void _StartProcess()
        {
            string sampleformat = "*:16:*";
            string player       = "oboe";

            if (Build.VERSION.SdkInt < BuildVersionCodes.O)
            {
                player = "opensl";
            }

            AudioManager am   = (AudioManager)Application.Context.GetSystemService(Application.AudioService);
            string       rate = "";
            string       fpb  = "";

            if (Build.VERSION.SdkInt >= BuildVersionCodes.JellyBeanMr1)
            {
                rate         = am.GetProperty(AudioManager.PropertyOutputSampleRate);
                fpb          = am.GetProperty(AudioManager.PropertyOutputFramesPerBuffer);
                sampleformat = string.Format("{0}:16:*", rate);
            }

            ProcessBuilder pb = new ProcessBuilder()
                                .Command(
                Path.Combine(Android.App.Application.Context.ApplicationInfo.NativeLibraryDir, "libsnapclient.so"),
                "-h", m_Host,
                "-p", Integer.ToString(m_Port), "--player", player, "--sampleformat", sampleformat)
                                .RedirectErrorStream(true);

            Dictionary <string, string> env = new Dictionary <string, string>();

            env.Add("SAMPLE_RATE", rate);
            env.Add("FRAMES_PER_BUFFER", fpb);

            m_Process = pb.Start();

            m_Reader = new Thread(new Runnable(() =>
            {
                BufferedReader bufferedReader = new BufferedReader(
                    new InputStreamReader(m_Process.InputStream));
                try
                {
                    string line;
                    while ((line = bufferedReader.ReadLine()) != null)
                    {
                        _Log(line);
                    }
                }
                catch (IOException e)
                {
                    e.PrintStackTrace();
                }
            }));
            m_LogReceived = false;
            m_Reader.Start();
        }
Beispiel #9
0
        public bool estarConectado()
        {
            Runtime runtime = Runtime.GetRuntime();

            try {
                Java.Lang.Process ipProcess = runtime.Exec("/system/bin/ping -c 1 8.8.8.8");
                int exitValue = ipProcess.WaitFor();
                return(exitValue == 0);
            }
            catch (IOException e) {
                e.PrintStackTrace();
            }
            catch (InterruptedException e) {
                e.PrintStackTrace();
            }
            return(false);
        }
Beispiel #10
0
        static public void StartTor()
        {
            string folder = Android.App.Application.Context.GetDir("Tor", FileCreationMode.WorldWriteable).AbsolutePath;

            //Tor
            string[] argsTor = new string[3];
            argsTor[0] = folder + "/tor";
            argsTor[1] = "-f";
            argsTor[2] = folder + "/torrc";

            if (!System.IO.File.Exists(argsTor[0]) || !System.IO.File.Exists(argsTor[2]))
            {
                //file not found
            }

            ProcessBuilder pb = new ProcessBuilder(argsTor);

            try
            {
                TorProc = pb.Start();
            }
            catch (Exception ex)
            {
                string str = ex.Message;
            }

            System.Action check    = CheckLog;
            Runnable      runnable = new Runnable(check);

            new Thread(runnable).Start();

            //Polipo
            string[] argsPolipo = new string[3];
            argsPolipo[0] = folder + "/polipo";
            argsPolipo[1] = "-c";
            argsPolipo[2] = folder + "/polipo.conf";

            ProcessBuilder pb2 = new ProcessBuilder(argsPolipo);

            Java.Lang.Process PolipoProc = pb2.Start();
        }
Beispiel #11
0
        public static void test_run()
        {
            //var app_path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            var path = Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures).AbsolutePath, "KoromoCopy", "youtube_dl");

            using (var br = new BinaryReader(Application.Context.Assets.Open("youtube_dl")))
            {
                using (var bw = new BinaryWriter(new FileStream(path, FileMode.Create)))
                {
                    byte[] buffer = new byte[2048];
                    int    length = 0;
                    while ((length = br.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        bw.Write(buffer, 0, length);
                    }
                }
            }

            //if (File.Exists(Path.Combine(app_path, "youtube_dl")))
            //    ;

            Java.Lang.Process p = Runtime.GetRuntime().Exec("chmod u+x " + path);
            //Java.Lang.Process p = Runtime.GetRuntime().Exec(new string[] { "/system/bin/chmod", "744", Path.Combine(app_path, "youtube_dl") });

            BufferedReader reader = new BufferedReader(new InputStreamReader(p.InputStream));
            int            read;

            char[]       bbuffer = new char[4096];
            StringBuffer output  = new StringBuffer();

            while ((read = reader.Read(bbuffer)) > 0)
            {
                output.Append(bbuffer, 0, read);
            }
            reader.Close();


            p.WaitFor();

            var st = output.ToString();
        }
Beispiel #12
0
        public Task <bool> PingHost(string host = null, int timeout = 3)
        {
            bool pingable = false;

            if (host == null)
            {
                host = Static.Secrets.ServerIp;
            }

            Runtime runtime = Runtime.GetRuntime();

            Java.Lang.Process process = runtime.Exec($"ping -c 1 -W {timeout} {host}");
            int result = process.WaitFor();

            if (result == 0)
            {
                pingable = true;
            }

            return(Task.FromResult(pingable));
        }
        public SerialPort(File device, int baudrate, int flags)
        {
            //        检查访问权限,如果没有读写权限,进行文件操作,修改文件访问权限
            if (!device.CanRead() || !device.CanWrite())
            {
                try
                {
                    //通过挂在到linux的方式,修改文件的操作权限
                    Java.Lang.Process su = Runtime.GetRuntime().Exec("/system/xbin/su");
                    //一般的都是/system/bin/su路径,有的也是/system/xbin/su
                    var cmd = new Java.Lang.String("chmod 777 " + device.AbsolutePath + "\n" + "exit\n");
                    // Log.e("cmd :", cmd);
                    su.OutputStream.Write(cmd.GetBytes());
                    if ((su.WaitFor() != 0) || !device.CanRead() || !device.CanWrite())
                    {
                        throw new SecurityException();
                    }
                }
                catch (Exception e)
                {
                    //   e.printStackTrace();
                    throw new SecurityException();
                }
            }

            var ptr = Open(Android.Runtime.JNIEnv.Handle, this.Handle, JNIEnv.NewString(device.AbsolutePath), baudrate, flags);

            if (ptr != System.IntPtr.Zero)
            {
                mFd = GetObject <FileDescriptor>(ptr, JniHandleOwnership.DoNotRegister);
            }
            if (mFd == null)
            {
                //  Log.e(TAG, "native open returns null");
                throw new IOException();
            }

            mFileInputStream  = new FileInputStream(mFd);
            mFileOutputStream = new FileOutputStream(mFd);
        }
Beispiel #14
0
        private static bool CheckUsingProcessPermissions()
        {
            Process process = null;

            try
            {
                process = Runtime.GetRuntime().Exec(new[] { "/system/xbin/which", "su" });

                using (var input = new BufferedReader(new InputStreamReader(process.InputStream)))
                {
                    return(input.ReadLine() != null);
                }
            }
            catch
            {
                return(false);
            }
            finally
            {
                process?.Destroy();
            }
        }
Beispiel #15
0
 void StopNode()
 {
     if (nodeProcess != null)
     {
         try
         {
             if (nodeProcess.IsAlive)
             {
                 nodeProcess.Destroy();
             }
         }
         catch (Java.Lang.Exception e)
         {
             Log.Error(GetType().Name, e.ToString());
         }
         finally
         {
             try { nodeProcess.Dispose(); }
             catch { }
             nodeProcess = null;
         }
     }
 }
        public void RebootMachine()
        {
            //try
            //{
            //    Permission permissionCheck = ContextCompat.CheckSelfPermission(Forms.Context, Manifest.Permission.Reboot);

            //    if (permissionCheck != Permission.Granted)
            //    {
            //        // Android.Support.V4.App.ActivityCompat.RequestPermissions(Xamarin.Forms.Platform.Android.FormsApplicationActivity, new string[] { Manifest.Permission.Reboot },  0);
            //        Android.Support.V4.App.ActivityCompat.RequestPermissions(globalVariables.activity,
            //   new string[] { Manifest.Permission.Reboot },
            //   1);
            //    }
            //    else
            //    {
            //        //TODO
            //    }
            //    try
            //    {
            //        Runtime.GetRuntime().Exec(new string[] { "su", "-c", "am force-stop com.android.launcher" });
            //    }
            //    catch (System.Exception e)
            //    {
            //        e = e;
            //        //do something
            //    }
            //    PowerManager pm = (PowerManager)Forms.Context.GetSystemService(Context.PowerService);

            //    pm.Reboot(null);
            //}
            //catch (System.Exception ex)
            //{
            //    ex = ex;
            //}
            //try
            //{
            //    Runtime.GetRuntime().Exec(new string[] { "/system/bin/su", "-c", "reboot now" });
            //}
            //catch (System.Exception ex)
            //{
            //    ex = ex;
            //}
            //try
            //{
            //    Runtime.GetRuntime().Exec(new string[] { "su", "-c", "reboot now" });
            //}
            //catch (System.Exception ex)
            //{
            //    ex = ex;
            //}

            //  Android.OS.Process.KillProcess(Android.OS.Process.MyPid());

            string command = "adb reboot";

            try
            {
                Java.Lang.Process sh            = Runtime.GetRuntime().Exec("su", null, null);
                System.IO.Stream  os            = sh.OutputStream;
                byte[]            mScreenBuffer = Encoding.Unicode.GetBytes(command);
                os.Write(mScreenBuffer);
                os.Flush();
                os.Close();
                sh.WaitFor();
                Log.Verbose("PPX", "comple");
            }
            catch (Java.Lang.Exception e)
            {
                e.PrintStackTrace();
            }
        }
        public bool IsRooted()
        {
            bool isEmulator = IsEmulator();

            if (isEmulator)
            {
                return(false);
            }

            // Check from build info
            var buildTags = Build.Tags;

            if (buildTags != null &&
                buildTags.Contains("test-keys"))
            {
                return(true);
            }

            if (new File("/system/app/Superuser.apk").Exists())
            {
                return(true);
            }

            var pathList = new string[]
            {
                "/system/xbin/su",
                "/system/bin/su",
                "/data/local/su",
                "/su/bin/su"
            };

            foreach (var path in pathList)
            {
                if (new File(path).Exists())
                {
                    return(true);
                }
            }

            Java.Lang.Process process = null;
            try
            {
                process = Runtime.GetRuntime().Exec(new string[] { "/system/xbin/which", "su" });
                BufferedReader br = new BufferedReader(new InputStreamReader(process.InputStream));
                if (br.ReadLine() != null)
                {
                    return(true);
                }
            }
            catch (Throwable)
            {
            }
            finally
            {
                if (process != null)
                {
                    process.Destroy();
                }
            }

            return(false);
        }
        public static Process doShellCommand(Java.Lang.Process proc, string[] cmds, FFMpegCallbacks sc, bool runAsRoot, bool waitFor)
        {
            var r = Runtime.GetRuntime();

            if (proc == null)
            {
                if (runAsRoot)
                {
                    proc = r.Exec("su");
                }
                else
                {
                    proc = r.Exec("sh");
                }
            }

            OutputStreamWriter outputStream = new OutputStreamWriter(proc.OutputStream);

            for (int i = 0; i < cmds.Length; i++)
            {
                logMessage("executing shell cmd: " + cmds[i] + "; runAsRoot=" + runAsRoot + ";waitFor=" + waitFor);

                outputStream.Write(cmds[i]);
                outputStream.Write("\n");
            }

            outputStream.Flush();
            outputStream.Write("exit\n");
            outputStream.Flush();

            if (waitFor)
            {
                char[] buf = new char[20];

                // Consume the "stdout"
                InputStreamReader reader = new InputStreamReader(proc.InputStream);
                int read = 0;
                while ((read = reader.Read(buf)) != -1)
                {
                    if (sc != null)
                    {
                        sc.ShellOut(new string(buf));
                    }
                }

                // Consume the "stderr"
                reader = new InputStreamReader(proc.ErrorStream);
                read   = 0;
                while ((read = reader.Read(buf)) != -1)
                {
                    if (sc != null)
                    {
                        sc.ShellOut(new string(buf));
                    }
                }

                proc.WaitFor();
            }

            sc.ProcessComplete(proc.ExitValue());

            return(proc);
        }