⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 extract.c

📁 WINDOWS下的ZIP解压软件,我是个学生,请让我加入这个网站学习
💻 C
📖 第 1 页 / 共 3 页
字号:
        if (!tflag && (quietflg < 2)) {
            fprintf(stdout, "  Expanding: %-22s ", filename);
            if (cflag)
                fprintf(stdout, "\n");
            fflush(stdout);
        }
#ifdef S_IFLNK   /* !!! This code needs to be added to unShrink, etc. !!! */
        if (symlnk) {
            fprintf(stdout, "\n  warning:  symbolic link ignored\n");
            error = 1;          /* 1:  warning error */
        }
#endif /* S_IFLNK */
        unReduce();
        break;

    case IMPLODED:
        if (!tflag && (quietflg < 2)) {
            fprintf(stdout, "  Exploding: %-22s ", filename);
            if (cflag)
                fprintf(stdout, "\n");
            fflush(stdout);
        }
#ifdef S_IFLNK   /* !!! This code needs to be added to unShrink, etc. !!! */
        if (symlnk) {
            fprintf(stdout, "\n  warning:  symbolic link ignored\n");
            error = 1;          /* 1:  warning error */
        }
#endif /* S_IFLNK */
        if (((r = explode()) != 0) && (r != 5)) {   /* ignore 5 if seekable */
            if ((tflag && quietflg) || (!tflag && (quietflg > 1)))
                fprintf(stderr, "  error:  %s%s\n", r == 3?
                  "not enough memory to explode " :
                  "invalid compressed (imploded) data for ", filename);
            else
                fprintf(stderr, "\n  error:  %s\n", r == 3?
                  "not enough memory for explode operation" :
                  "invalid compressed data for explode format");
            error = (r == 3)? 5 : 2;
        }
        break;

    case DEFLATED:
        if (!tflag && (quietflg < 2)) {
            fprintf(stdout, "  Inflating: %-22s ", filename);
            if (cflag)
                fprintf(stdout, "\n");
            fflush(stdout);
        }
#ifdef S_IFLNK   /* !!! This code needs to be added to unShrink, etc. !!! */
        if (symlnk) {
            fprintf(stdout, "\n  warning:  symbolic link ignored\n");
            error = 1;          /* 1:  warning error */
        }
#endif /* S_IFLNK */
        if ((r = inflate()) != 0) {
            if ((tflag && quietflg) || (!tflag && (quietflg > 1)))
                fprintf(stderr, "  error:  %s%s\n", r == 3?
                  "not enough memory to inflate " :
                  "invalid compressed (deflated) data for ", filename);
            else
                fprintf(stderr, "\n  error:  %s\n", r == 3?
                  "not enough memory for inflate operation" :
                  "invalid compressed data for inflate format");
            error = (r == 3)? 5 : 2;
        }
        break;

    default:   /* should never get to this point */
        fprintf(stderr, "%s:  unknown compression method\n", filename);
        /* close and delete file before return? */
        return 1;               /* 1:  warning error */

    } /* end switch (compression method) */

    if (disk_full) {            /* set by FlushOutput()/OUTB() macro */
        if (disk_full > 1)
            return 50;          /* 50:  disk full */
        error = 1;              /* 1:  warning error */
    }

/*---------------------------------------------------------------------------
    Write the last partial buffer, if any; set the file date and time; and
    close the file (not necessarily in that order).  Then make sure CRC came
    out OK and print result.
  ---------------------------------------------------------------------------*/

#ifdef S_IFLNK
    if (!symlnk) {
#endif /* S_IFLNK */
    if (!disk_full && FlushOutput())
        if (disk_full > 1)
            return 50;          /* 50:  disk full */
        else {                  /* disk_full == 1 */
            fprintf(stderr, "%s:  probably corrupt\n", filename);
            error = 1;          /* 1:  warning error */
        }

    if (!tflag)
#ifdef VMS
        CloseOutputFile();
#else /* !VMS */
#ifdef MTS                      /* MTS can't set file time */
        close(outfd);
#else /* !MTS */
        set_file_time_and_close();
#endif /* ?MTS */
#endif /* ?VMS */

#ifdef S_IFLNK
    } /* endif (!symlnk) */
#endif /* S_IFLNK */

    if (error > 1)   /* don't print redundant CRC error if error already */
        return error;

    /* logical-AND crc32val for 64-bit machines */
    if ((crc32val = ((~crc32val) & 0xFFFFFFFFL)) != lrec.crc32) {
        /* if quietflg is set, we haven't output the filename yet:  do it */
        if (quietflg)
            printf("%-22s: ", filename);
        fprintf(stdout, " Bad CRC %08lx  (should be %08lx)\n", crc32val,
                lrec.crc32);
        error = 1;              /* 1:  warning error */
    } else if (tflag) {
        if (!quietflg)
            fprintf(stdout, " OK\n");
    } else {
        if ((quietflg < 2) && !error)
            fprintf(stdout, "\n");
    }

    return error;

}       /* end function extract_or_test_member() */





#ifdef CRYPT

/*******************************/
/*  Function decrypt_member()  */
/*******************************/

