• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.internal.zip;
18 
19 import java.nio.ByteBuffer;
20 import java.nio.ByteOrder;
21 
22 /**
23  * ZIP End of Central Directory record.
24  */
25 public class EocdRecord {
26     private static final int CD_RECORD_COUNT_ON_DISK_OFFSET = 8;
27     private static final int CD_RECORD_COUNT_TOTAL_OFFSET = 10;
28     private static final int CD_SIZE_OFFSET = 12;
29     private static final int CD_OFFSET_OFFSET = 16;
30 
createWithModifiedCentralDirectoryInfo( ByteBuffer original, int centralDirectoryRecordCount, long centralDirectorySizeBytes, long centralDirectoryOffset)31     public static ByteBuffer createWithModifiedCentralDirectoryInfo(
32             ByteBuffer original,
33             int centralDirectoryRecordCount,
34             long centralDirectorySizeBytes,
35             long centralDirectoryOffset) {
36         ByteBuffer result = ByteBuffer.allocate(original.remaining());
37         result.order(ByteOrder.LITTLE_ENDIAN);
38         result.put(original.slice());
39         result.flip();
40         ZipUtils.setUnsignedInt16(
41                 result, CD_RECORD_COUNT_ON_DISK_OFFSET, centralDirectoryRecordCount);
42         ZipUtils.setUnsignedInt16(
43                 result, CD_RECORD_COUNT_TOTAL_OFFSET, centralDirectoryRecordCount);
44         ZipUtils.setUnsignedInt32(result, CD_SIZE_OFFSET, centralDirectorySizeBytes);
45         ZipUtils.setUnsignedInt32(result, CD_OFFSET_OFFSET, centralDirectoryOffset);
46         return result;
47     }
48 }
49