public static String getZipEntryCrc(File file, String entryName) { ZipFile zipFile = null; try { zipFile = new ZipFile(file); ZipEntry entry = zipFile.getEntry(entryName); if (entry == null) { return null; } return String.valueOf(entry.getCrc()); } catch (IOException e) { e.printStackTrace(); } finally { if (zipFile != null) { try { zipFile.close(); } catch (IOException e) { e.printStackTrace(); } } } return null; }
if (!zipEntry.isDirectory()) { String key = zipEntry.getName(); String value = zipEntry.getCrc() + Constant.Symbol.DOT + zipEntry.getSize(); map.put(key, value);
String zipEntryName = zipEntry.getName(); String oldZipEntryHash = map.get(zipEntryName); String newZipEntryHash = zipEntry.getCrc() + Constant.Symbol.DOT + zipEntry.getSize();
if (!zipEntry.isDirectory()) { String key = zipEntry.getName(); String value = zipEntry.getCrc() + Constant.Symbol.DOT + zipEntry.getSize(); map.put(key, value);
private void copyAllButClassesDexAndSigFiles(ZipFile source, ZipOutputStream destination) throws IOException { Enumeration<? extends ZipEntry> sourceEntries = source.entries(); while (sourceEntries.hasMoreElements()) { ZipEntry sourceEntry = sourceEntries.nextElement(); String sourceEntryName = sourceEntry.getName(); if (sourceEntryName.endsWith(".dex") || isSignatureFile(sourceEntryName)) { continue; } // separate ZipEntry avoids compression problems due to encodings ZipEntry destinationEntry = new ZipEntry(sourceEntryName); // use the same compression method as the original (certain files // are stored, not compressed) destinationEntry.setMethod(sourceEntry.getMethod()); // copy other necessary fields for STORE method destinationEntry.setSize(sourceEntry.getSize()); destinationEntry.setCrc(sourceEntry.getCrc()); // finally craft new entry destination.putNextEntry(destinationEntry); InputStream zipEntryInput = source.getInputStream(sourceEntry); byte[] buffer = new byte[2048]; int bytesRead = zipEntryInput.read(buffer); while (bytesRead > 0) { destination.write(buffer, 0, bytesRead); bytesRead = zipEntryInput.read(buffer); } zipEntryInput.close(); } }
String zipEntryName = zipEntry.getName(); String oldZipEntryHash = map.get(zipEntryName); String newZipEntryHash = zipEntry.getCrc() + Constant.Symbol.DOT + zipEntry.getSize();
boolean getEntryInfo(org.robolectric.res.android.ZipFileRO.ZipEntryRO entry, Ref<Short> pMethod, final Ref<Long> pUncompLen, Ref<Long> pCompLen, Ref<Long> pOffset, final Ref<Long> pModWhen, Ref<Long> pCrc32) { final ZipEntryRO zipEntry = /*reinterpret_cast<ZipEntryRO*>*/(entry); final ZipEntry ze = zipEntry.entry; if (pMethod != null) { pMethod.set((short) ze.getMethod()); } if (pUncompLen != null) { pUncompLen.set(ze.getSize()); // uncompressed_length } if (pCompLen != null) { pCompLen.set(ze.getCompressedSize()); } if (pOffset != null) { throw new UnsupportedOperationException("Figure out offset"); // pOffset = ze.offset; } if (pModWhen != null) { // todo pModWhen.set(ze.getLastModifiedTime().toMillis()); } if (pCrc32 != null) { pCrc32.set(ze.getCrc()); } return true; }
/** * Copy entry with another name. * * @param original - zipEntry to copy * @param newName - new entry name, optional, if null, ogirinal's entry * @return copy of the original entry, but with the given name */ static ZipEntry copy(ZipEntry original, String newName) { ZipEntry copy = new ZipEntry(newName == null ? original.getName() : newName); if (original.getCrc() != -1) { copy.setCrc(original.getCrc()); } if (original.getMethod() != -1) { copy.setMethod(original.getMethod()); } if (original.getSize() >= 0) { copy.setSize(original.getSize()); } if (original.getExtra() != null) { copy.setExtra(original.getExtra()); } copy.setComment(original.getComment()); copy.setTime(original.getTime()); return copy; }
outputEntry.setCrc(inputEntry.getCrc()); outputEntry.setSize(inputEntry.getSize());
String baseArscCrc = String.valueOf(arscEntry.getCrc()); if (!baseArscCrc.equals(resPatchInfo.arscBaseCrc)) { TinkerLog.e(TAG, "resources.arsc's crc is not equal, expect crc: %s, got crc: %s", resPatchInfo.arscBaseCrc, baseArscCrc);
String rawEntryCrc = String.valueOf(rawApkFileEntry.getCrc()); if (!rawEntryCrc.equals(rawApkCrc)) { TinkerLog.e(TAG, "apk entry %s crc is not equal, expect crc: %s, got crc: %s", patchRealPath, rawApkCrc, rawEntryCrc);
private static ArrayMemory zipEntryToArray(ZipEntry zipEntry) { final ArrayMemory result = new ArrayMemory(); result.refOfIndex("name").assign(zipEntry.getName()); result.refOfIndex("crc").assign(zipEntry.getCrc()); result.refOfIndex("size").assign(zipEntry.getSize()); result.refOfIndex("compressedSize").assign(zipEntry.getCompressedSize()); result.refOfIndex("time").assign(zipEntry.getTime()); result.refOfIndex("method").assign(zipEntry.getMethod()); result.refOfIndex("comment").assign(zipEntry.getComment()); result.refOfIndex("directory").assign(zipEntry.isDirectory()); return result; }
String rawEntryCrc = String.valueOf(rawApkFileEntry.getCrc()); if (!rawEntryCrc.equals(oldDexCrc)) { TinkerLog.e(TAG, "apk entry %s crc is not equal, expect crc: %s, got crc: %s", patchRealPath, oldDexCrc, rawEntryCrc); String rawEntryCrc = String.valueOf(rawApkFileEntry.getCrc()); if (!rawEntryCrc.equals(oldDexCrc)) { TinkerLog.e(TAG, "apk entry %s crc is not equal, expect crc: %s, got crc: %s", patchRealPath, oldDexCrc, rawEntryCrc);
ze.setSize(ze.getCompressedSize()); if (ze.getCrc() == -1) { throw new ZipException("STORED entry missing CRC");
/*************ZIP file operation***************/ public static boolean readZipFile(String zipFileName, StringBuffer crc) { try { ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFileName)); ZipEntry entry; while ((entry = zis.getNextEntry()) != null) { long size = entry.getSize(); crc.append(entry.getCrc() + ", size: " + size); } zis.close(); } catch (Exception ex) { Log.i(TAG,"Exception: " + ex.toString()); return false; } return true; }
public static Map<String, Long> getCheckSums(String archiveFile) throws IOException { Map<String, Long> checkSums = new HashMap<String, Long>(); ZipFile zipFile = new ZipFile(archiveFile); Enumeration<? extends ZipEntry> e = zipFile.entries(); while (e.hasMoreElements()) { ZipEntry entry = e.nextElement(); checkSums.put(entry.getName(), entry.getCrc()); } return checkSums; }
public static Map<String, Long> getCheckSums(String archiveFile) throws IOException { Map<String, Long> checkSums = new HashMap<String, Long>(); ZipFile zipFile = new ZipFile(archiveFile); Enumeration<? extends ZipEntry> e = zipFile.entries(); while (e.hasMoreElements()) { ZipEntry entry = e.nextElement(); checkSums.put(entry.getName(), entry.getCrc()); } return checkSums; }
private void writeEXT(ZipEntry e) throws IOException { writeInt(EXTSIG); // EXT header signature writeInt(e.getCrc()); // crc-32 writeInt(e.getCompressedSize()); // compressed size writeInt(e.getSize()); // uncompressed size }
public ZipEntryMatrix(ZipFile zipFile, ZipEntry zipEntry) { this.zipFile = zipFile; this.zipEntry = zipEntry; setLabel(zipEntry.getName()); setMetaData("CompressedSize", zipEntry.getCompressedSize()); setMetaData("CRC", zipEntry.getCrc()); setMetaData("Method", zipEntry.getMethod()); setMetaData("Size", zipEntry.getSize()); setMetaData("Time", zipEntry.getTime()); setMetaData("IsDirectory", zipEntry.isDirectory()); setMetaData("Comment", zipEntry.getComment()); }