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