Exemplo n.º 1
0
int main()
{
    char *fileName = "book.txt";
    char *zipFileName = "encoded.txt";
    char *unzipFileName = "decoded.txt";
    char mode;
SELECT:
    puts("Please enter 1 or 2 to select mode, 1 for code,2 for decode,3 to exit now~>_<:");
    mode=getchar();
    if (mode == '1')
    {

        ZipFile(fileName, zipFileName);
        printf("Ziped file was saved.\n");
        getchar();
        goto SELECT;
    }
    else if (mode =='2')
    {
        UnzipFile(zipFileName, unzipFileName);
        getchar();/*读走缓存区的回车*/
    }
    else if (mode=='3')
    {
        exit(0);
    }
    return 0;
}
Exemplo n.º 2
0
int TRI_UnzipFile(char const* filename, char const* outPath,
                  bool skipPaths, bool overwrite,
                  char const* password, std::string& errorMessage) {
#ifdef USEWIN32IOAPI
  zlib_filefunc64_def ffunc;
#endif
  size_t bufferSize = 16384;
  void* buffer = (void*)TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, bufferSize, false);

  if (buffer == nullptr) {
    return TRI_ERROR_OUT_OF_MEMORY;
  }

#ifdef USEWIN32IOAPI
  fill_win32_filefunc64A(&ffunc);
  unzFile uf = unzOpen2_64(filename, &ffunc);
#else
  unzFile uf = unzOpen64(filename);
