Search in sources :

Example 1 with ResourceFile

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

the class TabbedPane method makeContentPanel.

@Nullable
private ContentPanel makeContentPanel(JNode node) {
    if (node instanceof JResource) {
        JResource res = (JResource) node;
        ResourceFile resFile = res.getResFile();
        if (resFile != null) {
            if (resFile.getType() == ResourceType.IMG) {
                return new ImagePanel(this, res);
            }
        } else {
            return null;
        }
    }
    return new CodePanel(this, node);
}
Also used : ResourceFile(jadx.api.ResourceFile) JResource(jadx.gui.treemodel.JResource) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ResourceFile

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

the class ResourceIndex method getZipFile.

@Nullable
private ZipFile getZipFile(TreeNode res) {
    for (int i = 0; i < res.getChildCount(); i++) {
        TreeNode node = res.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 null;
            }
            ResourceFile file = resNode.getResFile();
            if (file == null) {
                ZipFile zip = getZipFile(resNode);
                if (zip != null) {
                    return zip;
                }
            } else {
                ResourceFile.ZipRef zipRef = file.getZipRef();
                if (zipRef != null) {
                    File zfile = zipRef.getZipFile();
                    if (FileUtils.isZipFile(zfile)) {
                        try {
                            return new ZipFile(zfile);
                        } catch (IOException ignore) {
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : ResourceFile(jadx.api.ResourceFile) ZipFile(java.util.zip.ZipFile) TreeNode(javax.swing.tree.TreeNode) JResource(jadx.gui.treemodel.JResource) IOException(java.io.IOException) ResourceFile(jadx.api.ResourceFile) File(java.io.File) ZipFile(java.util.zip.ZipFile) IOException(java.io.IOException) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with ResourceFile

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

the class RootNode method loadResources.

public void loadResources(List<ResourceFile> resources) {
    ResourceFile arsc = null;
    for (ResourceFile rf : resources) {
        if (rf.getType() == ResourceType.ARSC) {
            arsc = rf;
            break;
        }
    }
    if (arsc == null) {
        LOG.debug("'.arsc' file not found");
        return;
    }
    try {
        ResTableParser parser = ResourcesLoader.decodeStream(arsc, (size, is) -> {
            ResTableParser tableParser = new ResTableParser(this);
            tableParser.decode(is);
            return tableParser;
        });
        if (parser != null) {
            processResources(parser.getResStorage());
            updateObfuscatedFiles(parser, resources);
        }
    } catch (Exception e) {
        LOG.error("Failed to parse '.arsc' file", e);
    }
}
Also used : ResourceFile(jadx.api.ResourceFile) ResTableParser(jadx.core.xmlgen.ResTableParser) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Example 4 with ResourceFile

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

the class ExportGradleTest method exportGradle.

protected void exportGradle(String manifestFilename, String stringsFileName) {
    final JadxDecompiler decompiler = JadxDecompilerTestUtils.getMockDecompiler();
    ResourceFile androidManifest = mock(ResourceFile.class);
    final ResContainer androidManifestContainer = createResourceContainer(manifestFilename);
    when(androidManifest.loadContent()).thenReturn(androidManifestContainer);
    final ResContainer strings = createResourceContainer(stringsFileName);
    final RootNode root = decompiler.getRoot();
    final ExportGradleProject export = new ExportGradleProject(root, exportDir, androidManifest, strings);
    export.init();
    assertThat(export.getSrcOutDir().exists());
    assertThat(export.getResOutDir().exists());
}
Also used : ResourceFile(jadx.api.ResourceFile) RootNode(jadx.core.dex.nodes.RootNode) ExportGradleProject(jadx.core.export.ExportGradleProject) ResContainer(jadx.core.xmlgen.ResContainer) JadxDecompiler(jadx.api.JadxDecompiler)

Example 5 with ResourceFile

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

the class ImagePanel method loadImage.

private BufferedImage loadImage(JResource res) {
    ResourceFile resFile = res.getResFile();
    ResContainer resContainer = resFile.loadContent();
    ResContainer.DataType dataType = resContainer.getDataType();
    if (dataType == ResContainer.DataType.DECODED_DATA) {
        try {
            return ImageIO.read(new ByteArrayInputStream(resContainer.getDecodedData()));
        } catch (Exception e) {
            throw new JadxRuntimeException("Failed to load image", e);
        }
    } else if (dataType == ResContainer.DataType.RES_LINK) {
        try {
            return ResourcesLoader.decodeStream(resFile, (size, is) -> ImageIO.read(is));
        } catch (Exception e) {
            throw new JadxRuntimeException("Failed to load image", e);
        }
    } else {
        throw new JadxRuntimeException("Unsupported resource image data type: " + resFile);
    }
}
Also used : ResourceFile(jadx.api.ResourceFile) BufferedImage(java.awt.image.BufferedImage) RSyntaxTextArea(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea) TabbedPane(jadx.gui.ui.TabbedPane) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) AbstractCodeArea(jadx.gui.ui.codearea.AbstractCodeArea) ResContainer(jadx.core.xmlgen.ResContainer) ResourcesLoader(jadx.api.ResourcesLoader) JResource(jadx.gui.treemodel.JResource) ByteArrayInputStream(java.io.ByteArrayInputStream) ImageIO(javax.imageio.ImageIO) BorderLayout(java.awt.BorderLayout) ImageViewer(hu.kazocsaba.imageviewer.ImageViewer) ICodeWriter(jadx.api.ICodeWriter) Utils(jadx.core.utils.Utils) ResourceFile(jadx.api.ResourceFile) ResContainer(jadx.core.xmlgen.ResContainer) ByteArrayInputStream(java.io.ByteArrayInputStream) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) 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