use of jadx.api.ResourceFile in project jadx by skylot.
the class MainWindow method treeClickAction.
private void treeClickAction() {
try {
Object obj = tree.getLastSelectedPathComponent();
if (obj instanceof JResource) {
JResource res = (JResource) obj;
ResourceFile resFile = res.getResFile();
if (resFile != null && JResource.isSupportedForView(resFile.getType())) {
tabbedPane.showResource(res);
}
} else if (obj instanceof JNode) {
JNode node = (JNode) obj;
JClass cls = node.getRootClass();
if (cls != null) {
tabbedPane.codeJump(new Position(cls, node.getLine()));
}
}
} catch (Exception e) {
LOG.error("Content loading error", e);
}
}
use of jadx.api.ResourceFile in project jadx by skylot.
the class ResourceIndex method traverseTree.
private void traverseTree(TreeNode root, @Nullable ZipFile zip) {
for (int i = 0; i < root.getChildCount(); i++) {
TreeNode node = root.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;
}
ResourceFile resFile = resNode.getResFile();
if (resFile == null) {
traverseTree(node, zip);
} else {
if (resFile.getType() == ResourceType.ARSC && shouldSearchXML()) {
resFile.loadContent();
resNode.getFiles().forEach(t -> traverseTree(t, null));
} else {
filter(resNode, zip);
}
}
}
}
}
use of jadx.api.ResourceFile in project jadx by skylot.
the class MainWindow method nodeClickAction.
private boolean nodeClickAction(@Nullable Object obj) {
if (obj == null) {
return false;
}
try {
if (obj instanceof JResource) {
JResource res = (JResource) obj;
ResourceFile resFile = res.getResFile();
if (resFile != null && JResource.isSupportedForView(resFile.getType())) {
return tabbedPane.showNode(res);
}
} else if (obj instanceof JNode) {
JNode node = (JNode) obj;
if (node.getRootClass() != null) {
tabbedPane.codeJump(new JumpPosition(node));
return true;
}
return tabbedPane.showNode(node);
}
} catch (Exception e) {
LOG.error("Content loading error", e);
}
return false;
}
use of jadx.api.ResourceFile in project jadx by skylot.
the class JRoot method getHierarchyResources.
private JResource getHierarchyResources(List<ResourceFile> resources) {
JResource root = new JResource(null, NLS.str("tree.resources_title"), JResType.ROOT);
String splitPathStr = Pattern.quote(File.separator);
for (ResourceFile rf : resources) {
String rfName;
if (rf.getZipRef() != null) {
rfName = rf.getDeobfName();
} else {
rfName = new File(rf.getDeobfName()).getName();
}
String[] parts = new File(rfName).getPath().split(splitPathStr);
JResource curRf = root;
int count = parts.length;
for (int i = 0; i < count; i++) {
String name = parts[i];
JResource subRF = getResourceByName(curRf, name);
if (subRF == null) {
if (i != count - 1) {
subRF = new JResource(null, name, JResType.DIR);
} else {
subRF = new JResource(rf, rf.getOriginalName(), name, JResType.FILE);
}
curRf.getFiles().add(subRF);
}
curRf = subRF;
}
}
root.update();
return root;
}
use of jadx.api.ResourceFile in project jadx by skylot.
the class ResourcesSaver method saveToFile.
private void saveToFile(ResContainer rc, File outFile) {
switch(rc.getDataType()) {
case TEXT:
case RES_TABLE:
SaveCode.save(rc.getText(), outFile);
return;
case DECODED_DATA:
byte[] data = rc.getDecodedData();
FileUtils.makeDirsForFile(outFile);
try {
Files.write(outFile.toPath(), data);
} catch (Exception e) {
LOG.warn("Resource '{}' not saved, got exception", rc.getName(), e);
}
return;
case RES_LINK:
ResourceFile resFile = rc.getResLink();
FileUtils.makeDirsForFile(outFile);
try {
saveResourceFile(resFile, outFile);
} catch (Exception e) {
LOG.warn("Resource '{}' not saved, got exception", rc.getName(), e);
}
return;
default:
LOG.warn("Resource '{}' not saved, unknown type", rc.getName());
break;
}
}
Aggregations