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);
}
}
}
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);
}
}
}
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;
}
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;
}
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());
}
Aggregations