Remove changing uids/timestamps from zip/jar files

Pass -X to zip so that Unix UID/GID and extra timestamps aren't
saved into the zip files.

Add a new option to zipalign, -t, to replace all timestamps with static
timestamps (2008 Jan 1 00:00:00). Use this for all non-APK zip files.
APK zip timestamps are set based on the certificate date in SignApk.

Bug: 24201956
Change-Id: Ifb619fc499ba9d99fc624f2acd5f8de36d78ef8e
This commit is contained in:
Dan Willemsen
2015-10-27 16:25:29 -07:00
parent c448e91c3d
commit 3c2c064c87
13 changed files with 108 additions and 53 deletions

View File

@@ -39,6 +39,7 @@ void usage(void)
fprintf(stderr, " -c: check alignment only (does not modify file)\n");
fprintf(stderr, " -f: overwrite existing outfile.zip\n");
fprintf(stderr, " -p: page align stored shared object files\n");
fprintf(stderr, " -t: remove dynamic timestamps\n");
fprintf(stderr, " -v: verbose output\n");
fprintf(stderr, " -z: recompress using Zopfli\n");
}
@@ -64,7 +65,7 @@ static int getAlignment(bool pageAlignSharedLibs, int defaultAlignment,
* Copy all entries from "pZin" to "pZout", aligning as needed.
*/
static int copyAndAlign(ZipFile* pZin, ZipFile* pZout, int alignment, bool zopfli,
bool pageAlignSharedLibs)
bool pageAlignSharedLibs, bool removeTime)
{
int numEntries = pZin->getNumEntries();
ZipEntry* pEntry;
@@ -88,10 +89,10 @@ static int copyAndAlign(ZipFile* pZin, ZipFile* pZout, int alignment, bool zopfl
// (long) pEntry->getUncompressedLen());
if (zopfli) {
status = pZout->addRecompress(pZin, pEntry, &pNewEntry);
status = pZout->addRecompress(pZin, pEntry, removeTime, &pNewEntry);
bias += pNewEntry->getCompressedLen() - pEntry->getCompressedLen();
} else {
status = pZout->add(pZin, pEntry, padding, &pNewEntry);
status = pZout->add(pZin, pEntry, padding, removeTime, &pNewEntry);
}
} else {
const int alignTo = getAlignment(pageAlignSharedLibs, alignment, pEntry);
@@ -107,7 +108,7 @@ static int copyAndAlign(ZipFile* pZin, ZipFile* pZout, int alignment, bool zopfl
//printf("--- %s: orig at %ld(+%d) len=%ld, adding pad=%d\n",
// pEntry->getFileName(), (long) pEntry->getFileOffset(),
// bias, (long) pEntry->getUncompressedLen(), padding);
status = pZout->add(pZin, pEntry, padding, &pNewEntry);
status = pZout->add(pZin, pEntry, padding, removeTime, &pNewEntry);
}
if (status != NO_ERROR)
@@ -126,7 +127,8 @@ static int copyAndAlign(ZipFile* pZin, ZipFile* pZout, int alignment, bool zopfl
* output file exists and "force" wasn't specified.
*/
static int process(const char* inFileName, const char* outFileName,
int alignment, bool force, bool zopfli, bool pageAlignSharedLibs)
int alignment, bool force, bool zopfli, bool pageAlignSharedLibs,
bool removeTime)
{
ZipFile zin, zout;
@@ -157,7 +159,7 @@ static int process(const char* inFileName, const char* outFileName,
return 1;
}
int result = copyAndAlign(&zin, &zout, alignment, zopfli, pageAlignSharedLibs);
int result = copyAndAlign(&zin, &zout, alignment, zopfli, pageAlignSharedLibs, removeTime);
if (result != 0) {
printf("zipalign: failed rewriting '%s' to '%s'\n",
inFileName, outFileName);
@@ -228,6 +230,7 @@ int main(int argc, char* const argv[])
bool verbose = false;
bool zopfli = false;
bool pageAlignSharedLibs = false;
bool removeTime = false;
int result = 1;
int alignment;
char* endp;
@@ -260,6 +263,9 @@ int main(int argc, char* const argv[])
case 'p':
pageAlignSharedLibs = true;
break;
case 't':
removeTime = true;
break;
default:
fprintf(stderr, "ERROR: unknown flag -%c\n", *cp);
wantUsage = true;
@@ -290,7 +296,7 @@ int main(int argc, char* const argv[])
result = verify(argv[1], alignment, verbose, pageAlignSharedLibs);
} else {
/* create the new archive */
result = process(argv[1], argv[2], alignment, force, zopfli, pageAlignSharedLibs);
result = process(argv[1], argv[2], alignment, force, zopfli, pageAlignSharedLibs, removeTime);
/* trust, but verify */
if (result == 0) {