Search in sources :

Example 1 with AndroidManifestObject

use of com.wuntee.oter.aapt.androidmanifest.AndroidManifestObject in project otertool by wuntee.

the class PackageManagerController method loadPackageDetails.

public void loadPackageDetails(TableItem[] selection) {
    if (selection.length > 1) {
        return;
    }
    TableItem item = selection[0];
    final PackageBean bean = (PackageBean) item.getData(PackageBean.class.getName());
    logger.info("Loading package details for: " + bean.getApk());
    gui.setStatus("Loading package details for: " + bean.getApk());
    // Load file details
    Thread details = new Thread(new Runnable() {

        public void run() {
            // Pull file
            File apk = null;
            try {
                apk = AdbWorkshop.pullFile(bean.getApk());
            } catch (Exception e) {
                logger.error("Could not pull apk from device: ", e);
                GuiWorkshop.messageErrorThreaded(gui, "Could not pull apk from device: " + e.getMessage());
            }
            if (apk != null) {
                // Manifest
                try {
                    final AndroidManifestObject root = AndroidManifestWorkshop.getAndroidManifestObjectsForApk(apk);
                    gui.runRunnableAsync(new Runnable() {

                        public void run() {
                            // Load data in gui
                            gui.getPackageManagerAndroidManifestTab().loadAndroidManifestObjects(root);
                        }
                    });
                } catch (Exception e) {
                    logger.error("Could not parse the AndroidManifest.xml file: ", e);
                    GuiWorkshop.messageErrorThreaded(gui, "Could not parse the AndroidManifest.xml file: " + e.getMessage());
                }
                // AAPT
                List<String> details = null;
                try {
                    details = PackageManagerWorkshop.getDetailedPackageInfo(apk);
                } catch (Exception e) {
                    logger.error("Could not get detailed package information: ", e);
                    GuiWorkshop.messageErrorThreaded(gui, "Could not get detailed package information: " + e.getMessage());
                }
                final StringBuffer sb = new StringBuffer();
                if (details != null) {
                    for (String det : details) {
                        sb.append(det).append("\n");
                    }
                }
                gui.runRunnableAsync(new Runnable() {

                    public void run() {
                        // Load data in gui
                        gui.getPackageManagerStyledText().setText(sb.toString());
                    }
                });
            }
            // Files
            List<FsNode> files = null;
            try {
                files = FsWorkshop.getDirectoryRecursive("/data/data/" + bean.getClazz() + "/");
            } catch (Exception e) {
                logger.error("Could not get file listing: ", e);
                GuiWorkshop.messageErrorThreaded(gui, "Could not get file listing: " + e.getMessage());
            }
            if (files != null) {
                gui.runRunnableAsync(new FsListToTreeRunnable(files, gui.getPackageManagerFilesTree()));
            }
            gui.clearStatus();
        }
    });
    details.start();
}
Also used : FsListToTreeRunnable(com.wuntee.oter.view.widgets.runnable.FsListToTreeRunnable) TableItem(org.eclipse.swt.widgets.TableItem) FileToStyledTextRunnable(com.wuntee.oter.view.widgets.runnable.FileToStyledTextRunnable) FsListToTreeRunnable(com.wuntee.oter.view.widgets.runnable.FsListToTreeRunnable) List(java.util.List) AndroidManifestObject(com.wuntee.oter.aapt.androidmanifest.AndroidManifestObject) File(java.io.File) IOException(java.io.IOException) CommandFailedException(com.wuntee.oter.exception.CommandFailedException) SQLException(java.sql.SQLException)

Example 2 with AndroidManifestObject

use of com.wuntee.oter.aapt.androidmanifest.AndroidManifestObject in project otertool by wuntee.

the class CTabItemWithTreeForAndroidManifest method loadRecur.

private void loadRecur(AndroidManifestObject o, TreeItem parent) {
    TreeItem ti = null;
    if (parent == null) {
        ti = new TreeItem(this.getTree(), SWT.NONE);
    } else {
        ti = new TreeItem(parent, SWT.NONE);
    }
    if (o instanceof AndroidManifestElement) {
        AndroidManifestElement e = (AndroidManifestElement) o;
        ti.setText(e.getName());
        if (e.getName().equalsIgnoreCase("uses-permission")) {
            ti.setForeground(SWTResourceManager.getColor(SWT.COLOR_GREEN));
        } else if (e.getName().equalsIgnoreCase("activity")) {
            ti.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLUE));
        } else if (e.getName().equalsIgnoreCase("receiver") || e.getName().equalsIgnoreCase("provider")) {
            ti.setForeground(SWTResourceManager.getColor(SWT.COLOR_RED));
        }
    } else if (o instanceof AndroidManifestNamespace) {
        AndroidManifestNamespace n = (AndroidManifestNamespace) o;
        ti.setText(n.getName() + "=" + n.getValue());
    } else if (o instanceof AndroidManifestAttribute) {
        AndroidManifestAttribute a = (AndroidManifestAttribute) o;
        if (a.getRaw().equals("") && a.getType().equals("")) {
            ti.setText(a.getName() + "=" + a.getValue());
        } else if (a.getRaw().equals("") && !a.getType().equals("")) {
            ti.setText(a.getName() + "[" + a.getType() + "]=" + a.getValue());
        } else if (!a.getRaw().equals("") && a.getType().equals("")) {
            ti.setText(a.getName() + "[" + a.getRaw() + "]=" + a.getValue());
        } else {
            ti.setText(a.getName() + "[" + a.getType() + ":" + a.getRaw() + "]=" + a.getValue());
        }
    }
    String attributes = " [";
    for (AndroidManifestObject child : o.getChildren()) {
        if (child instanceof AndroidManifestAttribute) {
            AndroidManifestAttribute a = (AndroidManifestAttribute) child;
            attributes = attributes + a.getName() + "=" + a.getValue() + ", ";
        } else {
            loadRecur(child, ti);
        }
    }
    if (!attributes.equals(" [")) {
        ti.setText(ti.getText() + attributes.substring(0, attributes.length() - 2) + "]");
    }
    ti.setExpanded(true);
}
Also used : AndroidManifestAttribute(com.wuntee.oter.aapt.androidmanifest.AndroidManifestAttribute) AndroidManifestNamespace(com.wuntee.oter.aapt.androidmanifest.AndroidManifestNamespace) TreeItem(org.eclipse.swt.widgets.TreeItem) AndroidManifestElement(com.wuntee.oter.aapt.androidmanifest.AndroidManifestElement) AndroidManifestObject(com.wuntee.oter.aapt.androidmanifest.AndroidManifestObject)

Aggregations

AndroidManifestObject (com.wuntee.oter.aapt.androidmanifest.AndroidManifestObject)2 AndroidManifestAttribute (com.wuntee.oter.aapt.androidmanifest.AndroidManifestAttribute)1 AndroidManifestElement (com.wuntee.oter.aapt.androidmanifest.AndroidManifestElement)1 AndroidManifestNamespace (com.wuntee.oter.aapt.androidmanifest.AndroidManifestNamespace)1 CommandFailedException (com.wuntee.oter.exception.CommandFailedException)1 FileToStyledTextRunnable (com.wuntee.oter.view.widgets.runnable.FileToStyledTextRunnable)1 FsListToTreeRunnable (com.wuntee.oter.view.widgets.runnable.FsListToTreeRunnable)1 File (java.io.File)1 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 List (java.util.List)1 TableItem (org.eclipse.swt.widgets.TableItem)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1