mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 03:27:39 +00:00
Support \n in /zip/.args files
This commit is contained in:
parent
48e260e653
commit
585c86e2a4
4 changed files with 27 additions and 7 deletions
|
@ -93,6 +93,7 @@ EXAMPLES_DIRECTDEPS = \
|
|||
THIRD_PARTY_VQSORT \
|
||||
THIRD_PARTY_XED \
|
||||
THIRD_PARTY_ZLIB \
|
||||
TOOL_ARGS \
|
||||
TOOL_BUILD_LIB \
|
||||
TOOL_VIZ_LIB
|
||||
|
||||
|
|
|
@ -42,6 +42,9 @@ int IsZipEocd32(const uint8_t *p, size_t n, size_t i) {
|
|||
if (ZIP_CDIR_RECORDS(p + i) * kZipCfileHdrMinSize > ZIP_CDIR_SIZE(p + i)) {
|
||||
return kZipErrorEocdRecordsOverflow;
|
||||
}
|
||||
if (ZIP_CDIR_OFFSET(p + i) == 0xFFFFFFFFu) {
|
||||
return kZipErrorEocdRecordsOverflow;
|
||||
}
|
||||
if (ckd_add(&offset, ZIP_CDIR_OFFSET(p + i), ZIP_CDIR_SIZE(p + i))) {
|
||||
return kZipErrorEocdOffsetSizeOverflow;
|
||||
}
|
||||
|
|
|
@ -38,6 +38,21 @@ static struct ZipArgs {
|
|||
char **oldargv;
|
||||
} g_zipargs;
|
||||
|
||||
// remap \n → newline
|
||||
static char *Decode(char *arg) {
|
||||
int i, j;
|
||||
for (i = j = 0; arg[i]; ++i) {
|
||||
if (arg[i] == '\\' && arg[i + 1] == 'n') {
|
||||
arg[j++] = '\n';
|
||||
++i;
|
||||
} else {
|
||||
arg[j++] = arg[i];
|
||||
}
|
||||
}
|
||||
arg[j] = 0;
|
||||
return arg;
|
||||
}
|
||||
|
||||
static void AddZipArg(int *argc, char ***argv, char *arg) {
|
||||
*argv = xrealloc(*argv, (++(*argc) + 1) * sizeof(*(*argv)));
|
||||
(*argv)[*argc - 1] = arg;
|
||||
|
@ -72,7 +87,7 @@ int LoadZipArgsImpl(int *argc, char ***argv, char *data) {
|
|||
AddZipArg(&n, &args, (*argv)[i]);
|
||||
}
|
||||
} else {
|
||||
AddZipArg(&n, &args, arg);
|
||||
AddZipArg(&n, &args, Decode(arg));
|
||||
}
|
||||
start = 0;
|
||||
}
|
||||
|
|
|
@ -48,6 +48,8 @@
|
|||
* @fileoverview Zip File Disassembler.
|
||||
*/
|
||||
|
||||
uint8_t *map;
|
||||
|
||||
static __wur char *FormatDosDate(uint16_t dosdate) {
|
||||
return xasprintf("%04u-%02u-%02u", ((dosdate >> 9) & 0b1111111) + 1980,
|
||||
(dosdate >> 5) & 0b1111, dosdate & 0b11111);
|
||||
|
@ -60,9 +62,9 @@ static __wur char *FormatDosTime(uint16_t dostime) {
|
|||
|
||||
void AdvancePosition(uint8_t *map, size_t *pos, size_t off) {
|
||||
if (off > *pos) {
|
||||
printf("\n/\t<%s>\n", "LIMBO");
|
||||
disassemblehex(&map[*pos], off - *pos, stdout);
|
||||
printf("/\t</%s>\n", "LIMBO");
|
||||
/* printf("\n/\t<%s>\n", "LIMBO"); */
|
||||
/* disassemblehex(&map[*pos], off - *pos, stdout); */
|
||||
/* printf("/\t</%s>\n", "LIMBO"); */
|
||||
}
|
||||
*pos = off;
|
||||
}
|
||||
|
@ -288,8 +290,8 @@ void ShowLocalFileHeader(uint8_t *lf, uint16_t idx) {
|
|||
}
|
||||
|
||||
void ShowCentralFileHeader(uint8_t *cf) {
|
||||
printf("\n/\t%s (%zu %s)\n", "central directory file header",
|
||||
ZIP_CFILE_HDRSIZE(cf), "bytes");
|
||||
printf("\n/\t%s (%zu %s @ %#lx)\n", "central directory file header",
|
||||
ZIP_CFILE_HDRSIZE(cf), "bytes", cf - map);
|
||||
show(".ascii", format(b1, "%`'.*s", 4, cf), "magic");
|
||||
show(".byte", _gc(xasprintf("%d", ZIP_CFILE_VERSIONMADE(cf))),
|
||||
"zip version made");
|
||||
|
@ -485,7 +487,6 @@ void DisassembleZip(const char *path, uint8_t *p, size_t n) {
|
|||
|
||||
int main(int argc, char *argv[]) {
|
||||
int fd;
|
||||
uint8_t *map;
|
||||
struct stat st;
|
||||
ShowCrashReports();
|
||||
CHECK_EQ(2, argc);
|
||||
|
|
Loading…
Reference in a new issue