Search in sources :

Example 1 with ResContainer

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

the class JResource method addSubFiles.

protected void addSubFiles(ResContainer rc, JResource root, int depth) {
    CodeWriter cw = rc.getContent();
    if (cw != null) {
        if (depth == 0) {
            root.lineMapping = cw.getLineMapping();
            root.content = cw.toString();
        } else {
            String name = rc.getName();
            String[] path = name.split("/");
            String shortName = path.length == 0 ? name : path[path.length - 1];
            ResourceFileContent fileContent = new ResourceFileContent(shortName, ResourceType.XML, cw);
            addPath(path, root, new JResource(fileContent, name, shortName, JResType.FILE));
        }
    }
    List<ResContainer> subFiles = rc.getSubFiles();
    if (!subFiles.isEmpty()) {
        for (ResContainer subFile : subFiles) {
            addSubFiles(subFile, root, depth + 1);
        }
    }
}
Also used : ResContainer(jadx.core.xmlgen.ResContainer) ResourceFileContent(jadx.api.ResourceFileContent) CodeWriter(jadx.core.codegen.CodeWriter)

Example 2 with ResContainer

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

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

the class ExportGradleTest method createResourceContainer.

protected ResContainer createResourceContainer(String filename) {
    final ResContainer container = mock(ResContainer.class);
    ICodeInfo codeInfo = mock(ICodeInfo.class);
    when(codeInfo.getCodeStr()).thenReturn(loadFileContent(new File(MANIFEST_TESTS_DIR, filename)));
    when(container.getText()).thenReturn(codeInfo);
    return container;
}
Also used : ResContainer(jadx.core.xmlgen.ResContainer) ICodeInfo(jadx.api.ICodeInfo) ResourceFile(jadx.api.ResourceFile) File(java.io.File)

Example 4 with ResContainer

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

the class JadxDecompiler method getSaveTasks.

private List<Runnable> getSaveTasks(boolean saveSources, boolean saveResources) {
    if (root == null) {
        throw new JadxRuntimeException("No loaded files");
    }
    File sourcesOutDir;
    File resOutDir;
    if (args.isExportAsGradleProject()) {
        ResourceFile androidManifest = resources.stream().filter(resourceFile -> resourceFile.getType() == ResourceType.MANIFEST).findFirst().orElseThrow(IllegalStateException::new);
        ResContainer strings = resources.stream().filter(resourceFile -> resourceFile.getType() == ResourceType.ARSC).findFirst().orElseThrow(IllegalStateException::new).loadContent().getSubFiles().stream().filter(resContainer -> resContainer.getFileName().contains("strings.xml")).findFirst().orElseThrow(IllegalStateException::new);
        ExportGradleProject export = new ExportGradleProject(root, args.getOutDir(), androidManifest, strings);
        export.init();
        sourcesOutDir = export.getSrcOutDir();
        resOutDir = export.getResOutDir();
    } else {
        sourcesOutDir = args.getOutDirSrc();
        resOutDir = args.getOutDirRes();
    }
    List<Runnable> tasks = new ArrayList<>();
    // save resources first because decompilation can hang or fail
    if (saveResources) {
        appendResourcesSaveTasks(tasks, resOutDir);
    }
    if (saveSources) {
        appendSourcesSave(tasks, sourcesOutDir);
    }
    return tasks;
}
Also used : ExportGradleProject(jadx.core.export.ExportGradleProject) ResContainer(jadx.core.xmlgen.ResContainer) ArrayList(java.util.ArrayList) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) File(java.io.File)

Example 5 with ResContainer

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

the class JResource method getContent.

@Override
public synchronized String getContent() {
    if (loaded) {
        if (content == null) {
            return null;
        }
        return content.getCodeStr();
    }
    if (resFile == null || type != JResType.FILE) {
        return null;
    }
    if (!isSupportedForView(resFile.getType())) {
        return null;
    }
    ResContainer rc = resFile.loadContent();
    if (rc == null) {
        loaded = true;
        return null;
    }
    if (rc.getDataType() == ResContainer.DataType.RES_TABLE) {
        content = loadCurrentSingleRes(rc);
        for (ResContainer subFile : rc.getSubFiles()) {
            loadSubNodes(this, subFile, 1);
        }
    } else {
        // single node
        content = loadCurrentSingleRes(rc);
    }
    loaded = true;
    return content.getCodeStr();
}
Also used : ResContainer(jadx.core.xmlgen.ResContainer)

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