aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJooyung Han <jooyung@google.com>2021-07-21 01:18:21 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-07-21 01:18:21 +0000
commit76e93cc194bb00668358e1303112522f4df6f9e1 (patch)
tree30f23d8fb235eb5cbfd6945b3bca75c709ff9ba9
parent52b4ac61dce63c0dcb3553e8cb9f17465eb2765e (diff)
parent0f36b1cacc202393faecdcf021c01a602dd23cc5 (diff)
downloadapksig-76e93cc194bb00668358e1303112522f4df6f9e1.tar.gz
Add update for EOCD comment length am: 8ecf3e5d5d am: e73cdfba49 am: 4d430af0b8 am: 0f36b1cacc
Original change: https://android-review.googlesource.com/c/platform/tools/apksig/+/1762390 Change-Id: I70babd119275f9b7dd6fb5951d89d27b479f1e6d
-rw-r--r--src/main/java/com/android/apksig/apk/ApkUtils.java11
-rw-r--r--src/main/java/com/android/apksig/internal/zip/ZipUtils.java14
2 files changed, 25 insertions, 0 deletions
diff --git a/src/main/java/com/android/apksig/apk/ApkUtils.java b/src/main/java/com/android/apksig/apk/ApkUtils.java
index 426f0be..156ea17 100644
--- a/src/main/java/com/android/apksig/apk/ApkUtils.java
+++ b/src/main/java/com/android/apksig/apk/ApkUtils.java
@@ -97,6 +97,17 @@ public abstract class ApkUtils {
}
/**
+ * Updates the length of EOCD comment.
+ *
+ * @param zipEndOfCentralDirectory APK's ZIP End of Central Directory record
+ */
+ public static void updateZipEocdCommentLen(ByteBuffer zipEndOfCentralDirectory) {
+ ByteBuffer eocd = zipEndOfCentralDirectory.slice();
+ eocd.order(ByteOrder.LITTLE_ENDIAN);
+ ZipUtils.updateZipEocdCommentLen(eocd);
+ }
+
+ /**
* Returns the APK Signing Block of the provided {@code apk}.
*
* @throws ApkFormatException if the APK is not a valid ZIP archive
diff --git a/src/main/java/com/android/apksig/internal/zip/ZipUtils.java b/src/main/java/com/android/apksig/internal/zip/ZipUtils.java
index 9d9da15..1c2e82c 100644
--- a/src/main/java/com/android/apksig/internal/zip/ZipUtils.java
+++ b/src/main/java/com/android/apksig/internal/zip/ZipUtils.java
@@ -70,6 +70,20 @@ public abstract class ZipUtils {
}
/**
+ * Sets the length of EOCD comment.
+ *
+ * <p>NOTE: Byte order of {@code zipEndOfCentralDirectory} must be little-endian.
+ */
+ public static void updateZipEocdCommentLen(ByteBuffer zipEndOfCentralDirectory) {
+ assertByteOrderLittleEndian(zipEndOfCentralDirectory);
+ int commentLen = zipEndOfCentralDirectory.remaining() - ZIP_EOCD_REC_MIN_SIZE;
+ setUnsignedInt16(
+ zipEndOfCentralDirectory,
+ zipEndOfCentralDirectory.position() + ZIP_EOCD_COMMENT_LENGTH_FIELD_OFFSET,
+ commentLen);
+ }
+
+ /**
* Returns the offset of the start of the ZIP Central Directory in the archive.
*
* <p>NOTE: Byte order of {@code zipEndOfCentralDirectory} must be little-endian.