Search in sources :

Example 6 with ResContainer

use of jadx.core.xmlgen.ResContainer 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)

Example 7 with ResContainer

use of jadx.core.xmlgen.ResContainer in project jadx by skylot.

the class ResourcesLoader method decodeStream.

public static ResContainer decodeStream(ResourceFile rf, ResourceDecoder decoder) throws JadxException {
    ZipRef zipRef = rf.getZipRef();
    if (zipRef == null) {
        return null;
    }
    ZipFile zipFile = null;
    InputStream inputStream = null;
    ResContainer result = null;
    try {
        zipFile = new ZipFile(zipRef.getZipFile());
        ZipEntry entry = zipFile.getEntry(zipRef.getEntryName());
        if (entry == null) {
            throw new IOException("Zip entry not found: " + zipRef);
        }
        inputStream = new BufferedInputStream(zipFile.getInputStream(entry));
        result = decoder.decode(entry.getSize(), inputStream);
    } catch (Exception e) {
        throw new JadxException("Error decode: " + zipRef.getEntryName(), e);
    } finally {
        try {
            if (zipFile != null) {
                zipFile.close();
            }
        } catch (Exception e) {
            LOG.error("Error close zip file: {}", zipRef, e);
        }
        close(inputStream);
    }
    return result;
}
Also used : JadxException(jadx.core.utils.exceptions.JadxException) ResContainer(jadx.core.xmlgen.ResContainer) ZipFile(java.util.zip.ZipFile) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException) ZipRef(jadx.api.ResourceFile.ZipRef) JadxException(jadx.core.utils.exceptions.JadxException) IOException(java.io.IOException)

Example 8 with ResContainer

use of jadx.core.xmlgen.ResContainer in project jadx by skylot.

the class JResource method loadSubNodes.

private void loadSubNodes(JResource root, ResContainer rc, int depth) {
    String resName = rc.getName();
    String[] path = resName.split("/");
    String resShortName = path.length == 0 ? resName : path[path.length - 1];
    ICodeInfo code = rc.getText();
    ResourceFileContent fileContent = new ResourceFileContent(resShortName, ResourceType.XML, code);
    addPath(path, root, new JResource(fileContent, resName, resShortName, JResType.FILE));
    for (ResContainer subFile : rc.getSubFiles()) {
        loadSubNodes(root, subFile, depth + 1);
    }
}
Also used : ResContainer(jadx.core.xmlgen.ResContainer) ResourceFileContent(jadx.api.ResourceFileContent) ICodeInfo(jadx.api.ICodeInfo)

Aggregations

ResContainer (jadx.core.xmlgen.ResContainer)8 ResourceFile (jadx.api.ResourceFile)3 ICodeInfo (jadx.api.ICodeInfo)2 ResourceFileContent (jadx.api.ResourceFileContent)2 ExportGradleProject (jadx.core.export.ExportGradleProject)2 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)2 File (java.io.File)2 ImageViewer (hu.kazocsaba.imageviewer.ImageViewer)1 ICodeWriter (jadx.api.ICodeWriter)1 JadxDecompiler (jadx.api.JadxDecompiler)1 ZipRef (jadx.api.ResourceFile.ZipRef)1 ResourcesLoader (jadx.api.ResourcesLoader)1 CodeWriter (jadx.core.codegen.CodeWriter)1 RootNode (jadx.core.dex.nodes.RootNode)1 Utils (jadx.core.utils.Utils)1 JadxException (jadx.core.utils.exceptions.JadxException)1 JResource (jadx.gui.treemodel.JResource)1 TabbedPane (jadx.gui.ui.TabbedPane)1 AbstractCodeArea (jadx.gui.ui.codearea.AbstractCodeArea)1 BorderLayout (java.awt.BorderLayout)1