Search in sources :

Example 1 with CodeWriter

use of jadx.core.codegen.CodeWriter 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 CodeWriter

use of jadx.core.codegen.CodeWriter in project jadx by skylot.

the class DebugUtils method printInsns.

private static void printInsns(MethodNode mth, String indent, IBlock block) {
    for (InsnNode insn : block.getInstructions()) {
        try {
            MethodGen mg = MethodGen.getFallbackMethodGen(mth);
            InsnGen ig = new InsnGen(mg, true);
            CodeWriter code = new CodeWriter();
            ig.makeInsn(insn, code);
            String insnStr = code.toString().substring(CodeWriter.NL.length());
            LOG.debug("{} - {}", indent, insnStr);
        } catch (CodegenException e) {
            LOG.debug("{} - {}", indent, insn);
        }
    }
}
Also used : InsnNode(jadx.core.dex.nodes.InsnNode) InsnGen(jadx.core.codegen.InsnGen) CodegenException(jadx.core.utils.exceptions.CodegenException) CodeWriter(jadx.core.codegen.CodeWriter) MethodGen(jadx.core.codegen.MethodGen)

Example 3 with CodeWriter

use of jadx.core.codegen.CodeWriter in project jadx by skylot.

the class ResTableParser method makeDump.

public CodeWriter makeDump() throws IOException {
    CodeWriter writer = new CodeWriter();
    writer.add("app package: ").add(resStorage.getAppPackage());
    writer.startLine();
    ValuesParser vp = new ValuesParser(strings, resStorage.getResourcesNames());
    for (ResourceEntry ri : resStorage.getResources()) {
        writer.startLine(ri + ": " + vp.getValueString(ri));
    }
    writer.finish();
    return writer;
}
Also used : ResourceEntry(jadx.core.xmlgen.entry.ResourceEntry) ValuesParser(jadx.core.xmlgen.entry.ValuesParser) CodeWriter(jadx.core.codegen.CodeWriter)

Example 4 with CodeWriter

use of jadx.core.codegen.CodeWriter in project jadx by skylot.

the class ResXmlGen method makeResourcesXml.

public List<ResContainer> makeResourcesXml() {
    Map<String, CodeWriter> contMap = new HashMap<String, CodeWriter>();
    for (ResourceEntry ri : resStorage.getResources()) {
        if (SKIP_RES_TYPES.contains(ri.getTypeName())) {
            continue;
        }
        String fn = getFileName(ri);
        CodeWriter cw = contMap.get(fn);
        if (cw == null) {
            cw = new CodeWriter();
            cw.add("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            cw.startLine("<resources>");
            cw.incIndent();
            contMap.put(fn, cw);
        }
        addValue(cw, ri);
    }
    List<ResContainer> files = new ArrayList<ResContainer>(contMap.size());
    for (Map.Entry<String, CodeWriter> entry : contMap.entrySet()) {
        String fileName = entry.getKey();
        CodeWriter content = entry.getValue();
        content.decIndent();
        content.startLine("</resources>");
        content.finish();
        files.add(ResContainer.singleFile(fileName, content));
    }
    Collections.sort(files);
    return files;
}
Also used : HashMap(java.util.HashMap) ResourceEntry(jadx.core.xmlgen.entry.ResourceEntry) ArrayList(java.util.ArrayList) CodeWriter(jadx.core.codegen.CodeWriter) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with CodeWriter

use of jadx.core.codegen.CodeWriter in project jadx by skylot.

the class ResourcesSaver method save.

private void save(ResContainer rc, File outDir) {
    File outFile = new File(outDir, rc.getFileName());
    BufferedImage image = rc.getImage();
    if (image != null) {
        String ext = FilenameUtils.getExtension(outFile.getName());
        try {
            outFile = prepareFile(outFile);
            ImageIO.write(image, ext, outFile);
        } catch (IOException e) {
            LOG.error("Failed to save image: {}", rc.getName(), e);
        }
        return;
    }
    CodeWriter cw = rc.getContent();
    if (cw != null) {
        cw.save(outFile);
        return;
    }
    LOG.warn("Resource '{}' not saved, unknown type", rc.getName());
}
Also used : IOException(java.io.IOException) ResourceFile(jadx.api.ResourceFile) FileUtils.prepareFile(jadx.core.utils.files.FileUtils.prepareFile) File(java.io.File) CodeWriter(jadx.core.codegen.CodeWriter) BufferedImage(java.awt.image.BufferedImage)

Aggregations

CodeWriter (jadx.core.codegen.CodeWriter)11 ClassNode (jadx.core.dex.nodes.ClassNode)2 ResourceEntry (jadx.core.xmlgen.entry.ResourceEntry)2 IntegrationTest (jadx.tests.api.IntegrationTest)2 Test (org.junit.Test)2 ResourceFile (jadx.api.ResourceFile)1 ResourceFileContent (jadx.api.ResourceFileContent)1 InsnGen (jadx.core.codegen.InsnGen)1 MethodGen (jadx.core.codegen.MethodGen)1 InsnNode (jadx.core.dex.nodes.InsnNode)1 MethodNode (jadx.core.dex.nodes.MethodNode)1 CodegenException (jadx.core.utils.exceptions.CodegenException)1 FileUtils.prepareFile (jadx.core.utils.files.FileUtils.prepareFile)1 ResContainer (jadx.core.xmlgen.ResContainer)1 ValuesParser (jadx.core.xmlgen.entry.ValuesParser)1 BufferedImage (java.awt.image.BufferedImage)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1