📄 parsepkg.cpp
字号:
case '@': GetNextToken(); ParsePackageL(); break; case '!': GetNextToken(); ParseOptionsBlockL(); break; case '{': GetNextToken(); ParseLanguageBlockL(); break; case '+': GetNextToken(); ParseCapabilityL(); break; case IF_TOKEN: GetNextToken(); ParseIfBlockL(); break; case ';': ParseCommentL(); break; default: return; } } }void CParsePkg::ParseLanguagesL()// Parses the language definition line { Verbage(_T("processing languages")); if(m_pSISWriter->GetNoLanguages()) throw ErrLanguagesAlreadyDefined; for(;;) { if (m_token==ALPHA_TOKEN) { // Look for the option WORD wLoop; for(wLoop = 0; wLoop < NUMLANGOPTIONS; wLoop++) { if(!wcsicmp(m_tokenValue.pszString, KLangOptions[wLoop].pszOpt)) { // found match LANGNODE *pNode = new LANGNODE; if (!pNode) throw ErrNotEnoughMemory; pNode->wLang = (WORD)KLangOptions[wLoop].dwOpt; m_pSISWriter->AddLanguageNode(pNode); break; } } if(wLoop == NUMLANGOPTIONS) throw ErrUnknownLanguagesId; } else if (m_token==NUMERIC_TOKEN && m_tokenValue.dwNumber>=0 && m_tokenValue.dwNumber<=1000) // language codes may be given as a numeric value { LANGNODE *pNode = new LANGNODE; if (!pNode) throw ErrNotEnoughMemory; pNode->wLang = (WORD)m_tokenValue.dwNumber; m_pSISWriter->AddLanguageNode(pNode); } else throw ErrUnknownLanguagesId; GetNextToken(); if (m_token!=',') return; GetNextToken(); } }void CParsePkg::ParseHeaderL()// Parses the pkg header line { Verbage(_T("processing header")); if(m_pSISWriter->AreLangStringInit()) throw ErrHeaderAlreadyDefined; // Test if there are languages defined, if there are none then add english if(!m_pSISWriter->GetNoLanguages()) { Verbage(_T("no languages defined, assuming English only")); LANGNODE *pNode = new LANGNODE; if (!pNode) throw ErrNotEnoughMemory; pNode->wLang = ELangEnglish; m_pSISWriter->AddLanguageNode(pNode); } // process application names ExpectToken('{'); for (WORD wNumLangs=0; wNumLangs<m_pSISWriter->GetNoLanguages();wNumLangs++) { GetNextToken(); ExpectToken(QUOTED_STRING_TOKEN); LANGSTRINGNODE *pLSNode = new LANGSTRINGNODE; if (!pLSNode) throw ErrNotEnoughMemory; wcscpy(pLSNode->pszString,m_tokenValue.pszString); m_pSISWriter->AddLangStringNode(pLSNode); GetNextToken(); if (wNumLangs < m_pSISWriter->GetNoLanguages()-1) ExpectToken(','); } ExpectToken('}'); GetNextToken(); // Now look for the uid & version numbers DWORD dwUID = 0L, dwBuild = 0L, dwFlags = 0L, dwType = 0L; WORD wMajor = 0, wMinor = 0; ExpectToken(','); GetNextToken(); ExpectToken('('); GetNextToken(); ExpectToken(NUMERIC_TOKEN); dwUID=m_tokenValue.dwNumber; GetNextToken(); ExpectToken(')'); GetNextToken(); ExpectToken(','); GetNextToken(); ExpectToken(NUMERIC_TOKEN); wMajor=(WORD)m_tokenValue.dwNumber; GetNextToken(); ExpectToken(','); GetNextToken(); ExpectToken(NUMERIC_TOKEN); wMinor=(WORD)m_tokenValue.dwNumber; GetNextToken(); ExpectToken(','); GetNextToken(); ExpectToken(NUMERIC_TOKEN); dwBuild=m_tokenValue.dwNumber; GetNextToken(); // Parse any options BOOL narrow=FALSE; while (m_token==',') { GetNextToken(); if (m_token==TYPE_TOKEN) { GetNextToken(); ExpectToken('='); GetNextToken(); ParseOption(KSISTypes,NUMSISTYPEOPTIONS,&dwType); } else { DWORD option=ParseOption(KHeaderOptions,NUMHEADEROPTIONS,&dwFlags); narrow=(option==0); } } // if narrow not explicitly set default to unicode if (!narrow) dwFlags|=EInstIsUnicode; m_pSISWriter->SetVersionInfo(dwUID, wMajor, wMinor, dwBuild, (TSISType)dwType, (WORD)dwFlags); }void CParsePkg::ParseFileL()// Parses a file definition line { Verbage(_T("processing file")); if(!m_pSISWriter->AreLangStringInit()) throw ErrHeaderNotDefined; PKGLINENODE *pNode = new PKGLINENODE; if (!pNode) throw ErrNotEnoughMemory; memset((void *)pNode, '\0', sizeof(PKGLINENODE)); pNode->iPackageLineType=EInstPkgLineFile; pNode->file = new PKGLINEFILE; if (!pNode->file) throw ErrNotEnoughMemory; memset((void *)pNode->file, '\0', sizeof(PKGLINEFILE)); pNode->file->type=EInstFileTypeSimple; wcscpy(pNode->file->pszSource, m_tokenValue.pszString); if (pNode->file->pszSource[0] && !DoesExist(pNode->file->pszSource, &pNode->file->dwSize)) throw ErrFileNotFound; GetNextToken(); ExpectToken('-'); GetNextToken(); ExpectToken(QUOTED_STRING_TOKEN); // BAW-5CQEA5 Check for invalid destination (i.e starts with ':') if ( wcslen(m_tokenValue.pszString) > 0 && m_tokenValue.pszString[0] == ':' ) throw ErrBadDestinationPath; // ANN-5ESFPV If there is no drive specified, assume it's C: if ((wcslen(m_tokenValue.pszString) < 3) || (m_tokenValue.pszString[1] != ':') || (m_tokenValue.pszString[2] != '\\')) {// The drive is not specified, we will assume the user meant C: wcscpy(pNode->file->pszDest, L"c:\\"); wcscat(pNode->file->pszDest, m_tokenValue.pszString); } else { wcscpy(pNode->file->pszDest, m_tokenValue.pszString); } GetNextToken(); // Test for options if (m_token==',') { DWORD type=0; GetNextToken(); ParseOption(KTypeOptions,NUMTYPEOPTIONS, &type); pNode->file->type=(TInstFileType)type; if (pNode->file->type==EInstFileTypeMime) { ExpectToken(','); GetNextToken(); ExpectToken(QUOTED_STRING_TOKEN); wcscpy(pNode->file->pszMimeType, m_tokenValue.pszString); GetNextToken(); } if (m_token==',') { DWORD options=0; switch (pNode->file->type) { case EInstFileTypeText: GetNextToken(); ParseOption(KTextOptions,NUMTEXTOPTIONS, &options); pNode->file->options.iTextOption=(TInstFileTextOption)options; pNode->file->pszDest[0]='\0'; break; case EInstFileTypeRun: GetNextToken(); ParseOption(KRunOptions,NUMRUNOPTIONS, &options); if (m_token==',') { GetNextToken(); ParseOption(KCtrlOptions,NUMCTRLOPTIONS, &options); } // if running when uninstall then must use wait end option if (options&(EInstFileRunOptionRemoveOnly|EInstFileRunOptionInstallAndRemove) && !(options&EInstRunWaitEnd)) throw ErrUninstallNeedsWaitEnd; pNode->file->options.iRunOption=(TInstFileRunOption)options; break; case EInstFileTypeMime: GetNextToken(); ParseOption(KCtrlOptions,NUMCTRLOPTIONS, &options); pNode->file->options.iMimeOption=(TInstFileMimeOption)options; break; default: throw ErrBadOption; break; } } } // Test that the file exists if(pNode->file->type==EInstFileTypeNull) { pNode->file->dwSize = 0; pNode->file->pszSource[0]='\0'; } m_pSISWriter->AddPkgLineNode(pNode); }void CParsePkg::ParsePackageL()// Parses a package (component SIS file) line { Verbage(_T("processing embedded package file")); if(!m_pSISWriter->AreLangStringInit()) throw ErrHeaderNotDefined; PKGLINENODE *pNode = new PKGLINENODE; if (!pNode) throw ErrNotEnoughMemory; memset((void *)pNode, '\0', sizeof(PKGLINENODE)); pNode->iPackageLineType=EInstPkgLineFile; pNode->file = new PKGLINEFILE; if (!pNode->file) throw ErrNotEnoughMemory; memset((void *)pNode->file, '\0', sizeof(PKGLINEFILE)); pNode->file->type=EInstFileTypeComponent; ExpectToken(QUOTED_STRING_TOKEN); if (!FullPath(pNode->file->pszSource, m_tokenValue.pszString, MAX_PATH)) { throw ErrCannotGetFullPath; } // Test that the file exists if(!DoesExist(pNode->file->pszSource, &pNode->file->dwSize)) throw ErrFileNotFound; GetNextToken(); ExpectToken(','); GetNextToken(); ExpectToken('('); GetNextToken(); ExpectToken(NUMERIC_TOKEN); pNode->file->options.iComponentUid=m_tokenValue.dwNumber; GetNextToken(); ExpectToken(')'); GetNextToken(); // Check that the UID given in the PKG file is the same as the UID of the SIS // file we are embedding HANDLE hEmbeddedFile = ::MakeSISOpenFile(pNode->file->pszSource, GENERIC_READ, OPEN_EXISTING); if (hEmbeddedFile == INVALID_HANDLE_VALUE) { throw ErrReadFailed; } else { int embeddedUID; unsigned long numberOfBytesRead; int ok = ReadFile(hEmbeddedFile, (void*)&embeddedUID, sizeof(embeddedUID), &numberOfBytesRead,NULL); if (!ok) { throw ErrReadFailed; } if (embeddedUID != pNode->file->options.iComponentUid) { throw ErrUIDMismatch; } CloseHandle(hEmbeddedFile); } // Test that the filename is *.SIS if(wcsicmp(&pNode->file->pszSource[wcslen(pNode->file->pszSource) - wcslen(DESTFILE)], DESTFILE)) throw ErrPackageNotASISFile; pNode->file->pszDest[0] = '\0'; m_pSISWriter->AddPkgLineNode(pNode); }void CParsePkg::ParseDependencyL()// Parses a dependency line { Verbage(_T("processing dependency")); if(!m_pSISWriter->AreLangStringInit()) throw ErrHeaderNotDefined; DEPENDNODE *pNode = new DEPENDNODE; if (!pNode) throw ErrNotEnoughMemory; memset((void *)pNode, '\0', sizeof(DEPENDNODE)); ExpectToken(NUMERIC_TOKEN); pNode->dwUID=m_tokenValue.dwNumber; GetNextToken(); ExpectToken(')'); GetNextToken(); ExpectToken(','); GetNextToken(); ExpectToken(NUMERIC_TOKEN); pNode->wMajor=(WORD)m_tokenValue.dwNumber; GetNextToken(); ExpectToken(','); GetNextToken(); ExpectToken(NUMERIC_TOKEN); pNode->wMinor=(WORD)m_tokenValue.dwNumber; GetNextToken(); ExpectToken(','); GetNextToken(); ExpectToken(NUMERIC_TOKEN); pNode->dwBuild=m_tokenValue.dwNumber; GetNextToken(); ExpectToken(','); GetNextToken(); ExpectToken('{'); WORD wNumLangs = 0; while(wNumLangs < m_pSISWriter->GetNoLanguages()) { GetNextToken(); ExpectToken(QUOTED_STRING_TOKEN); LANGSTRINGNODE *pLSNode = new LANGSTRINGNODE; if (!pLSNode) throw ErrNotEnoughMemory; memset((void *)pLSNode, '\0', sizeof(LANGSTRINGNODE)); wcscpy(pLSNode->pszString,m_tokenValue.pszString); GetNextToken(); if(wNumLangs < (m_pSISWriter->GetNoLanguages() - 1)) ExpectToken(','); pLSNode->pNext = pNode->pLangStringBase; pNode->pLangStringBase = pLSNode; wNumLangs++; } ExpectToken('}'); GetNextToken(); m_pSISWriter->AddDependencyNode(pNode); }void CParsePkg::ParseSignatureL(){ // Parses the package-signature Verbage(_T("processing signature")); if(!m_pSISWriter->AreLangStringInit()) throw ErrHeaderNotDefined; // If generating a stub file then once have signature line don't need to // process rest of PKG file m_enoughForStub=TRUE; ExpectToken(QUOTED_STRING_TOKEN); SIGNATURENODE* pSig = new SIGNATURENODE; if (!pSig) throw ErrNotEnoughMemory; memset((void *)pSig, '\0', sizeof(SIGNATURENODE)); wcscpy(pSig->pszPrivateKey,m_tokenValue.pszString); pSig->iNumCerts = 1; //get a temporary filename for creating certificate chain LPWSTR pszTempChain; pszTempChain = TempFileName(L"chain.cer"); wcscpy(pSig->pszChainFile, pszTempChain); //get a temporary filename for Base64 decoding LPWSTR pszTempB64; pszTempB64 = TempFileName(L"temp.bin"); wcscpy(pSig->pszB64File, pszTempB64); GetNextToken(); ExpectToken(','); GetNextToken(); ExpectToken(QUOTED_STRING_TOKEN); wcscpy(pSig->pszPublicKey,m_tokenValue.pszString); DWORD dwSize; // Test that the files exist if (!DoesExist(pSig->pszPrivateKey, &dwSize) || !DoesExist(pSig->pszPublicKey, &dwSize)) throw ErrFileNotFound;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -