private void addEntry(List<ResourceFile> list, File zipFile, ZipEntry entry) { if (entry.isDirectory()) { return; } String name = entry.getName(); ResourceType type = ResourceType.getFileType(name); ResourceFile rf = ResourceFile.createResourceFile(jadxRef, name, type); if (rf != null) { rf.setZipRef(new ZipRef(zipFile, name)); list.add(rf); } }
@Override public String getContent() { try { ResourceFile.ZipRef zipRef = rf.getZipRef(); if (zipRef == null) { File file = new File(rf.getName()); try (InputStream inputStream = new BufferedInputStream(new FileInputStream(file))) { return CertificateManager.decode(inputStream); } } else { try (ZipFile zipFile = new ZipFile(zipRef.getZipFile())) { ZipEntry entry = zipFile.getEntry(zipRef.getEntryName()); if (entry == null) { throw new IOException("Zip entry not found: " + zipRef); } if (!ZipSecurity.isValidZipEntry(entry)) { return null; } try (InputStream inputStream = new BufferedInputStream(zipFile.getInputStream(entry))) { return CertificateManager.decode(inputStream); } } } } catch (Exception e) { LOG.error("Certificate decode error: {}", rf.getName(), e); return "Decode error: " + e.getMessage(); } } }
public static <T> T decodeStream(ResourceFile rf, ResourceDecoder<T> decoder) throws JadxException { try { ZipRef zipRef = rf.getZipRef(); if (zipRef == null) { File file = new File(rf.getName()); try (InputStream inputStream = new BufferedInputStream(new FileInputStream(file))) { return decoder.decode(file.length(), inputStream); } } else { try (ZipFile zipFile = new ZipFile(zipRef.getZipFile())) { ZipEntry entry = zipFile.getEntry(zipRef.getEntryName()); if (entry == null) { throw new IOException("Zip entry not found: " + zipRef); } if (!ZipSecurity.isValidZipEntry(entry)) { return null; } try (InputStream inputStream = new BufferedInputStream(zipFile.getInputStream(entry))) { return decoder.decode(entry.getSize(), inputStream); } } } } catch (Exception e) { throw new JadxException("Error decode: " + rf.getName(), e); } }