com.jrummyapps.android.shell.Shell Java Examples

The following examples show how to use com.jrummyapps.android.shell.Shell. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModulesVersions.java    From InviZible with GNU General Public License v3.0 5 votes vote down vote up
private void openCommandShell() {
    closeCommandShell();

    try {
        console = Shell.SH.getConsole();
    } catch (ShellNotFoundException e) {
        Log.e(LOG_TAG, "ModulesStatus: SH shell not found! " + e.getMessage() + e.getCause());
    }
}
 
Example #2
Source File: AdvancedNetworking.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
private int exec (String cmd, boolean wait) throws Exception
{
    CommandResult shellResult = Shell.run(cmd);
    debug("CMD: " + cmd + "; SUCCESS=" + shellResult.isSuccessful());

    if (!shellResult.isSuccessful()) {
        throw new Exception("Error: " + shellResult.exitCode + " ERR=" + shellResult.getStderr() + " OUT=" + shellResult.getStdout());
    }

    return shellResult.exitCode;
}
 
Example #3
Source File: ModulesStarterHelper.java    From InviZible with GNU General Public License v3.0 4 votes vote down vote up
Runnable getDNSCryptStarterRunnable() {
    return () -> {
        //new experiment
        android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);

        String dnsCmdString;
        final CommandResult shellResult;
        if (modulesStatus.isUseModulesWithRoot()) {

            dnsCmdString = busyboxPath + "nohup " + dnscryptPath
                    + " -config " + appDataDir
                    + "/app_data/dnscrypt-proxy/dnscrypt-proxy.toml -pidfile "+ appDataDir
                    + "/dnscrypt-proxy.pid >/dev/null 2>&1 &";
            String waitString = busyboxPath + "sleep 3";
            String checkIfModuleRunning = busyboxPath + "pgrep -l /libdnscrypt-proxy.so";

            shellResult = Shell.SU.run(dnsCmdString, waitString, checkIfModuleRunning);

            new PrefManager(service).setBoolPref("DNSCryptStartedWithRoot", true);

            if (shellResult.getStdout().contains(dnscryptPath)) {
                sendResultIntent(DNSCryptRunFragmentMark, DNSCRYPT_KEYWORD, dnscryptPath);
            } else {
                sendResultIntent(DNSCryptRunFragmentMark, DNSCRYPT_KEYWORD, "");
            }

        } else {
            dnsCmdString = dnscryptPath + " -config " + appDataDir
                    + "/app_data/dnscrypt-proxy/dnscrypt-proxy.toml -pidfile " + appDataDir + "/dnscrypt-proxy.pid";
            new PrefManager(service).setBoolPref("DNSCryptStartedWithRoot", false);

            shellResult = Shell.SH.run(dnsCmdString);
        }

        if (!shellResult.isSuccessful()) {

            if (modulesStatus.getDnsCryptState() == RESTARTING) {
                return;
            }

            if (modulesStatus.getDnsCryptState() != STOPPING && modulesStatus.getDnsCryptState() != STOPPED) {

                if (appVersion.startsWith("b")) {
                    handler.post(() -> Toast.makeText(service, "DNSCrypt Module Fault: "
                            + shellResult.exitCode + "\n\n ERR = " + shellResult.getStderr()
                            + "\n\n OUT = " + shellResult.getStdout(), Toast.LENGTH_LONG).show());
                }

                sendAskForceCloseBroadcast(service, "DNSCrypt");
            }

            Log.e(LOG_TAG, "Error DNSCrypt: "
                    + shellResult.exitCode + " ERR=" + shellResult.getStderr()
                    + " OUT=" + shellResult.getStdout());

            modulesStatus.setDnsCryptState(STOPPED);

            ModulesAux.makeModulesStateExtraLoop(service);

            sendResultIntent(DNSCryptRunFragmentMark, DNSCRYPT_KEYWORD, "");
        }
    };
}
 
