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