Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 34 additions & 3 deletions Introspy-Android Config/src/com/introspy/config/InjectConfig.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.introspy.config;

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

import android.content.Context;
import android.content.SharedPreferences;
import android.util.Log;
Expand Down Expand Up @@ -38,12 +43,13 @@ public String getHookTypesFromPrefs(Context context) {

public void enableApp(String appDir, Context context) {
String path = appDir + "/introspy.config";
_command += "su -c echo '" + getHookTypesFromPrefs(context) + "' > " + path + " ; su -c chmod 664 " + path + " ; ";
_command += "echo '" + getHookTypesFromPrefs(context) + "' > " + path + " \n";
_command += "chmod 664 " + path + " \n";
}

public void disableApp(String appDir) {
String path = appDir + "/introspy.config";
_command += "su -c rm " + path + " ; ";
_command += "rm " + path + " \n";
}

private String _command = "";
Expand All @@ -53,7 +59,7 @@ public Boolean commit() {
return false;
Log.i(_TAG, _command);
try {
Runtime.getRuntime().exec(_command);
execSuCommand(_command);
} catch (Exception e) {
_command = "";
Log.w(_TAG, "error: this app needs to be root.");
Expand All @@ -69,4 +75,29 @@ public void writeConfig(Boolean enable, String appDir, Context context) {
else
disableApp(appDir);
}

public static String execSuCommand(String cmd) throws IOException
{
Log.e("execSuCommand", cmd);
Process process = Runtime.getRuntime().exec("su");

DataOutputStream os = new DataOutputStream(process.getOutputStream());
os.writeBytes(cmd+"\n");
os.flush();
os.writeBytes("exit\n");
os.flush();

BufferedReader reader = new BufferedReader(new InputStreamReader(
process.getInputStream()));
int read;
char[] buffer = new char[4096];
StringBuffer output = new StringBuffer();
while ((read = reader.read(buffer)) > 0) {
output.append(buffer, 0, read);
}
reader.close();
os.close();
return output.toString();
}

}