Introducing XDA:DevCon – A Conference For Developers By Developers
XDA Developers Android and Mobile Development Forum
Forgot your password?
 
Post Reply+
Tip us?
 
jcase
Old
#1  
jcase's Avatar
Forum Moderator / Elite Recognized Developer - OP
Thanks Meter 2652
Posts: 2,016
Join Date: Feb 2010
Location: Noonya Washington

 
DONATE TO ME
Default [CODE] Launching shell commands

Basic command launch. Here I am using it to start/stop dropbear shhD. Sloppy? Yes, Dirty? Yes Works? Yes.

Code:
package net.andirc.dropbear;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;

public class dropbear extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        
    	AlertDialog.Builder alert = new AlertDialog.Builder(this);  

		alert.setTitle("DropBear");  
		alert.setMessage("Start or Kill");  
		  

		  
		alert.setPositiveButton("Start", new DialogInterface.OnClickListener() {  
		public void onClick(DialogInterface dialog, int whichButton) {  

			  Process myproc = null;
		       BufferedReader reader = null;  
		       try
		       {


		    	   myproc = Runtime.getRuntime().exec(new String[] {"su", "-c", "dropbear"}); 
		    	   reader = new BufferedReader(new InputStreamReader(myproc.getInputStream()));
		    	   
		               String line;
		               final StringBuilder sb = new StringBuilder();
		               String separator = System.getProperty("line.separator");
		        
		               while ((line = reader.readLine()) != null)
		               {
		                       sb.append(line);
		                       sb.append(separator);
		               }
		        
		               
}
		        
		       catch (Exception ex)
		       {
	
		       }

		       finally {} 
		       System.exit(0);  
			
		  }  
		});  
		  
		alert.setNegativeButton("Kill", new DialogInterface.OnClickListener() {  
		  public void onClick(DialogInterface dialog, int whichButton) {  
		      
		       Process myproc = null;
		       BufferedReader reader = null;  
		       try
		       {


		    	   myproc = Runtime.getRuntime().exec(new String[] {"su", "-c", "kill $(ps | grep dropbear | tr -s  ' ' | cut -d ' ' -f2)"}); 
		    	   reader = new BufferedReader(new InputStreamReader(myproc.getInputStream()));
		    	   
		               String line;
		               final StringBuilder sb = new StringBuilder();
		               String separator = System.getProperty("line.separator");
		        
		               while ((line = reader.readLine()) != null)
		               {
		                       sb.append(line);
		                       sb.append(separator);
		               }
		        
		               
}
		        
		       catch (Exception ex)
		       {
	
		       }

		       finally {} 
		       System.exit(0);  
		  }  
		});  
		  
		alert.show();     
		}
        
    }
I hack phones.

My Bitcoin address : 1Newifz6yETTmbziCsZZstmHHPH6ejNr75
 
nindoja
Old
#2  
Senior Member
Thanks Meter 6
Posts: 159
Join Date: Nov 2009
Quote:
Originally Posted by jcase View Post
Basic command launch. Here I am using it to start/stop dropbear shhD. Sloppy? Yes, Dirty? Yes Works? Yes.
Thanks for contributing the code, but I'm not sure why you think it's dirty? Based on my java experience (and my limited Android dev experience) that is how I would have done it.
 
jcase
Old
#3  
jcase's Avatar
Forum Moderator / Elite Recognized Developer - OP
Thanks Meter 2652
Posts: 2,016
Join Date: Feb 2010
Location: Noonya Washington

 
DONATE TO ME
Base on my utter lack of experience, and the fact that its pasted together from here and there. I assume there is a far cleaner way of doing it. Maybe not, works for me.

So nice not needing a cable to pull up a shell.
I hack phones.

My Bitcoin address : 1Newifz6yETTmbziCsZZstmHHPH6ejNr75
 
morphius2036
Old
#4  
morphius2036's Avatar
Senior Member
Thanks Meter 3
Posts: 223
Join Date: Sep 2009
Location: G-Vegas
Quote:
Originally Posted by jcase View Post
Base on my utter lack of experience, and the fact that its pasted together from here and there. I assume there is a far cleaner way of doing it. Maybe not, works for me.

So nice not needing a cable to pull up a shell.
Funny thing Jcase your dirty hacks look pro to me keep up the great work. When do you have time for sleep with a fam and school and all of us other dependents....to bad you can't claim us on taxes!
 
Post Reply+
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Go to top of page...