/***************************************************************************** BOOL EnterHashMode(lFILEINFO *fileList, UINT uiMode) fileList : (IN/OUT) pointer to the job structure whose files are to be processed uiMode : (IN) type of hash file Return Value: returns TRUE if everything went fine. FALSE went something went wrong. Notes: - takes fileList->fInfos.front().szFilename as .sha1 file and creates new list entries based on that *****************************************************************************/ BOOL EnterHashMode(lFILEINFO *fileList, UINT uiMode) { #ifdef UNICODE CHAR szLineAnsi[MAX_LINE_LENGTH]; #endif TCHAR szLine[MAX_LINE_LENGTH]; TCHAR szFilenameHash[MAX_PATH_EX]; HANDLE hFile; UINT uiStringLength; BOOL bErrorOccured, bEndOfFile; BOOL fileIsUTF16; UINT codePage; UNICODE_TYPE detectedBOM; FILEINFO fileinfoTmp = {0}; // save hash filename and path // => g_szBasePath in is the path part of the complete filename of the .xyz file StringCchCopy(szFilenameHash, MAX_PATH_EX, fileList->fInfos.front().szFilename); StringCchCopy(fileList->g_szBasePath, MAX_PATH_EX, szFilenameHash); ReduceToPath(fileList->g_szBasePath); if(fileList->uiCmdOpts==CMD_REPARENT) { TCHAR szReparentPath[MAX_PATH_EX]; LPITEMIDLIST iidl=NULL; BROWSEINFO bInfo = {0}; bInfo.lpszTitle = TEXT("Select folder for reparenting"); bInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_USENEWUI; bInfo.lpfn = BrowseFolderSetSelProc; bInfo.lParam = (LPARAM)(fileList->g_szBasePath + 4); if(iidl=SHBrowseForFolder(&bInfo)) { SHGetPathFromIDList(iidl,szReparentPath); CoTaskMemFree(iidl); StringCchPrintf(fileList->g_szBasePath, MAX_PATH_EX, TEXT("\\\\?\\%s\\"),szReparentPath); if(fileList->g_szBasePath[lstrlen(fileList->g_szBasePath) - 2] == TEXT('\\')) fileList->g_szBasePath[lstrlen(fileList->g_szBasePath) - 1] = TEXT('\0'); } } // set mode fileList->uiRapidCrcMode = uiMode; // free everything we did so far fileList->fInfos.clear(); hFile = CreateFile(szFilenameHash, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_SEQUENTIAL_SCAN , 0); if(hFile == INVALID_HANDLE_VALUE) { MessageBox(NULL, TEXT("Hash file could not be read"), TEXT("Error"), MB_ICONERROR | MB_OK); return FALSE; } // check for the BOM and read accordingly detectedBOM = CheckForBOM(hFile); fileIsUTF16 = (detectedBOM == UTF_16LE); if(!fileIsUTF16) { if(detectedBOM==UTF_8_BOM) codePage = CP_UTF8; else if(g_program_options.bUseDefaultCP) codePage = g_program_options.uiDefaultCP; else codePage = DetermineFileCP(hFile); } GetNextLine(hFile, szLine, MAX_LINE_LENGTH, & uiStringLength, &bErrorOccured, &bEndOfFile, fileIsUTF16); if(bErrorOccured) { MessageBox(NULL, TEXT("Hash file could not be read"), TEXT("Error"), MB_ICONERROR | MB_OK); return FALSE; } while( !(bEndOfFile && uiStringLength == 0) ) { #ifdef UNICODE // if we already read unicode characters we don't need the conversion here if(!fileIsUTF16) { AnsiFromUnicode(szLineAnsi,MAX_LINE_LENGTH,szLine); MultiByteToWideChar(codePage, // ANSI Codepage 0, // we use no flags; ANSI isn't a 'real' MBCC szLineAnsi, // the ANSI String -1, // ANSI String is 0 terminated szLine, // the UNICODE destination string MAX_LINE_LENGTH ); // size of the UNICODE String in chars uiStringLength = lstrlen(szLine); } #endif switch(uiMode) { case MODE_SFV: InterpretSFVLine(szLine, uiStringLength, fileList); break; case MODE_MD5: case MODE_SHA1: case MODE_SHA256: case MODE_SHA512: InterpretMDSHALine(szLine, uiStringLength, uiMode, fileList); break; case MODE_BSD: InterpretBSDLine(szLine, uiStringLength, fileList); break; } GetNextLine(hFile, szLine, MAX_LINE_LENGTH, & uiStringLength, &bErrorOccured, &bEndOfFile, fileIsUTF16); if(bErrorOccured) { MessageBox(NULL, TEXT("Hash file could not be read"), TEXT("Error"), MB_ICONERROR | MB_OK); fileList->fInfos.clear(); return FALSE; } } CloseHandle(hFile); return TRUE; }
void XMLParser::ParseMessage(CString& p_message,WhiteSpace p_whiteSpace /*=PRESERVE_WHITESPACE*/) { // Remember parsing mode m_whiteSpace = p_whiteSpace; // Check if we have something to do if(m_message == nullptr || p_message.IsEmpty()) { SetError(XmlError::XE_EmptyXML,(uchar*)"Empty message",false); return; } // Initialize the parsing pointer m_pointer = (uchar*) p_message.GetString(); // Check for Byte-Order-Mark first BOMType bomType = BOMType::BT_NO_BOM; unsigned int skip = 0; BOMOpenResult bomResult = CheckForBOM(m_pointer,bomType,skip); if(bomResult != BOMOpenResult::BOR_NoBom) { if(bomType != BOMType::BT_BE_UTF8) { // cannot process these strings SetError(XmlError::XE_IncompatibleEncoding,(uchar*)"Incompatible Byte-Order-Mark encoding",false); return; } m_message->m_encoding = XMLEncoding::ENC_UTF8; m_message->m_sendBOM = true; m_utf8 = true; // Skip past BOM m_pointer += skip; } // MAIN PARSING LOOP try { // Parse an XML level ParseLevel(); // Checks after parsing if(m_message->m_root->GetName().IsEmpty()) { // Minimum requirement of an XML message SetError(XmlError::XE_NoRootElement,(uchar*)"Missing root element of XML message"); } if(*m_pointer) { SetError(XmlError::XE_ExtraText,m_pointer); } } catch(XmlError& error) { // Error message text already set m_message->m_internalError = error; } // Conclusion of condensed level m_message->SetCondensed(m_spaces < m_elements); }