Merge "Use explicitly sized types in zipalign/ziptime"
This commit is contained in:
commit
1b2685137e
8 changed files with 144 additions and 136 deletions
|
@ -26,6 +26,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
using namespace android;
|
||||
|
||||
|
@ -56,7 +57,7 @@ status_t ZipEntry::initFromCDE(FILE* fp)
|
|||
/* using the info in the CDE, go load up the LFH */
|
||||
posn = ftell(fp);
|
||||
if (fseek(fp, mCDE.mLocalHeaderRelOffset, SEEK_SET) != 0) {
|
||||
ALOGD("local header seek failed (%ld)\n",
|
||||
ALOGD("local header seek failed (%" PRIu32 ")\n",
|
||||
mCDE.mLocalHeaderRelOffset);
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
|
@ -123,12 +124,12 @@ void ZipEntry::initNew(const char* fileName, const char* comment)
|
|||
mCDE.mExternalAttrs = 0x81b60020; // matches what WinZip does
|
||||
|
||||
if (mCDE.mFileNameLength > 0) {
|
||||
mCDE.mFileName = new unsigned char[mCDE.mFileNameLength+1];
|
||||
mCDE.mFileName = new uint8_t[mCDE.mFileNameLength+1];
|
||||
strcpy((char*) mCDE.mFileName, fileName);
|
||||
}
|
||||
if (mCDE.mFileCommentLength > 0) {
|
||||
/* TODO: stop assuming null-terminated ASCII here? */
|
||||
mCDE.mFileComment = new unsigned char[mCDE.mFileCommentLength+1];
|
||||
mCDE.mFileComment = new uint8_t[mCDE.mFileCommentLength+1];
|
||||
strcpy((char*) mCDE.mFileComment, comment);
|
||||
}
|
||||
|
||||
|
@ -150,20 +151,20 @@ status_t ZipEntry::initFromExternal(const ZipFile* pZipFile,
|
|||
memcpy(&mCDE, &pEntry->mCDE, sizeof(mCDE));
|
||||
|
||||
if (mCDE.mFileNameLength > 0) {
|
||||
mCDE.mFileName = new unsigned char[mCDE.mFileNameLength+1];
|
||||
mCDE.mFileName = new uint8_t[mCDE.mFileNameLength+1];
|
||||
if (mCDE.mFileName == NULL)
|
||||
return NO_MEMORY;
|
||||
strcpy((char*) mCDE.mFileName, (char*)pEntry->mCDE.mFileName);
|
||||
}
|
||||
if (mCDE.mFileCommentLength > 0) {
|
||||
mCDE.mFileComment = new unsigned char[mCDE.mFileCommentLength+1];
|
||||
mCDE.mFileComment = new uint8_t[mCDE.mFileCommentLength+1];
|
||||
if (mCDE.mFileComment == NULL)
|
||||
return NO_MEMORY;
|
||||
strcpy((char*) mCDE.mFileComment, (char*)pEntry->mCDE.mFileComment);
|
||||
}
|
||||
if (mCDE.mExtraFieldLength > 0) {
|
||||
/* we null-terminate this, though it may not be a string */
|
||||
mCDE.mExtraField = new unsigned char[mCDE.mExtraFieldLength+1];
|
||||
mCDE.mExtraField = new uint8_t[mCDE.mExtraFieldLength+1];
|
||||
if (mCDE.mExtraField == NULL)
|
||||
return NO_MEMORY;
|
||||
memcpy(mCDE.mExtraField, pEntry->mCDE.mExtraField,
|
||||
|
@ -180,7 +181,7 @@ status_t ZipEntry::initFromExternal(const ZipFile* pZipFile,
|
|||
assert(mLFH.mExtraField == NULL);
|
||||
mLFH.mExtraFieldLength = pEntry->mLFH.mExtraFieldLength;
|
||||
if (mLFH.mExtraFieldLength > 0) {
|
||||
mLFH.mExtraField = new unsigned char[mLFH.mExtraFieldLength+1];
|
||||
mLFH.mExtraField = new uint8_t[mLFH.mExtraFieldLength+1];
|
||||
if (mLFH.mExtraField == NULL)
|
||||
return NO_MEMORY;
|
||||
memcpy(mLFH.mExtraField, pEntry->mLFH.mExtraField,
|
||||
|
@ -205,9 +206,9 @@ status_t ZipEntry::addPadding(int padding)
|
|||
|
||||
if (mLFH.mExtraFieldLength > 0) {
|
||||
/* extend existing field */
|
||||
unsigned char* newExtra;
|
||||
uint8_t* newExtra;
|
||||
|
||||
newExtra = new unsigned char[mLFH.mExtraFieldLength + padding];
|
||||
newExtra = new uint8_t[mLFH.mExtraFieldLength + padding];
|
||||
if (newExtra == NULL)
|
||||
return NO_MEMORY;
|
||||
memset(newExtra + mLFH.mExtraFieldLength, 0, padding);
|
||||
|
@ -218,7 +219,7 @@ status_t ZipEntry::addPadding(int padding)
|
|||
mLFH.mExtraFieldLength += padding;
|
||||
} else {
|
||||
/* create new field */
|
||||
mLFH.mExtraField = new unsigned char[padding];
|
||||
mLFH.mExtraField = new uint8_t[padding];
|
||||
memset(mLFH.mExtraField, 0, padding);
|
||||
mLFH.mExtraFieldLength = padding;
|
||||
}
|
||||
|
@ -246,7 +247,7 @@ void ZipEntry::copyCDEtoLFH(void)
|
|||
|
||||
delete[] mLFH.mFileName;
|
||||
if (mLFH.mFileNameLength > 0) {
|
||||
mLFH.mFileName = new unsigned char[mLFH.mFileNameLength+1];
|
||||
mLFH.mFileName = new uint8_t[mLFH.mFileNameLength+1];
|
||||
strcpy((char*) mLFH.mFileName, (const char*) mCDE.mFileName);
|
||||
} else {
|
||||
mLFH.mFileName = NULL;
|
||||
|
@ -256,7 +257,7 @@ void ZipEntry::copyCDEtoLFH(void)
|
|||
/*
|
||||
* Set some information about a file after we add it.
|
||||
*/
|
||||
void ZipEntry::setDataInfo(long uncompLen, long compLen, unsigned long crc32,
|
||||
void ZipEntry::setDataInfo(long uncompLen, long compLen, uint32_t crc32,
|
||||
int compressionMethod)
|
||||
{
|
||||
mCDE.mCompressionMethod = compressionMethod;
|
||||
|
@ -360,7 +361,7 @@ void ZipEntry::setModWhen(time_t when)
|
|||
struct tm tmResult;
|
||||
#endif
|
||||
time_t even;
|
||||
unsigned short zdate, ztime;
|
||||
uint16_t zdate, ztime;
|
||||
|
||||
struct tm* ptm;
|
||||
|
||||
|
@ -402,7 +403,7 @@ void ZipEntry::setModWhen(time_t when)
|
|||
status_t ZipEntry::LocalFileHeader::read(FILE* fp)
|
||||
{
|
||||
status_t result = NO_ERROR;
|
||||
unsigned char buf[kLFHLen];
|
||||
uint8_t buf[kLFHLen];
|
||||
|
||||
assert(mFileName == NULL);
|
||||
assert(mExtraField == NULL);
|
||||
|
@ -433,7 +434,7 @@ status_t ZipEntry::LocalFileHeader::read(FILE* fp)
|
|||
|
||||
/* grab filename */
|
||||
if (mFileNameLength != 0) {
|
||||
mFileName = new unsigned char[mFileNameLength+1];
|
||||
mFileName = new uint8_t[mFileNameLength+1];
|
||||
if (mFileName == NULL) {
|
||||
result = NO_MEMORY;
|
||||
goto bail;
|
||||
|
@ -447,7 +448,7 @@ status_t ZipEntry::LocalFileHeader::read(FILE* fp)
|
|||
|
||||
/* grab extra field */
|
||||
if (mExtraFieldLength != 0) {
|
||||
mExtraField = new unsigned char[mExtraFieldLength+1];
|
||||
mExtraField = new uint8_t[mExtraFieldLength+1];
|
||||
if (mExtraField == NULL) {
|
||||
result = NO_MEMORY;
|
||||
goto bail;
|
||||
|
@ -468,7 +469,7 @@ bail:
|
|||
*/
|
||||
status_t ZipEntry::LocalFileHeader::write(FILE* fp)
|
||||
{
|
||||
unsigned char buf[kLFHLen];
|
||||
uint8_t buf[kLFHLen];
|
||||
|
||||
ZipEntry::putLongLE(&buf[0x00], kSignature);
|
||||
ZipEntry::putShortLE(&buf[0x04], mVersionToExtract);
|
||||
|
@ -507,13 +508,13 @@ status_t ZipEntry::LocalFileHeader::write(FILE* fp)
|
|||
void ZipEntry::LocalFileHeader::dump(void) const
|
||||
{
|
||||
ALOGD(" LocalFileHeader contents:\n");
|
||||
ALOGD(" versToExt=%u gpBits=0x%04x compression=%u\n",
|
||||
ALOGD(" versToExt=%" PRIu16 " gpBits=0x%04" PRIx16 " compression=%" PRIu16 "\n",
|
||||
mVersionToExtract, mGPBitFlag, mCompressionMethod);
|
||||
ALOGD(" modTime=0x%04x modDate=0x%04x crc32=0x%08lx\n",
|
||||
ALOGD(" modTime=0x%04" PRIx16 " modDate=0x%04" PRIx16 " crc32=0x%08" PRIx32 "\n",
|
||||
mLastModFileTime, mLastModFileDate, mCRC32);
|
||||
ALOGD(" compressedSize=%lu uncompressedSize=%lu\n",
|
||||
ALOGD(" compressedSize=%" PRIu32 " uncompressedSize=%" PRIu32 "\n",
|
||||
mCompressedSize, mUncompressedSize);
|
||||
ALOGD(" filenameLen=%u extraLen=%u\n",
|
||||
ALOGD(" filenameLen=%" PRIu16 " extraLen=%" PRIu16 "\n",
|
||||
mFileNameLength, mExtraFieldLength);
|
||||
if (mFileName != NULL)
|
||||
ALOGD(" filename: '%s'\n", mFileName);
|
||||
|
@ -536,7 +537,7 @@ void ZipEntry::LocalFileHeader::dump(void) const
|
|||
status_t ZipEntry::CentralDirEntry::read(FILE* fp)
|
||||
{
|
||||
status_t result = NO_ERROR;
|
||||
unsigned char buf[kCDELen];
|
||||
uint8_t buf[kCDELen];
|
||||
|
||||
/* no re-use */
|
||||
assert(mFileName == NULL);
|
||||
|
@ -575,7 +576,7 @@ status_t ZipEntry::CentralDirEntry::read(FILE* fp)
|
|||
|
||||
/* grab filename */
|
||||
if (mFileNameLength != 0) {
|
||||
mFileName = new unsigned char[mFileNameLength+1];
|
||||
mFileName = new uint8_t[mFileNameLength+1];
|
||||
if (mFileName == NULL) {
|
||||
result = NO_MEMORY;
|
||||
goto bail;
|
||||
|
@ -589,7 +590,7 @@ status_t ZipEntry::CentralDirEntry::read(FILE* fp)
|
|||
|
||||
/* read "extra field" */
|
||||
if (mExtraFieldLength != 0) {
|
||||
mExtraField = new unsigned char[mExtraFieldLength+1];
|
||||
mExtraField = new uint8_t[mExtraFieldLength+1];
|
||||
if (mExtraField == NULL) {
|
||||
result = NO_MEMORY;
|
||||
goto bail;
|
||||
|
@ -604,7 +605,7 @@ status_t ZipEntry::CentralDirEntry::read(FILE* fp)
|
|||
|
||||
/* grab comment, if any */
|
||||
if (mFileCommentLength != 0) {
|
||||
mFileComment = new unsigned char[mFileCommentLength+1];
|
||||
mFileComment = new uint8_t[mFileCommentLength+1];
|
||||
if (mFileComment == NULL) {
|
||||
result = NO_MEMORY;
|
||||
goto bail;
|
||||
|
@ -626,7 +627,7 @@ bail:
|
|||
*/
|
||||
status_t ZipEntry::CentralDirEntry::write(FILE* fp)
|
||||
{
|
||||
unsigned char buf[kCDELen];
|
||||
uint8_t buf[kCDELen];
|
||||
|
||||
ZipEntry::putLongLE(&buf[0x00], kSignature);
|
||||
ZipEntry::putShortLE(&buf[0x04], mVersionMadeBy);
|
||||
|
@ -676,15 +677,15 @@ status_t ZipEntry::CentralDirEntry::write(FILE* fp)
|
|||
void ZipEntry::CentralDirEntry::dump(void) const
|
||||
{
|
||||
ALOGD(" CentralDirEntry contents:\n");
|
||||
ALOGD(" versMadeBy=%u versToExt=%u gpBits=0x%04x compression=%u\n",
|
||||
ALOGD(" versMadeBy=%" PRIu16 " versToExt=%" PRIu16 " gpBits=0x%04" PRIx16 " compression=%" PRIu16 "\n",
|
||||
mVersionMadeBy, mVersionToExtract, mGPBitFlag, mCompressionMethod);
|
||||
ALOGD(" modTime=0x%04x modDate=0x%04x crc32=0x%08lx\n",
|
||||
ALOGD(" modTime=0x%04" PRIx16 " modDate=0x%04" PRIx16 " crc32=0x%08" PRIx32 "\n",
|
||||
mLastModFileTime, mLastModFileDate, mCRC32);
|
||||
ALOGD(" compressedSize=%lu uncompressedSize=%lu\n",
|
||||
ALOGD(" compressedSize=%" PRIu32 " uncompressedSize=%" PRIu32 "\n",
|
||||
mCompressedSize, mUncompressedSize);
|
||||
ALOGD(" filenameLen=%u extraLen=%u commentLen=%u\n",
|
||||
ALOGD(" filenameLen=%" PRIu16 " extraLen=%" PRIu16 " commentLen=%" PRIu16 "\n",
|
||||
mFileNameLength, mExtraFieldLength, mFileCommentLength);
|
||||
ALOGD(" diskNumStart=%u intAttr=0x%04x extAttr=0x%08lx relOffset=%lu\n",
|
||||
ALOGD(" diskNumStart=%" PRIu16 " intAttr=0x%04" PRIx16 " extAttr=0x%08" PRIx32 " relOffset=%" PRIu32 "\n",
|
||||
mDiskNumberStart, mInternalAttrs, mExternalAttrs,
|
||||
mLocalHeaderRelOffset);
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <utils/Errors.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace android {
|
||||
|
@ -85,7 +86,7 @@ public:
|
|||
/*
|
||||
* Return the data CRC.
|
||||
*/
|
||||
unsigned long getCRC32(void) const { return mCDE.mCRC32; }
|
||||
uint32_t getCRC32(void) const { return mCDE.mCRC32; }
|
||||
|
||||
/*
|
||||
* Return file modification time in UNIX seconds-since-epoch.
|
||||
|
@ -108,21 +109,21 @@ public:
|
|||
* Some basic functions for raw data manipulation. "LE" means
|
||||
* Little Endian.
|
||||
*/
|
||||
static inline unsigned short getShortLE(const unsigned char* buf) {
|
||||
static inline uint16_t getShortLE(const uint8_t* buf) {
|
||||
return buf[0] | (buf[1] << 8);
|
||||
}
|
||||
static inline unsigned long getLongLE(const unsigned char* buf) {
|
||||
static inline uint32_t getLongLE(const uint8_t* buf) {
|
||||
return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
|
||||
}
|
||||
static inline void putShortLE(unsigned char* buf, short val) {
|
||||
buf[0] = (unsigned char) val;
|
||||
buf[1] = (unsigned char) (val >> 8);
|
||||
static inline void putShortLE(uint8_t* buf, uint16_t val) {
|
||||
buf[0] = (uint8_t) val;
|
||||
buf[1] = (uint8_t) (val >> 8);
|
||||
}
|
||||
static inline void putLongLE(unsigned char* buf, long val) {
|
||||
buf[0] = (unsigned char) val;
|
||||
buf[1] = (unsigned char) (val >> 8);
|
||||
buf[2] = (unsigned char) (val >> 16);
|
||||
buf[3] = (unsigned char) (val >> 24);
|
||||
static inline void putLongLE(uint8_t* buf, uint32_t val) {
|
||||
buf[0] = (uint8_t) val;
|
||||
buf[1] = (uint8_t) (val >> 8);
|
||||
buf[2] = (uint8_t) (val >> 16);
|
||||
buf[3] = (uint8_t) (val >> 24);
|
||||
}
|
||||
|
||||
/* defined for Zip archives */
|
||||
|
@ -177,7 +178,7 @@ protected:
|
|||
/*
|
||||
* Set information about the data for this entry.
|
||||
*/
|
||||
void setDataInfo(long uncompLen, long compLen, unsigned long crc32,
|
||||
void setDataInfo(long uncompLen, long compLen, uint32_t crc32,
|
||||
int compressionMethod);
|
||||
|
||||
/*
|
||||
|
@ -195,7 +196,7 @@ protected:
|
|||
* the current file.
|
||||
*/
|
||||
void setLFHOffset(off_t offset) {
|
||||
mCDE.mLocalHeaderRelOffset = (long) offset;
|
||||
mCDE.mLocalHeaderRelOffset = (uint32_t) offset;
|
||||
}
|
||||
|
||||
/* mark for deletion; used by ZipFile::remove() */
|
||||
|
@ -240,19 +241,19 @@ private:
|
|||
status_t read(FILE* fp);
|
||||
status_t write(FILE* fp);
|
||||
|
||||
// unsigned long mSignature;
|
||||
unsigned short mVersionToExtract;
|
||||
unsigned short mGPBitFlag;
|
||||
unsigned short mCompressionMethod;
|
||||
unsigned short mLastModFileTime;
|
||||
unsigned short mLastModFileDate;
|
||||
unsigned long mCRC32;
|
||||
unsigned long mCompressedSize;
|
||||
unsigned long mUncompressedSize;
|
||||
unsigned short mFileNameLength;
|
||||
unsigned short mExtraFieldLength;
|
||||
unsigned char* mFileName;
|
||||
unsigned char* mExtraField;
|
||||
// uint32_t mSignature;
|
||||
uint16_t mVersionToExtract;
|
||||
uint16_t mGPBitFlag;
|
||||
uint16_t mCompressionMethod;
|
||||
uint16_t mLastModFileTime;
|
||||
uint16_t mLastModFileDate;
|
||||
uint32_t mCRC32;
|
||||
uint32_t mCompressedSize;
|
||||
uint32_t mUncompressedSize;
|
||||
uint16_t mFileNameLength;
|
||||
uint16_t mExtraFieldLength;
|
||||
uint8_t* mFileName;
|
||||
uint8_t* mExtraField;
|
||||
|
||||
enum {
|
||||
kSignature = 0x04034b50,
|
||||
|
@ -298,26 +299,26 @@ private:
|
|||
status_t read(FILE* fp);
|
||||
status_t write(FILE* fp);
|
||||
|
||||
// unsigned long mSignature;
|
||||
unsigned short mVersionMadeBy;
|
||||
unsigned short mVersionToExtract;
|
||||
unsigned short mGPBitFlag;
|
||||
unsigned short mCompressionMethod;
|
||||
unsigned short mLastModFileTime;
|
||||
unsigned short mLastModFileDate;
|
||||
unsigned long mCRC32;
|
||||
unsigned long mCompressedSize;
|
||||
unsigned long mUncompressedSize;
|
||||
unsigned short mFileNameLength;
|
||||
unsigned short mExtraFieldLength;
|
||||
unsigned short mFileCommentLength;
|
||||
unsigned short mDiskNumberStart;
|
||||
unsigned short mInternalAttrs;
|
||||
unsigned long mExternalAttrs;
|
||||
unsigned long mLocalHeaderRelOffset;
|
||||
unsigned char* mFileName;
|
||||
unsigned char* mExtraField;
|
||||
unsigned char* mFileComment;
|
||||
// uint32_t mSignature;
|
||||
uint16_t mVersionMadeBy;
|
||||
uint16_t mVersionToExtract;
|
||||
uint16_t mGPBitFlag;
|
||||
uint16_t mCompressionMethod;
|
||||
uint16_t mLastModFileTime;
|
||||
uint16_t mLastModFileDate;
|
||||
uint32_t mCRC32;
|
||||
uint32_t mCompressedSize;
|
||||
uint32_t mUncompressedSize;
|
||||
uint16_t mFileNameLength;
|
||||
uint16_t mExtraFieldLength;
|
||||
uint16_t mFileCommentLength;
|
||||
uint16_t mDiskNumberStart;
|
||||
uint16_t mInternalAttrs;
|
||||
uint32_t mExternalAttrs;
|
||||
uint32_t mLocalHeaderRelOffset;
|
||||
uint8_t* mFileName;
|
||||
uint8_t* mExtraField;
|
||||
uint8_t* mFileComment;
|
||||
|
||||
void dump(void) const;
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
using namespace android;
|
||||
|
||||
|
@ -206,7 +207,7 @@ void ZipFile::discardEntries(void)
|
|||
status_t ZipFile::readCentralDir(void)
|
||||
{
|
||||
status_t result = NO_ERROR;
|
||||
unsigned char* buf = NULL;
|
||||
uint8_t* buf = NULL;
|
||||
off_t fileLength, seekStart;
|
||||
long readAmount;
|
||||
int i;
|
||||
|
@ -222,7 +223,7 @@ status_t ZipFile::readCentralDir(void)
|
|||
goto bail;
|
||||
}
|
||||
|
||||
buf = new unsigned char[EndOfCentralDir::kMaxEOCDSearch];
|
||||
buf = new uint8_t[EndOfCentralDir::kMaxEOCDSearch];
|
||||
if (buf == NULL) {
|
||||
ALOGD("Failure allocating %d bytes for EOCD search",
|
||||
EndOfCentralDir::kMaxEOCDSearch);
|
||||
|
@ -296,7 +297,7 @@ status_t ZipFile::readCentralDir(void)
|
|||
* we're hoping to preserve.
|
||||
*/
|
||||
if (fseek(mZipFp, mEOCD.mCentralDirOffset, SEEK_SET) != 0) {
|
||||
ALOGD("Failure seeking to central dir offset %ld\n",
|
||||
ALOGD("Failure seeking to central dir offset %" PRIu32 "\n",
|
||||
mEOCD.mCentralDirOffset);
|
||||
result = UNKNOWN_ERROR;
|
||||
goto bail;
|
||||
|
@ -305,7 +306,7 @@ status_t ZipFile::readCentralDir(void)
|
|||
/*
|
||||
* Loop through and read the central dir entries.
|
||||
*/
|
||||
ALOGV("Scanning %d entries...\n", mEOCD.mTotalNumEntries);
|
||||
ALOGV("Scanning %" PRIu16 " entries...\n", mEOCD.mTotalNumEntries);
|
||||
int entry;
|
||||
for (entry = 0; entry < mEOCD.mTotalNumEntries; entry++) {
|
||||
ZipEntry* pEntry = new ZipEntry;
|
||||
|
@ -325,7 +326,7 @@ status_t ZipFile::readCentralDir(void)
|
|||
* If all went well, we should now be back at the EOCD.
|
||||
*/
|
||||
{
|
||||
unsigned char checkBuf[4];
|
||||
uint8_t checkBuf[4];
|
||||
if (fread(checkBuf, 1, 4, mZipFp) != 4) {
|
||||
ALOGD("EOCD check read failed\n");
|
||||
result = INVALID_OPERATION;
|
||||
|
@ -365,7 +366,7 @@ status_t ZipFile::addCommon(const char* fileName, const void* data, size_t size,
|
|||
status_t result = NO_ERROR;
|
||||
long lfhPosn, startPosn, endPosn, uncompressedLen;
|
||||
FILE* inputFp = NULL;
|
||||
unsigned long crc;
|
||||
uint32_t crc;
|
||||
time_t modWhen;
|
||||
|
||||
if (mReadOnly)
|
||||
|
@ -466,14 +467,16 @@ status_t ZipFile::addCommon(const char* fileName, const void* data, size_t size,
|
|||
bool scanResult;
|
||||
int method;
|
||||
long compressedLen;
|
||||
unsigned long longcrc;
|
||||
|
||||
scanResult = ZipUtils::examineGzip(inputFp, &method, &uncompressedLen,
|
||||
&compressedLen, &crc);
|
||||
&compressedLen, &longcrc);
|
||||
if (!scanResult || method != ZipEntry::kCompressDeflated) {
|
||||
ALOGD("this isn't a deflated gzip file?");
|
||||
result = UNKNOWN_ERROR;
|
||||
goto bail;
|
||||
}
|
||||
crc = longcrc;
|
||||
|
||||
result = copyPartialFpToFp(mZipFp, inputFp, compressedLen, NULL);
|
||||
if (result != NO_ERROR) {
|
||||
|
@ -710,7 +713,7 @@ status_t ZipFile::addRecompress(const ZipFile* pSourceZip, const ZipEntry* pSour
|
|||
goto bail;
|
||||
}
|
||||
long startPosn = ftell(mZipFp);
|
||||
unsigned long crc;
|
||||
uint32_t crc;
|
||||
if (compressFpToFp(mZipFp, NULL, buf, uncompressedLen, &crc) != NO_ERROR) {
|
||||
ALOGW("recompress of '%s' failed\n", pEntry->mCDE.mFileName);
|
||||
result = UNKNOWN_ERROR;
|
||||
|
@ -780,9 +783,9 @@ bail:
|
|||
* On exit, "srcFp" will be seeked to the end of the file, and "dstFp"
|
||||
* will be seeked immediately past the data.
|
||||
*/
|
||||
status_t ZipFile::copyFpToFp(FILE* dstFp, FILE* srcFp, unsigned long* pCRC32)
|
||||
status_t ZipFile::copyFpToFp(FILE* dstFp, FILE* srcFp, uint32_t* pCRC32)
|
||||
{
|
||||
unsigned char tmpBuf[32768];
|
||||
uint8_t tmpBuf[32768];
|
||||
size_t count;
|
||||
|
||||
*pCRC32 = crc32(0L, Z_NULL, 0);
|
||||
|
@ -811,7 +814,7 @@ status_t ZipFile::copyFpToFp(FILE* dstFp, FILE* srcFp, unsigned long* pCRC32)
|
|||
* On exit, "dstFp" will be seeked immediately past the data.
|
||||
*/
|
||||
status_t ZipFile::copyDataToFp(FILE* dstFp,
|
||||
const void* data, size_t size, unsigned long* pCRC32)
|
||||
const void* data, size_t size, uint32_t* pCRC32)
|
||||
{
|
||||
size_t count;
|
||||
|
||||
|
@ -836,9 +839,9 @@ status_t ZipFile::copyDataToFp(FILE* dstFp,
|
|||
* will be seeked immediately past the data just written.
|
||||
*/
|
||||
status_t ZipFile::copyPartialFpToFp(FILE* dstFp, FILE* srcFp, long length,
|
||||
unsigned long* pCRC32)
|
||||
uint32_t* pCRC32)
|
||||
{
|
||||
unsigned char tmpBuf[32768];
|
||||
uint8_t tmpBuf[32768];
|
||||
size_t count;
|
||||
|
||||
if (pCRC32 != NULL)
|
||||
|
@ -846,7 +849,7 @@ status_t ZipFile::copyPartialFpToFp(FILE* dstFp, FILE* srcFp, long length,
|
|||
|
||||
while (length) {
|
||||
long readSize;
|
||||
|
||||
|
||||
readSize = sizeof(tmpBuf);
|
||||
if (readSize > length)
|
||||
readSize = length;
|
||||
|
@ -878,15 +881,15 @@ status_t ZipFile::copyPartialFpToFp(FILE* dstFp, FILE* srcFp, long length,
|
|||
* will be seeked immediately past the compressed data.
|
||||
*/
|
||||
status_t ZipFile::compressFpToFp(FILE* dstFp, FILE* srcFp,
|
||||
const void* data, size_t size, unsigned long* pCRC32)
|
||||
const void* data, size_t size, uint32_t* pCRC32)
|
||||
{
|
||||
status_t result = NO_ERROR;
|
||||
const size_t kBufSize = 1024 * 1024;
|
||||
unsigned char* inBuf = NULL;
|
||||
unsigned char* outBuf = NULL;
|
||||
uint8_t* inBuf = NULL;
|
||||
uint8_t* outBuf = NULL;
|
||||
size_t outSize = 0;
|
||||
bool atEof = false; // no feof() aviailable yet
|
||||
unsigned long crc;
|
||||
uint32_t crc;
|
||||
ZopfliOptions options;
|
||||
unsigned char bp = 0;
|
||||
|
||||
|
@ -902,7 +905,7 @@ status_t ZipFile::compressFpToFp(FILE* dstFp, FILE* srcFp,
|
|||
/*
|
||||
* Create an input buffer and an output buffer.
|
||||
*/
|
||||
inBuf = new unsigned char[kBufSize];
|
||||
inBuf = new uint8_t[kBufSize];
|
||||
if (inBuf == NULL) {
|
||||
result = NO_MEMORY;
|
||||
goto bail;
|
||||
|
@ -1128,7 +1131,7 @@ status_t ZipFile::filemove(FILE* fp, off_t dst, off_t src, size_t n)
|
|||
if (dst == src || n <= 0)
|
||||
return NO_ERROR;
|
||||
|
||||
unsigned char readBuf[32768];
|
||||
uint8_t readBuf[32768];
|
||||
|
||||
if (dst < src) {
|
||||
/* shift stuff toward start of file; must read from start */
|
||||
|
@ -1294,7 +1297,7 @@ bail:
|
|||
* "buf" should be positioned at the EOCD signature, and should contain
|
||||
* the entire EOCD area including the comment.
|
||||
*/
|
||||
status_t ZipFile::EndOfCentralDir::readBuf(const unsigned char* buf, int len)
|
||||
status_t ZipFile::EndOfCentralDir::readBuf(const uint8_t* buf, int len)
|
||||
{
|
||||
/* don't allow re-use */
|
||||
assert(mComment == NULL);
|
||||
|
@ -1322,11 +1325,11 @@ status_t ZipFile::EndOfCentralDir::readBuf(const unsigned char* buf, int len)
|
|||
|
||||
if (mCommentLen > 0) {
|
||||
if (kEOCDLen + mCommentLen > len) {
|
||||
ALOGD("EOCD(%d) + comment(%d) exceeds len (%d)\n",
|
||||
ALOGD("EOCD(%d) + comment(%" PRIu16 ") exceeds len (%d)\n",
|
||||
kEOCDLen, mCommentLen, len);
|
||||
return UNKNOWN_ERROR;
|
||||
}
|
||||
mComment = new unsigned char[mCommentLen];
|
||||
mComment = new uint8_t[mCommentLen];
|
||||
memcpy(mComment, buf + kEOCDLen, mCommentLen);
|
||||
}
|
||||
|
||||
|
@ -1338,7 +1341,7 @@ status_t ZipFile::EndOfCentralDir::readBuf(const unsigned char* buf, int len)
|
|||
*/
|
||||
status_t ZipFile::EndOfCentralDir::write(FILE* fp)
|
||||
{
|
||||
unsigned char buf[kEOCDLen];
|
||||
uint8_t buf[kEOCDLen];
|
||||
|
||||
ZipEntry::putLongLE(&buf[0x00], kSignature);
|
||||
ZipEntry::putShortLE(&buf[0x04], mDiskNumber);
|
||||
|
@ -1366,9 +1369,9 @@ status_t ZipFile::EndOfCentralDir::write(FILE* fp)
|
|||
void ZipFile::EndOfCentralDir::dump(void) const
|
||||
{
|
||||
ALOGD(" EndOfCentralDir contents:\n");
|
||||
ALOGD(" diskNum=%u diskWCD=%u numEnt=%u totalNumEnt=%u\n",
|
||||
ALOGD(" diskNum=%" PRIu16 " diskWCD=%" PRIu16 " numEnt=%" PRIu16 " totalNumEnt=%" PRIu16 "\n",
|
||||
mDiskNumber, mDiskWithCentralDir, mNumEntries, mTotalNumEntries);
|
||||
ALOGD(" centDirSize=%lu centDirOff=%lu commentLen=%u\n",
|
||||
ALOGD(" centDirSize=%" PRIu32 " centDirOff=%" PRIu32 " commentLen=%" PRIu32 "\n",
|
||||
mCentralDirSize, mCentralDirOffset, mCommentLen);
|
||||
}
|
||||
|
||||
|
|
|
@ -194,18 +194,18 @@ private:
|
|||
delete[] mComment;
|
||||
}
|
||||
|
||||
status_t readBuf(const unsigned char* buf, int len);
|
||||
status_t readBuf(const uint8_t* buf, int len);
|
||||
status_t write(FILE* fp);
|
||||
|
||||
//unsigned long mSignature;
|
||||
unsigned short mDiskNumber;
|
||||
unsigned short mDiskWithCentralDir;
|
||||
unsigned short mNumEntries;
|
||||
unsigned short mTotalNumEntries;
|
||||
unsigned long mCentralDirSize;
|
||||
unsigned long mCentralDirOffset; // offset from first disk
|
||||
unsigned short mCommentLen;
|
||||
unsigned char* mComment;
|
||||
//uint32_t mSignature;
|
||||
uint16_t mDiskNumber;
|
||||
uint16_t mDiskWithCentralDir;
|
||||
uint16_t mNumEntries;
|
||||
uint16_t mTotalNumEntries;
|
||||
uint32_t mCentralDirSize;
|
||||
uint32_t mCentralDirOffset; // offset from first disk
|
||||
uint16_t mCommentLen;
|
||||
uint8_t* mComment;
|
||||
|
||||
enum {
|
||||
kSignature = 0x06054b50,
|
||||
|
@ -235,18 +235,18 @@ private:
|
|||
ZipEntry** ppEntry);
|
||||
|
||||
/* copy all of "srcFp" into "dstFp" */
|
||||
status_t copyFpToFp(FILE* dstFp, FILE* srcFp, unsigned long* pCRC32);
|
||||
status_t copyFpToFp(FILE* dstFp, FILE* srcFp, uint32_t* pCRC32);
|
||||
/* copy all of "data" into "dstFp" */
|
||||
status_t copyDataToFp(FILE* dstFp,
|
||||
const void* data, size_t size, unsigned long* pCRC32);
|
||||
const void* data, size_t size, uint32_t* pCRC32);
|
||||
/* copy some of "srcFp" into "dstFp" */
|
||||
status_t copyPartialFpToFp(FILE* dstFp, FILE* srcFp, long length,
|
||||
unsigned long* pCRC32);
|
||||
uint32_t* pCRC32);
|
||||
/* like memmove(), but on parts of a single file */
|
||||
status_t filemove(FILE* fp, off_t dest, off_t src, size_t n);
|
||||
/* compress all of "srcFp" into "dstFp", using Deflate */
|
||||
status_t compressFpToFp(FILE* dstFp, FILE* srcFp,
|
||||
const void* data, size_t size, unsigned long* pCRC32);
|
||||
const void* data, size_t size, uint32_t* pCRC32);
|
||||
|
||||
/* get modification date from a file descriptor */
|
||||
time_t getModTime(int fd);
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
using namespace android;
|
||||
|
||||
|
@ -55,7 +56,7 @@ status_t ZipEntry::initAndRewriteFromCDE(FILE* fp)
|
|||
/* using the info in the CDE, go load up the LFH */
|
||||
posn = ftell(fp);
|
||||
if (fseek(fp, mCDE.mLocalHeaderRelOffset, SEEK_SET) != 0) {
|
||||
LOG("local header seek failed (%ld)\n",
|
||||
LOG("local header seek failed (%" PRIu32 ")\n",
|
||||
mCDE.mLocalHeaderRelOffset);
|
||||
return -1;
|
||||
}
|
||||
|
@ -86,7 +87,7 @@ status_t ZipEntry::initAndRewriteFromCDE(FILE* fp)
|
|||
status_t ZipEntry::LocalFileHeader::rewrite(FILE* fp)
|
||||
{
|
||||
status_t result = 0;
|
||||
unsigned char buf[kLFHLen];
|
||||
uint8_t buf[kLFHLen];
|
||||
|
||||
if (fread(buf, 1, kLFHLen, fp) != kLFHLen)
|
||||
return -1;
|
||||
|
@ -124,8 +125,8 @@ status_t ZipEntry::LocalFileHeader::rewrite(FILE* fp)
|
|||
status_t ZipEntry::CentralDirEntry::rewrite(FILE* fp)
|
||||
{
|
||||
status_t result = 0;
|
||||
unsigned char buf[kCDELen];
|
||||
unsigned short fileNameLength, extraFieldLength, fileCommentLength;
|
||||
uint8_t buf[kCDELen];
|
||||
uint16_t fileNameLength, extraFieldLength, fileCommentLength;
|
||||
|
||||
if (fread(buf, 1, kCDELen, fp) != kCDELen)
|
||||
return -1;
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#define __LIBS_ZIPENTRY_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef int status_t;
|
||||
|
@ -49,15 +50,15 @@ public:
|
|||
* Some basic functions for raw data manipulation. "LE" means
|
||||
* Little Endian.
|
||||
*/
|
||||
static inline unsigned short getShortLE(const unsigned char* buf) {
|
||||
static inline uint16_t getShortLE(const uint8_t* buf) {
|
||||
return buf[0] | (buf[1] << 8);
|
||||
}
|
||||
static inline unsigned long getLongLE(const unsigned char* buf) {
|
||||
static inline uint32_t getLongLE(const uint8_t* buf) {
|
||||
return buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
|
||||
}
|
||||
static inline void putShortLE(unsigned char* buf, short val) {
|
||||
buf[0] = (unsigned char) val;
|
||||
buf[1] = (unsigned char) (val >> 8);
|
||||
static inline void putShortLE(uint8_t* buf, uint16_t val) {
|
||||
buf[0] = (uint8_t) val;
|
||||
buf[1] = (uint8_t) (val >> 8);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
@ -99,7 +100,7 @@ private:
|
|||
|
||||
status_t rewrite(FILE* fp);
|
||||
|
||||
unsigned long mLocalHeaderRelOffset;
|
||||
uint32_t mLocalHeaderRelOffset;
|
||||
|
||||
enum {
|
||||
kSignature = 0x02014b50,
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
using namespace android;
|
||||
|
||||
|
@ -72,7 +73,7 @@ status_t ZipFile::rewrite(const char* zipFileName)
|
|||
status_t ZipFile::rewriteCentralDir(void)
|
||||
{
|
||||
status_t result = 0;
|
||||
unsigned char* buf = NULL;
|
||||
uint8_t* buf = NULL;
|
||||
off_t fileLength, seekStart;
|
||||
long readAmount;
|
||||
int i;
|
||||
|
@ -88,7 +89,7 @@ status_t ZipFile::rewriteCentralDir(void)
|
|||
goto bail;
|
||||
}
|
||||
|
||||
buf = new unsigned char[EndOfCentralDir::kMaxEOCDSearch];
|
||||
buf = new uint8_t[EndOfCentralDir::kMaxEOCDSearch];
|
||||
if (buf == NULL) {
|
||||
LOG("Failure allocating %d bytes for EOCD search",
|
||||
EndOfCentralDir::kMaxEOCDSearch);
|
||||
|
@ -152,7 +153,7 @@ status_t ZipFile::rewriteCentralDir(void)
|
|||
* we're hoping to preserve.
|
||||
*/
|
||||
if (fseek(mZipFp, mEOCD.mCentralDirOffset, SEEK_SET) != 0) {
|
||||
LOG("Failure seeking to central dir offset %ld\n",
|
||||
LOG("Failure seeking to central dir offset %" PRIu32 "\n",
|
||||
mEOCD.mCentralDirOffset);
|
||||
result = -1;
|
||||
goto bail;
|
||||
|
@ -179,7 +180,7 @@ status_t ZipFile::rewriteCentralDir(void)
|
|||
/*
|
||||
* If all went well, we should now be back at the EOCD.
|
||||
*/
|
||||
unsigned char checkBuf[4];
|
||||
uint8_t checkBuf[4];
|
||||
if (fread(checkBuf, 1, 4, mZipFp) != 4) {
|
||||
LOG("EOCD check read failed\n");
|
||||
result = -1;
|
||||
|
@ -208,9 +209,9 @@ bail:
|
|||
* "buf" should be positioned at the EOCD signature, and should contain
|
||||
* the entire EOCD area including the comment.
|
||||
*/
|
||||
status_t ZipFile::EndOfCentralDir::readBuf(const unsigned char* buf, int len)
|
||||
status_t ZipFile::EndOfCentralDir::readBuf(const uint8_t* buf, int len)
|
||||
{
|
||||
unsigned short diskNumber, diskWithCentralDir, numEntries;
|
||||
uint16_t diskNumber, diskWithCentralDir, numEntries;
|
||||
|
||||
if (len < kEOCDLen) {
|
||||
/* looks like ZIP file got truncated */
|
||||
|
|
|
@ -51,10 +51,10 @@ private:
|
|||
public:
|
||||
EndOfCentralDir(void) : mTotalNumEntries(0), mCentralDirOffset(0) {}
|
||||
|
||||
status_t readBuf(const unsigned char* buf, int len);
|
||||
status_t readBuf(const uint8_t* buf, int len);
|
||||
|
||||
unsigned short mTotalNumEntries;
|
||||
unsigned long mCentralDirOffset; // offset from first disk
|
||||
uint16_t mTotalNumEntries;
|
||||
uint32_t mCentralDirOffset; // offset from first disk
|
||||
|
||||
enum {
|
||||
kSignature = 0x06054b50,
|
||||
|
|
Loading…
Reference in a new issue