use of jadx.api.ResourceFile in project jadx by skylot.
the class TabbedPane method makeContentPanel.
@Nullable
private ContentPanel makeContentPanel(JNode node) {
if (node instanceof JResource) {
JResource res = (JResource) node;
ResourceFile resFile = res.getResFile();
if (resFile != null) {
if (resFile.getType() == ResourceType.IMG) {
return new ImagePanel(this, res);
}
} else {
return null;
}
}
return new CodePanel(this, node);
}
use of jadx.api.ResourceFile in project jadx by skylot.
the class ResourceIndex method getZipFile.
@Nullable
private ZipFile getZipFile(TreeNode res) {
for (int i = 0; i < res.getChildCount(); i++) {
TreeNode node = res.getChildAt(i);
if (node instanceof JResource) {
JResource resNode = (JResource) node;
try {
resNode.loadNode();
} catch (Exception e) {
LOG.error("Error load resource node: {}", resNode, e);
return null;
}
ResourceFile file = resNode.getResFile();
if (file == null) {
ZipFile zip = getZipFile(resNode);
if (zip != null) {
return zip;
}
} else {
ResourceFile.ZipRef zipRef = file.getZipRef();
if (zipRef != null) {
File zfile = zipRef.getZipFile();
if (FileUtils.isZipFile(zfile)) {
try {
return new ZipFile(zfile);
} catch (IOException ignore) {
}
}
}
}
}
}
return null;
}
use of jadx.api.ResourceFile in project jadx by skylot.
the class RootNode method loadResources.
public void loadResources(List<ResourceFile> resources) {
ResourceFile arsc = null;
for (ResourceFile rf : resources) {
if (rf.getType() == ResourceType.ARSC) {
arsc = rf;
break;
}
}
if (arsc == null) {
LOG.debug("'.arsc' file not found");
return;
}
try {
ResTableParser parser = ResourcesLoader.decodeStream(arsc, (size, is) -> {
ResTableParser tableParser = new ResTableParser(this);
tableParser.decode(is);
return tableParser;
});
if (parser != null) {
processResources(parser.getResStorage());
updateObfuscatedFiles(parser, resources);
}
} catch (Exception e) {
LOG.error("Failed to parse '.arsc' file", e);
}
}
use of jadx.api.ResourceFile 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.api.ResourceFile 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);
}
}
Aggregations