NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.tasarhane.cmd">

<uses-permission android:name="android.permission.ACCESS_SUPERUSER"/>


<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>




package com.tasarhane.cmd;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

//TODO check roottools http://code.google.com/p/roottools/
public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

final Button su = (Button) findViewById(R.id.su_button);
su.setOnClickListener(new Button.OnClickListener() {

@Override
public void onClick(View v) {
RootShell.su();
}
});

}

}









package com.tasarhane.cmd;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;

import android.util.Log;

public class RootShell {
private static final String LOG_TAG = RootShell.class.getSimpleName();

public static void shExecute(String[] commands) {
Process shell = null;
DataOutputStream out = null;

try {
// Acquire shell - no root
Log.i("RootShell", "Starting exec of sh");
shell = Runtime.getRuntime().exec("sh");
// Create stream for sh shell
out = new DataOutputStream(shell.getOutputStream());

// Executing commands without root rights
Log.i(LOG_TAG, "Executing commands...");
for (String command : commands) {
Log.i(LOG_TAG, "Executing: " + command);
out.writeBytes(command + "n");
out.flush();
}

out.writeBytes("exitn");
out.flush();
shell.waitFor();

} catch (Exception e) {
Log.e(LOG_TAG, "ShellRoot#shExecute() finished with error", e);
} finally {
try {
if (out != null) {
out.close();
}
// shell.destroy();
} catch (Exception e) {
// hopeless
}
}
}

public static void su(){
Process shell = null;
DataOutputStream out = null;

try {
shell = Runtime.getRuntime().exec("su");
out = new DataOutputStream(shell.getOutputStream());

out.writeBytes("monkey -f /storage/sdcard0/Pictures/dnm1.txt 1" + "n");
out.flush();

out.writeBytes("exitn");
out.flush();

shell.waitFor();

} catch (Exception e) {
Log.d(LOG_TAG, "ShellRoot#suExecute() finished with error", e);
} finally {
try {
if (out != null) {
out.close();
}
// shell.destroy();
} catch (Exception e) {
// hopeless
}
}


}

public static void suExecute(String[] commands) {
Process shell = null;
DataOutputStream out = null;
BufferedReader in = null;

try {
// Acquire root
Log.i(LOG_TAG, "Starting exec of su");
shell = Runtime.getRuntime().exec("su");
// Create stream for root shell
out = new DataOutputStream(shell.getOutputStream());

in = new BufferedReader(new InputStreamReader(shell.getInputStream()));

// Executing commands with root rights
Log.i(LOG_TAG, "Executing commands...");
for (String command : commands) {
Log.i(LOG_TAG, "Executing: " + command);
out.writeBytes("input tap 10 10" + "n");
out.flush();
}

out.writeBytes("exitn");
out.flush();
String line;
StringBuilder sb = new StringBuilder();
while ((line = in.readLine()) != null) {
sb.append(line).append("n");
}
Log.i(LOG_TAG, sb.toString());
shell.waitFor();

} catch (Exception e) {
Log.d(LOG_TAG, "ShellRoot#suExecute() finished with error", e);
} finally {
try {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
// shell.destroy();
} catch (Exception e) {
// hopeless
}
}
}

// run command with su rights and return output of that command(inside su
// shell)
public static void suOutputExecute(String command) {
try {
int BUFF_LEN = 1024;
Process p = Runtime.getRuntime().exec(new String[] { "su", "-c", "system/bin/sh" });
DataOutputStream stdin = new DataOutputStream(p.getOutputStream());
// from here all commands are executed with su permissions
stdin.writeBytes(command + "n"); // n executes the command
InputStream stdout = p.getInputStream();
byte[] buffer = new byte[BUFF_LEN];
int read;
String out = new String();
// read method will wait forever if there is nothing in the stream
// so we need to read it in another way than
// while((read=stdout.read(buffer))>0)
while (true) {
read = stdout.read(buffer);
out += new String(buffer, 0, read);
if (read < BUFF_LEN) {
// we have read everything
break;
}
}
stdout.close();
Log.e("ROOT", out);
p.waitFor();
} catch (Exception e) {
Log.e("ROOT", "Error", e);
}
}

/**
* Copy busybox binaries to /data/data/lecho.sample.rootshel and set x
* permission
*
* @param command
* for example /data/data/my.app/files/busybox ping -4 8.8.8.8
*/
public static void busyboxExecute(String command) {
try {
int BUFF_LEN = 1024;
Process p = Runtime.getRuntime().exec(command);
BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream()));
char[] buffer = new char[BUFF_LEN];
int read;
StringBuilder out = new StringBuilder();
while ((read = stdout.read(buffer)) > 0) {
out.append(buffer, 0, read);
}
stdout.close();
Log.e("ROOT", out.toString());
p.waitFor();
} catch (Exception e) {
Log.e("ROOT", "Error", e);
}
}
}







<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<EditText
android:id="@+id/edit"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/sh_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SH shell" />
<Button
android:id="@+id/su_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SU shell" />
<Button
android:id="@+id/su_output_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SU output" />
<Button
android:id="@+id/busybox_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Busybox" />
</LinearLayout>
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.