#endif
  if (uf == nullptr) {
    errorMessage = std::string("unable to open zip file ") + filename;
    return TRI_ERROR_INTERNAL;
  }

  int res = UnzipFile(uf, buffer, bufferSize, outPath, skipPaths, overwrite,
                      password, errorMessage);

  unzClose(uf);

  TRI_Free(TRI_UNKNOWN_MEM_ZONE, buffer);

  return res;
}
Exemplo n.º 3
0
BOOL CUnzipper::UnzipFile(int nFile, LPCTSTR szFolder, BOOL bIgnoreFilePath)
{
	if (!m_uzFile)
		return FALSE;

	if (!szFolder)
		szFolder = m_szOutputFolder;

	if (!GotoFile(nFile))
		return FALSE;

	return UnzipFile(szFolder, bIgnoreFilePath);
}
Exemplo n.º 4
0
int main()
{
    /*进行功能选择*/
    char *fileName = "book.txt";
    char *zipFileName = "encoded.txt";
    char *unzipFileName = "decoded.txt";
    char mode;
    while(1)
    {
        puts("Please enter 1 or 2 to select mode, 1 for encode,2 for decode,3 to exit now:");
        puts("fff");
        mode=getchar();
        if (mode == '1')
        {
            int x=ZipFile(fileName, zipFileName);
            if(x==1)continue;
            printf("Coded! Ziped file was saved.\n");
            getchar();/*读走缓存区的回车*/
        }
        else if (mode =='2')
        {
            int x=UnzipFile(zipFileName, unzipFileName);
            if(x==1)continue;
            getchar();/*读走缓存区的回车*/
        }
        else if (mode=='3')
        {
            exit(0);
        }
        else
        {
            puts("Unexpected input!\n");
            getchar();/*读走缓存区的回车*/
        }
    }
    return 0;
}
Exemplo n.º 5
0
int TRI_UnzipFile (const char* filename,
                   const char* outPath, 
                   const bool skipPaths,
                   const bool overwrite,
                   const char* password) {
  unzFile uf;
#ifdef USEWIN32IOAPI
  zlib_filefunc64_def ffunc;
#endif
  void* buffer;
  size_t bufferSize;
  int res;
  
  bufferSize = 16384;
  buffer = (void*) TRI_Allocate(TRI_UNKNOWN_MEM_ZONE, bufferSize, false);

  if (buffer == NULL) {
    return TRI_ERROR_OUT_OF_MEMORY;
  }


#ifdef USEWIN32IOAPI
  fill_win32_filefunc64A(&ffunc);
  uf = unzOpen2_64(filename, &ffunc);
#else
  uf = unzOpen64(filename);
#endif

  res = UnzipFile(uf, buffer, bufferSize, outPath, skipPaths, overwrite, password);

  unzClose(uf);

  TRI_Free(TRI_UNKNOWN_MEM_ZONE, buffer);

  return res;
}
Exemplo n.º 6
0
BOOL CUnzipper::UnzipTo(LPCTSTR szFolder, BOOL bIgnoreFilePath)
{
	if (!m_uzFile)
		return FALSE;

	if (!szFolder || !CreateFolder(szFolder))
		return FALSE;

	if (GetFileCount() == 0)
		return FALSE;

	if (!GotoFirstFile())
		return FALSE;

	// else
	do
	{
		if (!UnzipFile(szFolder, bIgnoreFilePath))
			return FALSE;
	}
	while (GotoNextFile());
	
	return TRUE;
}
Exemplo n.º 7
0
crpOpenErrorReportW(
                    LPCWSTR pszFileName,
                    LPCWSTR pszMd5Hash,
                    LPCWSTR pszSymSearchPath,
                    DWORD dwFlags,
                    CrpHandle* pHandle)
{   
    UNREFERENCED_PARAMETER(dwFlags);

    int status = -1;
    int nNewHandle = 0;
    CrpReportData report_data;  
    int zr = 0;
    int xml_find_res = UNZ_END_OF_LIST_OF_FILE;
    int dmp_find_res = UNZ_END_OF_LIST_OF_FILE;
    char szXmlFileName[1024]="";
    char szDmpFileName[1024]="";
    char szFileName[1024]="";
    CString sCalculatedMD5Hash;
    CString sAppName;
    strconv_t strconv;

    crpSetErrorMsg(_T("Unspecified error."));
    *pHandle = 0;

    report_data.m_sSymSearchPath = pszSymSearchPath;
    report_data.m_pDescReader = new CCrashDescReader;
    report_data.m_pDmpReader = new CMiniDumpReader;

    // Check dbghelp.dll version
    if(!report_data.m_pDmpReader->CheckDbgHelpApiVersion())
    {
        crpSetErrorMsg(_T("Invalid dbghelp.dll version (v6.11 expected)."));
        goto exit; // Invalid hash
    }

    // Check ZIP integrity
    if(pszMd5Hash!=NULL)
    {
        int result = CalcFileMD5Hash(pszFileName, sCalculatedMD5Hash);
        if(result!=0)
            goto exit;

        if(sCalculatedMD5Hash.CompareNoCase(pszMd5Hash)!=0)
        {  
            crpSetErrorMsg(_T("File might be corrupted, because MD5 hash is wrong."));
            goto exit; // Invalid hash
        }
    }

    // Open ZIP archive
    report_data.m_hZip = unzOpen((const char*)pszFileName);
    if(report_data.m_hZip==NULL)
    {
        crpSetErrorMsg(_T("Error opening ZIP archive."));
        goto exit;
    }

    // Look for v1.1 crash description XML
    xml_find_res = unzLocateFile(report_data.m_hZip, (const char*)"crashrpt.xml", 1);
    zr = unzGetCurrentFileInfo(report_data.m_hZip, NULL, szXmlFileName, 1024, NULL, 0, NULL, 0);

    // Look for v1.1 crash dump 
    dmp_find_res = unzLocateFile(report_data.m_hZip, (const char*)"crashdump.dmp", 1);
    zr = unzGetCurrentFileInfo(report_data.m_hZip, NULL, szDmpFileName, 1024, NULL, 0, NULL, 0);

    // If xml and dmp still not found, assume it is v1.0
    if(xml_find_res!=UNZ_OK && dmp_find_res!=UNZ_OK)  
    {    
        // Look for .dmp file
        zr = unzGoToFirstFile(report_data.m_hZip);
        if(zr==UNZ_OK)
        {
            for(;;)
            {        
                zr = unzGetCurrentFileInfo(report_data.m_hZip, NULL, szDmpFileName, 1024, NULL, 0, NULL, 0);
                if(zr!=UNZ_OK)
                    break;

                CString sFileName = szDmpFileName;

                CString sExt = Utility::GetFileExtension(sFileName);
                if(sExt.CompareNoCase(_T("dmp"))==0)
                {
                    // DMP found
                    sAppName = Utility::GetBaseFileName(sFileName);
                    dmp_find_res = UNZ_OK;
                    break;
                }

                zr=unzGoToNextFile(report_data.m_hZip);
                if(zr!=UNZ_OK)
                    break;
            }
        }

        // Assume the name of XML is the same as DMP
        CString sXmlName = Utility::GetBaseFileName(CString(szDmpFileName)) + _T(".xml");
        zr = unzLocateFile(report_data.m_hZip, strconv.t2a(sXmlName), 1);
        zr = unzGetCurrentFileInfo(report_data.m_hZip, NULL, szXmlFileName, 1024, NULL, 0, NULL, 0);
        if(zr==UNZ_OK)
        {
            xml_find_res = UNZ_OK;
        }
    }

    // Check that both xml and dmp found
    if(xml_find_res!=UNZ_OK || dmp_find_res!=UNZ_OK)
    {
        crpSetErrorMsg(_T("File is not a valid crash report (XML or DMP missing)."));
        goto exit; // XML or DMP not found 
    }

    // Load crash description data
    if(xml_find_res==UNZ_OK)
    {
        CString sTempFile = Utility::getTempFileName();
        zr = UnzipFile(report_data.m_hZip, szXmlFileName, sTempFile);
        if(zr!=0)
        {
            crpSetErrorMsg(_T("Error extracting ZIP item."));
            Utility::RecycleFile(sTempFile, TRUE);
            goto exit; // Can't unzip ZIP element
        }

        int result = report_data.m_pDescReader->Load(sTempFile);    
        DeleteFile(sTempFile);
        if(result!=0)
        {
            crpSetErrorMsg(_T("Crash description file is not a valid XML file."));
            goto exit; // Corrupted XML
        }    
    }  

    // Extract minidump file
    if(dmp_find_res==UNZ_OK)
    {
        CString sTempFile = Utility::getTempFileName();
        zr = UnzipFile(report_data.m_hZip, szDmpFileName, sTempFile);
        if(zr!=0)
        {
            Utility::RecycleFile(sTempFile, TRUE);
            crpSetErrorMsg(_T("Error extracting ZIP item."));
            goto exit; // Can't unzip ZIP element
        }

        report_data.m_sMiniDumpTempName = sTempFile;
    } 

    if(report_data.m_pDescReader->m_dwGeneratorVersion==1000)
    {
        // Check if appname is empty (this may be true for v1.0 reports)
        if(report_data.m_pDescReader->m_sAppName.IsEmpty())
            report_data.m_pDescReader->m_sAppName = sAppName;

        // Check if app version is empty (this may be true for v1.0 reports)
        if(report_data.m_pDescReader->m_sAppVersion.IsEmpty() ||
            report_data.m_pDescReader->m_sImageName.IsEmpty())
        {
            // Load minidump right now
            int nLoad = report_data.m_pDmpReader->Open(report_data.m_sMiniDumpTempName, 
                report_data.m_sSymSearchPath);
            if(nLoad!=0)
            {
                crpSetErrorMsg(_T("Error opening minidump file."));
                Utility::RecycleFile(report_data.m_sMiniDumpTempName, TRUE);
                goto exit; 
            }

            // Find the candidate for application's executable module
            CMiniDumpReader* pDmpReader = report_data.m_pDmpReader;
            int nExeModuleIndx = -1;
            UINT i;
            for(i=0; i<pDmpReader->m_DumpData.m_Modules.size(); i++)
            {
                CString sModuleName = pDmpReader->m_DumpData.m_Modules[i].m_sModuleName;
                CString sBaseName = Utility::GetBaseFileName(sModuleName);
                CString sExt = Utility::GetFileExtension(sModuleName);
                if(sBaseName.CompareNoCase(report_data.m_pDescReader->m_sAppName)==0 &&
                    sExt.CompareNoCase(_T("exe"))==0)
                {
                    nExeModuleIndx = i;
                    break;
                }
            }
            if(nExeModuleIndx>=0)
            {
                if(report_data.m_pDescReader->m_sImageName.IsEmpty())
                {
                    report_data.m_pDescReader->m_sImageName =
                        pDmpReader->m_DumpData.m_Modules[i].m_sImageName;
                }

                if(report_data.m_pDescReader->m_sAppVersion.IsEmpty())
                {
                    VS_FIXEDFILEINFO* fi = pDmpReader->m_DumpData.m_Modules[i].m_pVersionInfo;
                    if(fi!=NULL)
                    {
                        WORD dwVerMajor = (WORD)(fi->dwProductVersionMS>>16);
                        WORD dwVerMinor = (WORD)(fi->dwProductVersionMS&0xFF);
                        WORD dwPatchLevel = (WORD)(fi->dwProductVersionLS>>16);
                        WORD dwVerBuild = (WORD)(fi->dwProductVersionLS&0xFF);

                        report_data.m_pDescReader->m_sAppVersion.Format(_T("%u.%u.%u.%u"), 
                            dwVerMajor, dwVerMinor, dwPatchLevel, dwVerBuild);            
                    }
                }
            }