mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-30 06:20:28 +00:00
Remove old zip base skew hack
Since 8ff48201ca
we no longer need the
hack where, when running .com.dbg files, we scanned for the embedded
.com file offset, and then computed zip offsets realtive to that. It
wasn't very reliable in the first place, and was causing issues with
running our new .com.dbg executables, which are true zip files.
This commit is contained in:
parent
207e18a060
commit
52d28966f7
10 changed files with 134 additions and 238 deletions
|
@ -1,78 +0,0 @@
|
|||
#if 0
|
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │
|
||||
│ all copyright and related or neighboring rights to this file, │
|
||||
│ as it is written in the following disclaimers: │
|
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/log/check.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/sysv/consts/map.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/prot.h"
|
||||
#include "libc/zip.internal.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "usage: %s FOO.COM\n", argv[0]);
|
||||
fprintf(stderr,
|
||||
"prints lowest file offset (in decimal bytes) at which zip\n"
|
||||
"records exist within a .com, .com.dbg, or .zip file\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int fd = open(argv[1], O_RDONLY);
|
||||
if (fd == -1) {
|
||||
perror(argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
size_t n;
|
||||
struct stat st;
|
||||
CHECK_EQ(0, fstat(fd, &st));
|
||||
n = st.st_size;
|
||||
|
||||
uint8_t *m;
|
||||
CHECK_NE(MAP_FAILED, (m = mmap(0, n, PROT_READ, MAP_PRIVATE, fd, 0)));
|
||||
|
||||
int err;
|
||||
uint8_t *b, *d, *p;
|
||||
if ((p = FindEmbeddedApe(m, n))) {
|
||||
b = p;
|
||||
n -= p - m;
|
||||
} else {
|
||||
b = m;
|
||||
}
|
||||
if (!(d = GetZipEocd(b, n, &err))) {
|
||||
fprintf(stderr, "%s: couldn't locate central directory [zip error %d]\n",
|
||||
argv[1], err);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
size_t zsize = n;
|
||||
uint8_t *zmap = m;
|
||||
uint8_t *zbase = b;
|
||||
uint8_t *zcdir = d;
|
||||
DCHECK(IsZipEocd32(zbase, zsize, zcdir - zbase) == kZipOk ||
|
||||
IsZipEocd64(zbase, zsize, zcdir - zbase) == kZipOk);
|
||||
|
||||
uint64_t cf;
|
||||
uint64_t lf;
|
||||
uint64_t minzipoffset;
|
||||
n = GetZipCdirRecords(zcdir);
|
||||
minzipoffset = cf = GetZipCdirOffset(zcdir);
|
||||
for (; n--; cf += ZIP_CFILE_HDRSIZE(zbase + cf)) {
|
||||
CHECK_EQ(kZipCfileHdrMagic, ZIP_CFILE_MAGIC(zbase + cf));
|
||||
lf = GetZipCfileOffset(zbase + cf);
|
||||
minzipoffset = MIN(minzipoffset, lf);
|
||||
}
|
||||
|
||||
printf("%ld\n", (zbase + minzipoffset) - m);
|
||||
}
|
|
@ -123,12 +123,15 @@ static void CopyZip(void) {
|
|||
unsigned char *ineof, *stop, *eocd, *cdir, *lfile, *cfile;
|
||||
|
||||
// find zip eocd header
|
||||
ineof = (unsigned char *)inmap + insize;
|
||||
ineof = inmap + insize;
|
||||
eocd = ineof - kZipCdirHdrMinSize;
|
||||
stop = MAX(eocd - 65536, inmap);
|
||||
for (;; --eocd) {
|
||||
if (eocd < stop) return;
|
||||
if (READ32LE(eocd) == kZipCdirHdrMagic) {
|
||||
if (IsZipEocd32(inmap, insize, eocd - inmap) != kZipOk) {
|
||||
Die(inpath, "found bad eocd record");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue