Android Open Source - devoxx-2013-android-app-security Exec Shell






From Project

Back to project page devoxx-2013-android-app-security.

License

The source code is released under:

Apache License

If you think the Android project devoxx-2013-android-app-security listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package be.idamf.android.tamperdetection.util;
//from  www. j a  va 2s.  c  om
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 * Helper class to check if su can be called.
 * See http://www.simonroses.com/2013/06/appsec-build-rooted-detection-in-your-app/
 * and
 * http://stackoverflow.com/questions/1101380/determine-if-running-on-a-rooted-device
 */
public class ExecShell {

    protected static enum SHELL_CMD {
        check_su_binary(new String[] { "/system/xbin/which","su" });

        String[] commands;

        SHELL_CMD(final String[] commands) {
            this.commands = commands;
        }
    }

    public List<String> executeCommand(SHELL_CMD shellCmd) {
        String line = null;
        List<String> fullResponse = new ArrayList<String>();
        Process process = null;

        try {
            process = Runtime.getRuntime().exec(shellCmd.commands);
        } catch (IOException e) {
            return null;
        }

        BufferedReader processComm = new BufferedReader(new InputStreamReader(process.getInputStream()));
        try {
            while ((line = processComm.readLine()) != null) {
                fullResponse.add(line);
            }
        } catch (IOException e) {
            fullResponse = null;
        } finally {
            if (processComm != null) {
                try {
                    processComm.close();
                } catch (IOException e) {
                    // failed to close inputStream
                }
            }
        }
        process.destroy();

        return fullResponse;
    }
}




Java Source Code List

be.idamf.android.tamperdetection.MainActivity.java
be.idamf.android.tamperdetection.data.PublicKeyInfo.java
be.idamf.android.tamperdetection.pinning.TrustAllTrustManager.java
be.idamf.android.tamperdetection.task.EnvironmentChecker.java
be.idamf.android.tamperdetection.task.RootDetector.java
be.idamf.android.tamperdetection.ui.EnvironmentCheckFragment.java
be.idamf.android.tamperdetection.ui.NetworkCheckFragment.java
be.idamf.android.tamperdetection.ui.RootCheckFragment.java
be.idamf.android.tamperdetection.util.ExecShell.java
be.idamf.android.tamperdetection.util.RootDetectionUtils.java
be.idamf.android.tamperdetection.util.TamperDetectionUtils.java