1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.apksig.zip; 18 19 import java.nio.ByteBuffer; 20 21 /** 22 * Base representation of an APK's zip sections containing the central directory's offset, the size 23 * of the central directory in bytes, the number of records in the central directory, the offset 24 * of the end of central directory, and a ByteBuffer containing the end of central directory 25 * contents. 26 */ 27 public class ZipSections { 28 private final long mCentralDirectoryOffset; 29 private final long mCentralDirectorySizeBytes; 30 private final int mCentralDirectoryRecordCount; 31 private final long mEocdOffset; 32 private final ByteBuffer mEocd; 33 ZipSections( long centralDirectoryOffset, long centralDirectorySizeBytes, int centralDirectoryRecordCount, long eocdOffset, ByteBuffer eocd)34 public ZipSections( 35 long centralDirectoryOffset, 36 long centralDirectorySizeBytes, 37 int centralDirectoryRecordCount, 38 long eocdOffset, 39 ByteBuffer eocd) { 40 mCentralDirectoryOffset = centralDirectoryOffset; 41 mCentralDirectorySizeBytes = centralDirectorySizeBytes; 42 mCentralDirectoryRecordCount = centralDirectoryRecordCount; 43 mEocdOffset = eocdOffset; 44 mEocd = eocd; 45 } 46 47 /** 48 * Returns the start offset of the ZIP Central Directory. This value is taken from the 49 * ZIP End of Central Directory record. 50 */ getZipCentralDirectoryOffset()51 public long getZipCentralDirectoryOffset() { 52 return mCentralDirectoryOffset; 53 } 54 55 /** 56 * Returns the size (in bytes) of the ZIP Central Directory. This value is taken from the 57 * ZIP End of Central Directory record. 58 */ getZipCentralDirectorySizeBytes()59 public long getZipCentralDirectorySizeBytes() { 60 return mCentralDirectorySizeBytes; 61 } 62 63 /** 64 * Returns the number of records in the ZIP Central Directory. This value is taken from the 65 * ZIP End of Central Directory record. 66 */ getZipCentralDirectoryRecordCount()67 public int getZipCentralDirectoryRecordCount() { 68 return mCentralDirectoryRecordCount; 69 } 70 71 /** 72 * Returns the start offset of the ZIP End of Central Directory record. The record extends 73 * until the very end of the APK. 74 */ getZipEndOfCentralDirectoryOffset()75 public long getZipEndOfCentralDirectoryOffset() { 76 return mEocdOffset; 77 } 78 79 /** 80 * Returns the contents of the ZIP End of Central Directory. 81 */ getZipEndOfCentralDirectory()82 public ByteBuffer getZipEndOfCentralDirectory() { 83 return mEocd; 84 } 85 }