Search in sources :

Example 6 with ResourceFile

use of jadx.api.ResourceFile in project jadx by skylot.

the class MainWindow method treeClickAction.

private void treeClickAction() {
    try {
        Object obj = tree.getLastSelectedPathComponent();
        if (obj instanceof JResource) {
            JResource res = (JResource) obj;
            ResourceFile resFile = res.getResFile();
            if (resFile != null && JResource.isSupportedForView(resFile.getType())) {
                tabbedPane.showResource(res);
            }
        } else if (obj instanceof JNode) {
            JNode node = (JNode) obj;
            JClass cls = node.getRootClass();
            if (cls != null) {
                tabbedPane.codeJump(new Position(cls, node.getLine()));
            }
        }
    } catch (Exception e) {
        LOG.error("Content loading error", e);
    }
}
Also used : ResourceFile(jadx.api.ResourceFile) Position(jadx.gui.utils.Position) JResource(jadx.gui.treemodel.JResource) JClass(jadx.gui.treemodel.JClass) CacheObject(jadx.gui.utils.CacheObject) JNode(jadx.gui.treemodel.JNode) ExpandVetoException(javax.swing.tree.ExpandVetoException)

Example 7 with ResourceFile

use of jadx.api.ResourceFile in project jadx by skylot.

the class ResourceIndex method traverseTree.

private void traverseTree(TreeNode root, @Nullable ZipFile zip) {
    for (int i = 0; i < root.getChildCount(); i++) {
        TreeNode node = root.getChildAt(i);
        if (node instanceof JResource) {
            JResource resNode = (JResource) node;
            try {
                resNode.loadNode();
            } catch (Exception e) {
                LOG.error("Error load resource node: {}", resNode, e);
                return;
            }
            ResourceFile resFile = resNode.getResFile();
            if (resFile == null) {
                traverseTree(node, zip);
            } else {
                if (resFile.getType() == ResourceType.ARSC && shouldSearchXML()) {
                    resFile.loadContent();
                    resNode.getFiles().forEach(t -> traverseTree(t, null));
                } else {
                    filter(resNode, zip);
                }
            }
        }
    }
}
Also used : ResourceFile(jadx.api.ResourceFile) TreeNode(javax.swing.tree.TreeNode) JResource(jadx.gui.treemodel.JResource) IOException(java.io.IOException)

Example 8 with ResourceFile

use of jadx.api.ResourceFile in project jadx by skylot.

the class MainWindow method nodeClickAction.

private boolean nodeClickAction(@Nullable Object obj) {
    if (obj == null) {
        return false;
    }
    try {
        if (obj instanceof JResource) {
            JResource res = (JResource) obj;
            ResourceFile resFile = res.getResFile();
            if (resFile != null && JResource.isSupportedForView(resFile.getType())) {
                return tabbedPane.showNode(res);
            }
        } else if (obj instanceof JNode) {
            JNode node = (JNode) obj;
            if (node.getRootClass() != null) {
                tabbedPane.codeJump(new JumpPosition(node));
                return true;
            }
            return tabbedPane.showNode(node);
        }
    } catch (Exception e) {
        LOG.error("Content loading error", e);
    }
    return false;
}
Also used : ResourceFile(jadx.api.ResourceFile) JumpPosition(jadx.gui.utils.JumpPosition) JResource(jadx.gui.treemodel.JResource) JNode(jadx.gui.treemodel.JNode) HeadlessException(java.awt.HeadlessException)

Example 9 with ResourceFile

use of jadx.api.ResourceFile in project jadx by skylot.

the class JRoot method getHierarchyResources.

private JResource getHierarchyResources(List<ResourceFile> resources) {
    JResource root = new JResource(null, NLS.str("tree.resources_title"), JResType.ROOT);
    String splitPathStr = Pattern.quote(File.separator);
    for (ResourceFile rf : resources) {
        String rfName;
        if (rf.getZipRef() != null) {
            rfName = rf.getDeobfName();
        } else {
            rfName = new File(rf.getDeobfName()).getName();
        }
        String[] parts = new File(rfName).getPath().split(splitPathStr);
        JResource curRf = root;
        int count = parts.length;
        for (int i = 0; i < count; i++) {
            String name = parts[i];
            JResource subRF = getResourceByName(curRf, name);
            if (subRF == null) {
                if (i != count - 1) {
                    subRF = new JResource(null, name, JResType.DIR);
                } else {
                    subRF = new JResource(rf, rf.getOriginalName(), name, JResType.FILE);
                }
                curRf.getFiles().add(subRF);
            }
            curRf = subRF;
        }
    }
    root.update();
    return root;
}
Also used : ResourceFile(jadx.api.ResourceFile) ResourceFile(jadx.api.ResourceFile) File(java.io.File)

Example 10 with ResourceFile

use of jadx.api.ResourceFile in project jadx by skylot.

the class ResourcesSaver method saveToFile.

private void saveToFile(ResContainer rc, File outFile) {
    switch(rc.getDataType()) {
        case TEXT:
        case RES_TABLE:
            SaveCode.save(rc.getText(), outFile);
            return;
        case DECODED_DATA:
            byte[] data = rc.getDecodedData();
            FileUtils.makeDirsForFile(outFile);
            try {
                Files.write(outFile.toPath(), data);
            } catch (Exception e) {
                LOG.warn("Resource '{}' not saved, got exception", rc.getName(), e);
            }
            return;
        case RES_LINK:
            ResourceFile resFile = rc.getResLink();
            FileUtils.makeDirsForFile(outFile);
            try {
                saveResourceFile(resFile, outFile);
            } catch (Exception e) {
                LOG.warn("Resource '{}' not saved, got exception", rc.getName(), e);
            }
            return;
        default:
            LOG.warn("Resource '{}' not saved, unknown type", rc.getName());
            break;
    }
}
Also used : ResourceFile(jadx.api.ResourceFile) JadxException(jadx.core.utils.exceptions.JadxException) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Aggregations

ResourceFile (jadx.api.ResourceFile)11 JResource (jadx.gui.treemodel.JResource)6 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)3 ResContainer (jadx.core.xmlgen.ResContainer)2 JNode (jadx.gui.treemodel.JNode)2 File (java.io.File)2 IOException (java.io.IOException)2 TreeNode (javax.swing.tree.TreeNode)2 Nullable (org.jetbrains.annotations.Nullable)2 ImageViewer (hu.kazocsaba.imageviewer.ImageViewer)1 ICodeWriter (jadx.api.ICodeWriter)1 JadxDecompiler (jadx.api.JadxDecompiler)1 ResourcesLoader (jadx.api.ResourcesLoader)1 RootNode (jadx.core.dex.nodes.RootNode)1 ExportGradleProject (jadx.core.export.ExportGradleProject)1 Utils (jadx.core.utils.Utils)1 JadxException (jadx.core.utils.exceptions.JadxException)1 ResTableParser (jadx.core.xmlgen.ResTableParser)1 ResourceStorage (jadx.core.xmlgen.ResourceStorage)1 ResourceEntry (jadx.core.xmlgen.entry.ResourceEntry)1