Example #4
Source File: ModulesStarterHelper.java    From InviZible with GNU General Public License v3.0 4 votes vote down vote up
Runnable getITPDStarterRunnable() {
    return () -> {
        //new experiment
        android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);

        String itpdCmdString;

        final CommandResult shellResult;
        if (modulesStatus.isUseModulesWithRoot()) {
            correctITPDConfRunAsDaemon(service, appDataDir, true);

            Shell.SU.run(busyboxPath + "mkdir -p " + appDataDir + "/i2pd_data",
                    "cd " + appDataDir + "/app_data/i2pd",
                    busyboxPath + "cp -R certificates " + appDataDir + "/i2pd_data");

            itpdCmdString = itpdPath + " --conf " + appDataDir
                    + "/app_data/i2pd/i2pd.conf --datadir " + appDataDir
                    + "/i2pd_data --pidfile " + appDataDir + "/i2pd.pid &";
            String waitString = busyboxPath + "sleep 3";
            String checkIfModuleRunning = busyboxPath + "pgrep -l /libi2pd.so";

            shellResult = Shell.SU.run(itpdCmdString, waitString, checkIfModuleRunning);

            new PrefManager(service).setBoolPref("ITPDStartedWithRoot", true);

            if (shellResult.getStdout().contains(itpdPath)) {
                sendResultIntent(I2PDRunFragmentMark, ITPD_KEYWORD, itpdPath);
            } else {
                sendResultIntent(I2PDRunFragmentMark, ITPD_KEYWORD, "");
            }

        } else {
            correctITPDConfRunAsDaemon(service, appDataDir, false);
            itpdCmdString = itpdPath + " --conf " + appDataDir
                    + "/app_data/i2pd/i2pd.conf --datadir " + appDataDir
                    + "/i2pd_data --pidfile " + appDataDir + "/i2pd.pid";
            new PrefManager(service).setBoolPref("ITPDStartedWithRoot", false);

            shellResult = Shell.SH.run(itpdCmdString);
        }

        if (!shellResult.isSuccessful()) {

            if (modulesStatus.getItpdState() == RESTARTING) {
                return;
            }

            if (modulesStatus.getItpdState() != STOPPING && modulesStatus.getItpdState() != STOPPED) {
                if (appVersion.startsWith("b")) {
                    handler.post(() -> Toast.makeText(service, "Purple I2P Module Fault: "
                            + shellResult.exitCode + "\n\n ERR = " + shellResult.getStderr()
                            + "\n\n OUT = " + shellResult.getStdout(), Toast.LENGTH_LONG).show());
                }

                sendAskForceCloseBroadcast(service, "I2P");
            }

            Log.e(LOG_TAG, "Error ITPD: " + shellResult.exitCode + " ERR="
                    + shellResult.getStderr() + " OUT=" + shellResult.getStdout());

            modulesStatus.setItpdState(STOPPED);

            ModulesAux.makeModulesStateExtraLoop(service);

            sendResultIntent(I2PDRunFragmentMark, ITPD_KEYWORD, "");
        }
    };
}
 