static int decrypt_member()   /* return 10 if out of memory or can't get */
{                             /*  tty; 1 if password bad; 0 if password OK */
    UWORD b;
    int n, r;
    static int nopwd=FALSE;
    char *m, *prompt;
    byte h[12];


    /* get header once (turn off "encrypted" flag temporarily so we don't
     * try to decrypt the same data twice) */
    pInfo->encrypted = FALSE;
    for (n = 0; n < 12; n++) {
        ReadByte(&b);
        h[n] = (byte) b;
    }
    pInfo->encrypted = TRUE;

    /* if have key already, test it; else allocate memory for it */
    if (key) {
        if (!testp(h))
            return 0;      /* existing password OK (else prompt for new) */
        else if (nopwd)
            return 1;      /* user indicated no more prompting */
    } else if ((key = (char *)malloc(PWLEN+1)) == (char *)NULL)
        return 10;

    if ((prompt = (char *)malloc(FILNAMSIZ+15)) != (char *)NULL) {
        sprintf(prompt, "%s password: ", filename);
        m = prompt;
    } else
        m = "Enter password: ";

    /* try a few keys */
    for (r = 0;  r < 3;  ++r) {
        m = getp(m, key, PWLEN+1);
        if (prompt != (char *)NULL) {
            free(prompt);
            prompt = (char *)NULL;
        }
        if (m == (char *)NULL)
            return 10;
        if (!testp(h))
            return 0;
        if (*key == '\0') {
            nopwd = TRUE;
            return 1;
        }
        m = "password incorrect--reenter: ";
    }
    return 1;
}





/**********************/
/*  Function testp()  */
/**********************/

static int testp(h)   /* return -1 if bad password; 0 if OK */
    byte *h;
{
    UWORD b;
    int n, t;
    byte *p;

    /* set keys */
    init_keys(key);

    /* check password */
    for (n = 0; n < 12; n++)
        b = DECRYPT(h[n]);

#ifdef CRYPT_DEBUG
    printf("   lrec.crc = %08lx  crec.crc = %08lx  pInfo->ExtLocHdr = %s\n",
      lrec.crc32, pInfo->crc, pInfo->ExtLocHdr? "true":"false");
    printf("   incnt = %d  unzip offset into zipfile = %ld\n", incnt,
      cur_zipfile_bufstart+(inptr-inbuf));
    printf("   b = %02x  (crc >> 24) = %02x  (lrec.time >> 8) = %02x\n",
      b, (UWORD)(lrec.crc32 >> 24), (lrec.last_mod_file_time >> 8));
#endif /* CRYPT_DEBUG */

    /* same test as in zipbare() in crypt.c (now check only one byte): */
    if (b != (pInfo->ExtLocHdr? lrec.last_mod_file_time >> 8 :
        (UWORD)(lrec.crc32 >> 24)))
        return -1;  /* bad */

    /* password OK:  decrypt current buffer contents before leaving */
    for (n = (longint)incnt > csize ? (int)csize : incnt, p = inptr; n--; p++)
        *p = (byte) DECRYPT(*p);
    return 0;       /* OK */

} /* end function testp() */

#endif /* CRYPT */





/*******************************/
/*  Function ReadMemoryByte()  */
/*******************************/

int ReadMemoryByte(x)   /* return PK-type error code */
    UWORD *x;
{
    if (mem_i_offset < mem_i_size) {
        *x = (UWORD) mem_i_buffer[mem_i_offset++];
        return 8;
    } else
        return 0;
}





/****************************/
/*  Function FlushMemory()  */
/****************************/

int FlushMemory()   /* return PK-type error code */
{
    if (outcnt == 0)
        return 0;

    if (mem_o_offset + outcnt <= mem_o_size) {
        memcpy((char *)(mem_o_buffer+(UWORD)mem_o_offset), (char *)outbuf,
          outcnt);
        mem_o_offset += outcnt;
        return 0;
    } else
        return 50;
}





/***************************/
/*  Function memextract()  */   /* extract compressed extra field block */
/***************************/

int memextract(tgt, tgtsize, src, srcsize)  /* return 0 if success, 1 if not */
    byte *tgt, *src;
    ULONG tgtsize, srcsize;
{
    UWORD method, error = 0;
    ULONG crc, oldcrc;
    int r;

    method = makeword(src);
    crc = makelong(src+2);

    mem_i_buffer = src + 2 + 4;      /* method and crc */
    mem_i_size   = srcsize - 2 - 4;
    mem_i_offset = 0;
  
    mem_o_buffer = tgt;
    mem_o_size   = tgtsize;
    mem_o_offset = 0;

    mem_mode = 1;

    bits_left = 0;
    bitbuf = 0L;
    outpos = 0L;
    outcnt = 0;
    outptr = outbuf;
    zipeof = 0;

    switch (method) {
        case STORED:
            memcpy(tgt, src + 2 + 4, (extent) (srcsize - 2 - 4));
            break;
        case DEFLATED:
            if ((r = inflate()) != 0) {
                fprintf(stderr, "error:  %s\n", r == 3 ?
                  "not enough memory for inflate operation" :
                  "invalid compressed data for the inflate format");
                error = (r == 3)? 5 : 2;
            }
            FlushOutput();
            break;
        default:
            fprintf(stderr,
              "warning:  unsupported extra field compression type--skipping\n");
            error = 1;   /* GRR:  this should be passed on up via SetEAs() */
            break;
    }

    mem_mode = 0;

    if (!error) {
        oldcrc = crc32val;
        crc32val = 0xFFFFFFFFL;
        UpdateCRC((unsigned char *) mem_o_buffer, (int) mem_o_size);
        crc32val = (~crc32val) & 0xFFFFFFFFL;

        if (crc32val != crc) {
            printf("(Bad extra field CRC %08lx, should be %08lx)\n", crc32val,
              crc);
            error = 1;
        }
        crc32val = oldcrc; /* grrr ... this ugly kludge should be fixed */
    }

    return error;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -