【问题标题】:How to check integrity of ZIP-file (Office Open XML file) with C/C++?如何使用 C/C++ 检查 ZIP 文件(Office Open XML 文件)的完整性?
【发布时间】:2017-01-07 05:34:35
【问题描述】:

美好的一天!

有时,Office Open XML 格式(docx、pptx、xslx)的文件的某些部分会跳动。众所周知,这些文件实际上是 ZIP 文件(可能带有特殊的压缩算法?)。

是否有任何库(最好有 C/C++ 中的示例)可以检查(不解压缩)ZIP 文件的完整性(检查存档内容的 CRC 校验和)?

【问题讨论】:

  • 欢迎来到stackoverflow。这是一个问答网站,您需要先展示您已经尝试过的所有内容,然后人们才能帮助您。请看看这个:stackoverflow.com/help/how-to-ask
  • @AnkurAggarwal 请投票关闭它作为图书馆请求。

标签: c++ zip ms-office openxml integrity


【解决方案1】:

我用过miniz:

BOOL isZipCorrect(const char *pFilename) {
  int ci;
  void *p;
  size_t uncomp_size;
  mz_bool status;
  mz_zip_archive zip_archive;
  // open the archive.
  memset(&zip_archive, 0, sizeof(zip_archive));
  status = mz_zip_reader_init_file(&zip_archive, pFilename, 0);
  if (!status) {
      return FALSE;
  }

  // go throw all files
  for (ci = 0; ci < (int)mz_zip_reader_get_num_files(&zip_archive); ci++) {
    // get information about each file in the archive
    mz_zip_archive_file_stat file_stat;
    if (!mz_zip_reader_file_stat(&zip_archive, ci, &file_stat))
    {
      mz_zip_reader_end(&zip_archive);
      return FALSE;
    }

    // try to extract this file
    p = mz_zip_reader_extract_file_to_heap(&zip_archive, file_stat.m_filename, &uncomp_size, 0);
    if (!p)
    {
      mz_zip_reader_end(&zip_archive);
      return FALSE;
    }

    // we're done.
    mz_free(p);
  }

  // close the archive, freeing any resources it was using
  mz_zip_reader_end(&zip_archive);

  // return ok state
  return TRUE;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-03
    • 2020-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多