Example #5
Source File: ViewDumper.java    From fuckView with GNU Affero General Public License v3.0 4 votes vote down vote up
public static synchronized ArrayList<ViewItem> parseCurrentView() {
//        File f = new File("/mnt/sdcard/dump.xml");
//        if (f.exists()) f.delete();


        Shell.SU.run("uiautomator dump /mnt/sdcard/dump.xml");
        String xml = MainActivity.readFile("dump.xml").replace("\n", "");
        ArrayList<ViewItem> itemList = new ArrayList<>();
        ViewItem temp;
        XmlPullParser parser = Xml.newPullParser();
        try {
            parser.setInput(new StringReader(xml));
            int eventType = parser.getEventType();
            while (eventType != XmlPullParser.END_DOCUMENT) {
                String tagName = parser.getName();
                switch (eventType) {
                    case XmlPullParser.START_TAG:
                        if ("node".equals(tagName)) {
                            temp = new ViewItem();
                            //读类名
                            String[] className = parser.getAttributeValue(null, "class").split("\\.");
                            temp.simpleClassName = className[className.length - 1];
                            //读坐标
                            String bounds = parser.getAttributeValue(null, "bounds");
                            String[] tempN = bounds.replaceFirst("\\[", "").split("\\]\\[");
                            String[] point = tempN[0].split(",");
                            if (point.length == 2) {
                                temp.bounds = new Point(Integer.valueOf(point[0]), Integer.valueOf(point[1]));
                            } else {
                                temp.bounds = new Point();
                            }
                            //读宽高
                            point = bounds.split("\\]\\[")[1].split(",");
                            if (point.length == 2) {
                                temp.wh = new Point(Integer.valueOf(point[0]) - temp.bounds.x, Integer.valueOf(point[1].replaceFirst("\\]", "")) - temp.bounds.y);
                            } else {
                                temp.wh = new Point();
                            }
                            //其他杂类信息
                            temp.id = itemList.size();
                            temp.level = parser.getDepth();
                            ViewItem vi = getLastTopLevelNode(itemList, temp.level - 1);
                            temp.parentId = (vi == null ? NO_PARENT : vi.id);
                            itemList.add(temp);
                        }
                        break;
                    default:
                        break;
                }
                eventType = parser.next();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return itemList;
    }
 
Example #6
Source File: CheckerFragment.java    From fuckView with GNU Affero General Public License v3.0 4 votes vote down vote up
private void fillCheckerList() {
    Executors.newSingleThreadExecutor().execute(new Runnable() {
        @Override
        public void run() {
            final ArrayList<HashMap<String, String>> dataList = new ArrayList<>();
            HashMap<String, String> row = new HashMap<>();
            row.put("item", getString(R.string.check_item_module_enabled));
            row.put("status", bool2Str(MainActivity.isModuleActive()));
            dataList.add(row);

            row = new HashMap<>(2);
            row.put("item", getString(R.string.check_item_floating_permission));
            row.put("status", bool2Str(canShowFloatingWindow()));
            dataList.add(row);


            row = new HashMap<>(2);
            row.put("item", getString(R.string.check_item_service_running));
            row.put("status", bool2Str(DumperService.getInstance() != null && DumperService.getInstance().getRootInActiveWindow() != null));
            dataList.add(row);


            row = new HashMap<>(2);
            row.put("item", getString(R.string.check_item_root));
            row.put("status", bool2Str(Shell.SU.available()));
            dataList.add(row);
            mCheckerList.post(new Runnable() {
                @Override
                public void run() {
                    mCheckerList.setAdapter(new SimpleAdapter(getContext(), dataList, R.layout.pairs, new String[]{"item", "status"}, new int[]{R.id.pairs_textView1, R.id.pairs_textView2}));
                    int colorResId = MainActivity.isModuleActive() ? R.color.darker_green : R.color.warning;
                    int iconResId = MainActivity.isModuleActive() ? R.drawable.ic_check_circle : R.drawable.ic_error;
                    int textResId = MainActivity.isModuleActive() ? R.string.module_active : R.string.module_not_active;
                    mStatusText.setText(textResId);
                    mStatusText.setTextColor(getResources().getColor(colorResId));
                    mStatusIcon.setImageResource(iconResId);
                    mStatusContainer.setBackgroundColor(getResources().getColor(colorResId));
                    dismiss();
                }
            });
        }
    });

}
 
Example #7
Source File: PreferencesActivity.java    From fuckView with GNU Affero General Public License v3.0 4 votes vote down vote up
private String getLogcatInfo() {
    return Shell.SU.run("logcat -d -v time").getStdout();
}
 
Example #8
Source File: PreferencesActivity.java    From fuckView with GNU Affero General Public License v3.0 4 votes vote down vote up
private String getXposedLogInfo() {
    return Shell.SU.run("cat /data/data/de.robv.android.xposed.installer/log/error.log").getStdout();
}