@Override public Icon getIcon() { switch (type) { case ROOT: return ROOT_ICON; case DIR: return FOLDER_ICON; case FILE: ResourceType resType = resFile.getType(); if (resType == ResourceType.MANIFEST) { return MANIFEST_ICON; } if (resType == ResourceType.CODE) { return new OverlayIcon(FILE_ICON, ERROR_ICON, JAVA_ICON); } if (!isSupportedForView(resType)) { return new OverlayIcon(FILE_ICON, ERROR_ICON); } return FILE_ICON; } return FILE_ICON; }
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 { ResourceStorage resStorage = ResourcesLoader.decodeStream(arsc, (size, is) -> { ResTableParser parser = new ResTableParser(); parser.decode(is); return parser.getResStorage(); }); processResources(resStorage); } catch (Exception e) { LOG.error("Failed to parse '.arsc' file", e); } }
@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; } } if (node instanceof ApkSignature) { return new HtmlPanel(this, node); } if (node instanceof JCertificate) { return new CertificatePanel(this, node); } return new CodePanel(this, node); }
@Override public String getSyntaxName() { if (resFile == null) { return null; } switch (resFile.getType()) { case CODE: return super.getSyntaxName(); case MANIFEST: case XML: return SyntaxConstants.SYNTAX_STYLE_XML; default: String syntax = getSyntaxByExtension(resFile.getName()); if (syntax != null) { return syntax; } return super.getSyntaxName(); } }
public final void update() { if (files.isEmpty()) { if (type == JResType.DIR || type == JResType.ROOT || resFile.getType() == ResourceType.ARSC) { // fake leaf to force show expand button // real sub nodes will load on expand in loadNode() method add(new TextNode(NLS.str("tree.loading"))); } } else { removeAllChildren(); for (JResource res : files) { res.update(); add(res); } } }
static ResContainer loadContent(JadxDecompiler jadxRef, ResourceFile rf) { try { return decodeStream(rf, (size, is) -> loadContent(jadxRef, rf, is)); } catch (JadxException e) { LOG.error("Decode error", e); CodeWriter cw = new CodeWriter(); cw.add("Error decode ").add(rf.getType().toString().toLowerCase()); cw.startLine(Utils.getStackTrace(e.getCause())); return ResContainer.textResource(rf.getName(), cw); } }
private static ResContainer loadContent(JadxDecompiler jadxRef, ResourceFile rf, InputStream inputStream) throws IOException { switch (rf.getType()) { case MANIFEST: case XML: CodeWriter content = jadxRef.getXmlParser().parse(inputStream); return ResContainer.textResource(rf.getName(), content); case ARSC: return new ResTableParser().decodeFiles(inputStream); case IMG: return decodeImage(rf, inputStream); default: return ResContainer.resourceFileLink(rf); } }
private void treeClickAction() { try { Object obj = tree.getLastSelectedPathComponent(); if (obj == null) { return; } 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 JCertificate) || (obj instanceof ApkSignature)) { tabbedPane.showSimpleNode((JNode) obj); } else if (obj instanceof JNode) { JNode node = (JNode) obj; JClass cls = node.getRootClass(); if (cls != null) { tabbedPane.codeJump(new JumpPosition(cls, node.getLine())); } } } catch (Exception e) { LOG.error("Content loading error", e); } }
@Override public synchronized String getContent() { if (loaded) { return content; } if (resFile == null || type != JResType.FILE) { return null; } if (!isSupportedForView(resFile.getType())) { return null; } ResContainer rc = resFile.loadContent(); if (rc == null) { return null; } if (rc.getDataType() == ResContainer.DataType.RES_TABLE) { content = loadCurrentSingleRes(rc); for (ResContainer subFile : rc.getSubFiles()) { loadSubNodes(this, subFile, 1); } loaded = true; return content; } // single node return loadCurrentSingleRes(rc); }