13344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian/*
23344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * Copyright (C) 2006 The Android Open Source Project
33344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian *
43344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
53344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * you may not use this file except in compliance with the License.
63344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * You may obtain a copy of the License at
73344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian *
83344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
93344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian *
103344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * Unless required by applicable law or agreed to in writing, software
113344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
123344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * See the License for the specific language governing permissions and
143344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * limitations under the License.
153344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian */
163344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
173344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian//
183344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian// Zip archive entries.
193344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian//
203344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian// The ZipEntry class is tightly meshed with the ZipFile class.
213344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian//
223344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian#ifndef __LIBS_ZIPENTRY_H
233344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian#define __LIBS_ZIPENTRY_H
243344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
253344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian#include <utils/Errors.h>
263344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
273344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian#include <stdlib.h>
2841bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen#include <stdint.h>
293344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian#include <stdio.h>
30319524ba3375959b6c5ddd553717ecd570d2ead2Mathias Agopian#include <time.h>
313344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
323344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopiannamespace android {
333344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
343344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopianclass ZipFile;
353344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
363344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian/*
373344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * ZipEntry objects represent a single entry in a Zip archive.
383344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian *
393344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * You can use one of these to get or set information about an entry, but
403344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * there are no functions here for accessing the data itself.  (We could
413344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * tuck a pointer to the ZipFile in here for convenience, but that raises
423344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * the likelihood of using ZipEntry objects after discarding the ZipFile.)
433344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian *
443344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * File information is stored in two places: next to the file data (the Local
453344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * File Header, and possibly a Data Descriptor), and at the end of the file
463344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian * (the Central Directory Entry).  The two must be kept in sync.
473344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian */
483344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopianclass ZipEntry {
493344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopianpublic:
503344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    friend class ZipFile;
513344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
523344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    ZipEntry(void)
533344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        : mDeleted(false), mMarked(false)
543344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        {}
553344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    ~ZipEntry(void) {}
563344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
573344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
583344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Returns "true" if the data is compressed.
593344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
603344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    bool isCompressed(void) const {
613344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        return mCDE.mCompressionMethod != kCompressStored;
623344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    }
633344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    int getCompressionMethod(void) const { return mCDE.mCompressionMethod; }
643344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
653344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
663344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Return the uncompressed length.
673344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
683344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    off_t getUncompressedLen(void) const { return mCDE.mUncompressedSize; }
693344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
703344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
713344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Return the compressed length.  For uncompressed data, this returns
723344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * the same thing as getUncompresesdLen().
733344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
743344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    off_t getCompressedLen(void) const { return mCDE.mCompressedSize; }
753344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
763344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
773344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Return the absolute file offset of the start of the compressed or
783344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * uncompressed data.
793344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
803344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    off_t getFileOffset(void) const {
813344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        return mCDE.mLocalHeaderRelOffset +
823344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian                LocalFileHeader::kLFHLen +
833344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian                mLFH.mFileNameLength +
843344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian                mLFH.mExtraFieldLength;
853344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    }
863344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
873344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
883344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Return the data CRC.
893344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
9041bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen    uint32_t getCRC32(void) const { return mCDE.mCRC32; }
913344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
923344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
933344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Return file modification time in UNIX seconds-since-epoch.
943344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
953344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    time_t getModWhen(void) const;
963344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
973344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
983344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Return the archived file name.
993344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
1003344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    const char* getFileName(void) const { return (const char*) mCDE.mFileName; }
1013344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
1023344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
1033344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Application-defined "mark".  Can be useful when synchronizing the
1043344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * contents of an archive with contents on disk.
1053344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
1063344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    bool getMarked(void) const { return mMarked; }
1073344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    void setMarked(bool val) { mMarked = val; }
1083344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
1093344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
1103344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Some basic functions for raw data manipulation.  "LE" means
1113344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Little Endian.
1123344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
11341bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen    static inline uint16_t getShortLE(const uint8_t* buf) {
1143344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        return buf[0] | (buf[1] << 8);
1153344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    }
11641bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen    static inline uint32_t getLongLE(const uint8_t* buf) {
1173344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
1183344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    }
11941bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen    static inline void putShortLE(uint8_t* buf, uint16_t val) {
12041bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        buf[0] = (uint8_t) val;
12141bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        buf[1] = (uint8_t) (val >> 8);
1223344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    }
12341bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen    static inline void putLongLE(uint8_t* buf, uint32_t val) {
12441bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        buf[0] = (uint8_t) val;
12541bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        buf[1] = (uint8_t) (val >> 8);
12641bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        buf[2] = (uint8_t) (val >> 16);
12741bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        buf[3] = (uint8_t) (val >> 24);
1283344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    }
1293344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
1303344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /* defined for Zip archives */
1313344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    enum {
1323344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        kCompressStored     = 0,        // no compression
1333344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        // shrunk           = 1,
1343344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        // reduced 1        = 2,
1353344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        // reduced 2        = 3,
1363344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        // reduced 3        = 4,
1373344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        // reduced 4        = 5,
1383344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        // imploded         = 6,
1393344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        // tokenized        = 7,
1403344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        kCompressDeflated   = 8,        // standard deflate
1413344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        // Deflate64        = 9,
1423344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        // lib imploded     = 10,
1433344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        // reserved         = 11,
1443344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        // bzip2            = 12,
1453344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    };
1463344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
1473344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
1483344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Deletion flag.  If set, the entry will be removed on the next
1493344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * call to "flush".
1503344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
1513344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    bool getDeleted(void) const { return mDeleted; }
1523344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
1533344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopianprotected:
1543344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
1553344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Initialize the structure from the file, which is pointing at
1563344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * our Central Directory entry.
1573344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
1583344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    status_t initFromCDE(FILE* fp);
1593344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
1603344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
1613344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Initialize the structure for a new file.  We need the filename
1623344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * and comment so that we can properly size the LFH area.  The
1633344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * filename is mandatory, the comment is optional.
1643344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
1653344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    void initNew(const char* fileName, const char* comment);
1663344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
1673344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
1683344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Initialize the structure with the contents of a ZipEntry from
1693344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * another file.
1703344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
171af1d7411825e589f09074c04bbbd80497b60e9e9Aurimas Liutikas    status_t initFromExternal(const ZipEntry* pEntry);
1723344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
1733344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
1743344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Add some pad bytes to the LFH.  We do this by adding or resizing
1753344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * the "extra" field.
1763344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
1773344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    status_t addPadding(int padding);
1783344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
1793344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
1803344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Set information about the data for this entry.
1813344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
18241bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen    void setDataInfo(long uncompLen, long compLen, uint32_t crc32,
1833344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        int compressionMethod);
1843344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
1853344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
1863344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Set the modification date.
1873344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
1883344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    void setModWhen(time_t when);
1893344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
1903344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
1913344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Return the offset of the local file header.
1923344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
1933344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    off_t getLFHOffset(void) const { return mCDE.mLocalHeaderRelOffset; }
1943344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
1953344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
1963344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Set the offset of the local file header, relative to the start of
1973344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * the current file.
1983344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
1993344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    void setLFHOffset(off_t offset) {
20041bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        mCDE.mLocalHeaderRelOffset = (uint32_t) offset;
2013344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    }
2023344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2033344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /* mark for deletion; used by ZipFile::remove() */
2043344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    void setDeleted(void) { mDeleted = true; }
2053344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2063344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopianprivate:
2073344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /* these are private and not defined */
2083344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    ZipEntry(const ZipEntry& src);
2093344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    ZipEntry& operator=(const ZipEntry& src);
2103344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2113344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /* returns "true" if the CDE and the LFH agree */
2123344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    bool compareHeaders(void) const;
2133344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    void copyCDEtoLFH(void);
2143344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2153344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    bool        mDeleted;       // set if entry is pending deletion
2163344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    bool        mMarked;        // app-defined marker
2173344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2183344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
2193344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Every entry in the Zip archive starts off with one of these.
2203344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
2213344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    class LocalFileHeader {
2223344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    public:
2233344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        LocalFileHeader(void) :
2243344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mVersionToExtract(0),
2253344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mGPBitFlag(0),
2263344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mCompressionMethod(0),
2273344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mLastModFileTime(0),
2283344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mLastModFileDate(0),
2293344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mCRC32(0),
2303344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mCompressedSize(0),
2313344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mUncompressedSize(0),
2323344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mFileNameLength(0),
2333344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mExtraFieldLength(0),
2343344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mFileName(NULL),
2353344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mExtraField(NULL)
2363344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        {}
2373344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        virtual ~LocalFileHeader(void) {
2383344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            delete[] mFileName;
2393344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            delete[] mExtraField;
2403344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        }
2413344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2423344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        status_t read(FILE* fp);
2433344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        status_t write(FILE* fp);
2443344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
24541bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        // uint32_t mSignature;
24641bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mVersionToExtract;
24741bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mGPBitFlag;
24841bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mCompressionMethod;
24941bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mLastModFileTime;
25041bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mLastModFileDate;
25141bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint32_t mCRC32;
25241bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint32_t mCompressedSize;
25341bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint32_t mUncompressedSize;
25441bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mFileNameLength;
25541bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mExtraFieldLength;
25641bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint8_t* mFileName;
25741bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint8_t* mExtraField;
2583344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2593344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        enum {
2603344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            kSignature      = 0x04034b50,
2613344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            kLFHLen         = 30,       // LocalFileHdr len, excl. var fields
2623344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        };
2633344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2643344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        void dump(void) const;
2653344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    };
2663344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
2673344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    /*
2683344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * Every entry in the Zip archive has one of these in the "central
2693344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     * directory" at the end of the file.
2703344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian     */
2713344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    class CentralDirEntry {
2723344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    public:
2733344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        CentralDirEntry(void) :
2743344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mVersionMadeBy(0),
2753344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mVersionToExtract(0),
2763344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mGPBitFlag(0),
2773344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mCompressionMethod(0),
2783344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mLastModFileTime(0),
2793344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mLastModFileDate(0),
2803344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mCRC32(0),
2813344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mCompressedSize(0),
2823344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mUncompressedSize(0),
2833344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mFileNameLength(0),
2843344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mExtraFieldLength(0),
2853344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mFileCommentLength(0),
2863344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mDiskNumberStart(0),
2873344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mInternalAttrs(0),
2883344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mExternalAttrs(0),
2893344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mLocalHeaderRelOffset(0),
2903344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mFileName(NULL),
2913344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mExtraField(NULL),
2923344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            mFileComment(NULL)
2933344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        {}
2940c38bc57624be94ffa01d0193b66506d4607c02cYing Wang        ~CentralDirEntry(void) {
2953344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            delete[] mFileName;
2963344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            delete[] mExtraField;
2973344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            delete[] mFileComment;
2983344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        }
2993344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
3003344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        status_t read(FILE* fp);
3013344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        status_t write(FILE* fp);
3023344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
30341bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        // uint32_t mSignature;
30441bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mVersionMadeBy;
30541bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mVersionToExtract;
30641bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mGPBitFlag;
30741bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mCompressionMethod;
30841bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mLastModFileTime;
30941bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mLastModFileDate;
31041bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint32_t mCRC32;
31141bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint32_t mCompressedSize;
31241bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint32_t mUncompressedSize;
31341bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mFileNameLength;
31441bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mExtraFieldLength;
31541bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mFileCommentLength;
31641bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mDiskNumberStart;
31741bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint16_t mInternalAttrs;
31841bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint32_t mExternalAttrs;
31941bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint32_t mLocalHeaderRelOffset;
32041bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint8_t* mFileName;
32141bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint8_t* mExtraField;
32241bc424c323f86806f04acd22304d4d149bc5dbeDan Willemsen        uint8_t* mFileComment;
3233344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
3243344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        void dump(void) const;
3253344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
3263344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        enum {
3273344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            kSignature      = 0x02014b50,
3283344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian            kCDELen         = 46,       // CentralDirEnt len, excl. var fields
3293344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        };
3303344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    };
3313344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
3323344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    enum {
3333344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        //kDataDescriptorSignature  = 0x08074b50,   // currently unused
3343344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        kDataDescriptorLen  = 16,           // four 32-bit fields
3353344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
3363344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        kDefaultVersion     = 20,           // need deflate, nothing much else
3373344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        kDefaultMadeBy      = 0x0317,       // 03=UNIX, 17=spec v2.3
3383344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian        kUsesDataDescr      = 0x0008,       // GPBitFlag bit 3
3393344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    };
3403344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
3413344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    LocalFileHeader     mLFH;
3423344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian    CentralDirEntry     mCDE;
3433344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian};
3443344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
3453344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian}; // namespace android
3463344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian
3473344b2e9b27466111524dfcfb64d7258153e0cb7Mathias Agopian#endif // __LIBS_ZIPENTRY_H
348