public static bool canRunRootCommands() { bool retval = false; Process suProcess; try { suProcess = Runtime.GetRuntime().Exec("su"); var os = new Java.IO.DataOutputStream(suProcess.OutputStream); var osRes = new Java.IO.DataInputStream(suProcess.InputStream); if (null != os && null != osRes) { os.WriteBytes("id\n"); os.Flush(); string currUid = osRes.ReadLine(); bool exitSu = false; if (null == currUid) { retval = false; exitSu = false; Console.WriteLine("Can't get root access or denied by user"); } else if (true == currUid.Contains("uid=0")) { retval = true; exitSu = true; Console.WriteLine("Root access granted"); } else { retval = false; exitSu = true; Console.WriteLine("Root access rejected: " + currUid); } if (exitSu) { os.WriteBytes("exit\n"); os.Flush(); } } } catch (Java.Lang.Exception e) { retval = false; Console.WriteLine("Root access rejected [" + e.Class.Name + "] : " + e.Message); } return(retval); }
public static bool canRunRootCommands() { bool retval = false; Process suProcess; try { suProcess = Runtime.GetRuntime().Exec("su"); var os = new Java.IO.DataOutputStream(suProcess.OutputStream); var osRes = new Java.IO.DataInputStream(suProcess.InputStream); if (null != os && null != osRes) { os.WriteBytes("id\n"); os.Flush(); string currUid = osRes.ReadLine(); bool exitSu = false; if (null == currUid) { retval = false; exitSu = false; Console.WriteLine("Can't get root access or denied by user"); } else if (true == currUid.Contains("uid=0")) { retval = true; exitSu = true; Console.WriteLine("Root access granted"); } else { retval = false; exitSu = true; Console.WriteLine("Root access rejected: " + currUid); } if (exitSu) { os.WriteBytes("exit\n"); os.Flush(); } } } catch (Java.Lang.Exception e) { retval = false; Console.WriteLine("Root access rejected [" + e.Class.Name + "] : " + e.Message); } return retval; }
public static void readFully(this Java.IO.DataInputStream stream, byte[] b) { stream.ReadFully(b); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // set views btnPush = FindViewById<Button>(Resource.Id.btn_pushDB); btnSettings = FindViewById<Button>(Resource.Id.btn_settings); layout_settingsOK = FindViewById<LinearLayout>(Resource.Id.layout_settingsOK); btnPush.Click += async delegate { //btnPush.Text = ""; string smsdb = "/data/data/com.android.providers.telephony/databases/mmssms.db"; //btnPush.Text = "copying db to sdcard"; var p = Java.Lang.Runtime.GetRuntime().Exec("su"); var os = new Java.IO.DataOutputStream(p.OutputStream); var osRes = new Java.IO.DataInputStream(p.InputStream); var cmd = "cp " + smsdb + " /sdcard/dev/tmp/"; os.WriteBytes(cmd + '\n'); os.Flush(); //string msg = osRes.ReadLine(); //btnPush.Text = "maybe copied to sdcard"; HttpResponseMessage res; bool isGood; string msg; string localsmsdb = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.Path, "dev/tmp/mmssms.db"); using (var stream = File.OpenRead(localsmsdb)) { using (HttpClient httpClient = new HttpClient( new HttpClientHandler() { Credentials = new NetworkCredential(user,pass), PreAuthenticate = true }) ) { try { isGood = true; res = await httpClient.PutAsync(remotePath,new StreamContent(stream)); res.EnsureSuccessStatusCode(); msg="OK"; } catch (Exception ex) { isGood = false; msg = ex.Message; } } } btnPush.Text = string.Format("{0} => {1}", isGood, msg); }; btnSettings.Click += (sender, e)=> { var intent = new Intent(this, typeof(Settings)); StartActivity(intent); }; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // set views btnPush = FindViewById <Button>(Resource.Id.btn_pushDB); btnSettings = FindViewById <Button>(Resource.Id.btn_settings); layout_settingsOK = FindViewById <LinearLayout>(Resource.Id.layout_settingsOK); btnPush.Click += async delegate { //btnPush.Text = ""; string smsdb = "/data/data/com.android.providers.telephony/databases/mmssms.db"; //btnPush.Text = "copying db to sdcard"; var p = Java.Lang.Runtime.GetRuntime().Exec("su"); var os = new Java.IO.DataOutputStream(p.OutputStream); var osRes = new Java.IO.DataInputStream(p.InputStream); var cmd = "cp " + smsdb + " /sdcard/dev/tmp/"; os.WriteBytes(cmd + '\n'); os.Flush(); //string msg = osRes.ReadLine(); //btnPush.Text = "maybe copied to sdcard"; HttpResponseMessage res; bool isGood; string msg; string localsmsdb = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.Path, "dev/tmp/mmssms.db"); using (var stream = File.OpenRead(localsmsdb)) { using (HttpClient httpClient = new HttpClient( new HttpClientHandler() { Credentials = new NetworkCredential(user, pass), PreAuthenticate = true }) ) { try { isGood = true; res = await httpClient.PutAsync(remotePath, new StreamContent(stream)); res.EnsureSuccessStatusCode(); msg = "OK"; } catch (Exception ex) { isGood = false; msg = ex.Message; } } } btnPush.Text = string.Format("{0} => {1}", isGood, msg); }; btnSettings.Click += (sender, e) => { var intent = new Intent(this, typeof(Settings)); StartActivity(intent); }; }