Esempio n. 1
0
/*****************************************************************************
BOOL GetCrcFromFilename(TCHAR szFilename[MAX_PATH], DWORD * pdwFoundCrc)
	szFilename		: (IN) string; assumed to be the szFilenameShort member of the
						   FILEINFO struct
	pdwFoundCrc		: (OUT) return value is TRUE this parameter is set to the found
							CRC32 as a DWORD

Return Value:
	returns TRUE if a CRC was found in the filename. Otherwise FALSE

Notes:
	- walks through a filename from the rear to the front.
	- if a ']' or ')' is found we check if 9 chars before is an '[' or '(' and if
	  there are 8 legal Hex characters in between (via IsLegalHexSymbol)
*****************************************************************************/
BOOL GetCrcFromFilename(CONST TCHAR szFilename[MAX_PATH], DWORD * pdwFoundCrc)
{
	size_t StringSize;
	INT iIndex;
	BOOL bFound;
	TCHAR szCrc[9];
	TCHAR szFileWithoutPath[MAX_PATH];

	StringCchCopy(szFileWithoutPath, MAX_PATH, GetFilenameWithoutPathPointer(szFilename));

	if(FAILED(StringCchLength(szFileWithoutPath, MAX_PATH, &StringSize)))
		return FALSE;

	if(StringSize == 0)
		return FALSE;
	
	iIndex = (int)StringSize;
	bFound = FALSE;
	do{
		--iIndex;
		if((szFileWithoutPath[iIndex] == TEXT(']')) || (szFileWithoutPath[iIndex] == TEXT(')')) )
		{
			if ((iIndex - 9) < 0)
				break;
			else{
				bFound = TRUE;
				if (! ((szFileWithoutPath[iIndex-9] == TEXT('[')) || (szFileWithoutPath[iIndex-9] == TEXT('(')) ) )
					bFound = FALSE;
				for(int i=1; i <= 8; ++i)
					if(! IsLegalHexSymbol(szFileWithoutPath[iIndex-i]))
						bFound = FALSE;
				if(bFound)
					iIndex -= 8;
			}
		}
	}
	while((iIndex > 0) && (!bFound));

	if(!bFound)
		return FALSE;
	
	StringCchCopyN(szCrc, 9, szFileWithoutPath + iIndex, 8);
	(*pdwFoundCrc) = HexToDword(szCrc, 8);

	return TRUE;
}
Esempio n. 2
0
BOOL InterpretMDSHALine(TCHAR *szLine, UINT uiStringLength, UINT uiMode, lFILEINFO *fileList)
{
    UINT    uiHashLengthChars = g_hash_lengths[uiMode] * 2;
    UINT	uiIndex;
    BOOL	bHashOK, bWasAbsolute = FALSE;

    FILEINFO fileinfoTmp = {0};
    fileinfoTmp.parentList=fileList;

    if(uiStringLength < uiHashLengthChars)
        return FALSE;

    if( IsLegalHexSymbol(szLine[0]) ){
	    bHashOK = TRUE;
	    for(uiIndex=0; uiIndex < uiHashLengthChars; ++uiIndex)
		    if(! IsLegalHexSymbol(szLine[uiIndex]))
			    bHashOK = FALSE;
	    if(bHashOK){
		    fileinfoTmp.hashInfo[uiMode].dwFound = TRUE;
		    for(uiIndex=0; uiIndex < g_hash_lengths[uiMode]; ++uiIndex)
			    *((BYTE *)&fileinfoTmp.hashInfo[uiMode].f + uiIndex) = (BYTE)HexToDword(szLine + uiIndex * 2, 2);
		    fileinfoTmp.dwError = NOERROR;
	    }
	    else
		    fileinfoTmp.dwError = APPL_ERROR_ILLEGAL_CRC;

	    //delete trailing spaces
	    while(szLine[uiStringLength - 1] == TEXT(' ')){
		    szLine[uiStringLength - 1] = NULL;
		    uiStringLength--;
	    }

	    //find leading spaces and '*'
	    uiIndex = uiHashLengthChars; // szLine[uiHashLengthChars] is the first char after the hash
	    while( (uiIndex < uiStringLength) && ((szLine[uiIndex] == TEXT(' ')) || (szLine[uiIndex] == TEXT('*'))) )
		    uiIndex++;

        ReplaceChar(szLine, MAX_PATH_EX, TEXT('/'), TEXT('\\'));

        bWasAbsolute = !ConstructCompleteFilename(fileinfoTmp.szFilename, fileList->g_szBasePath, szLine + uiIndex);

	    fileList->fInfos.push_back(fileinfoTmp);
    }

    return bWasAbsolute;
}
Esempio n. 3
0
BOOL InterpretSFVLine(TCHAR *szLine, UINT uiStringLength, lFILEINFO *fileList, UINT uiHashMode)
{
    BOOL	bCrcOK, bWasAbsolute = FALSE;

    FILEINFO fileinfoTmp = {0};
    fileinfoTmp.parentList=fileList;

    if(uiStringLength < 9)
        return FALSE;

    //delete trailing spaces
	while( (szLine[uiStringLength - 1] == TEXT(' ')) && (uiStringLength > 8) ){
		szLine[uiStringLength - 1] = NULL;
		uiStringLength--;
	}

	if( (szLine[0] != TEXT(';')) && (szLine[0] != TEXT('\0')) ){
		bCrcOK = TRUE;
		for(int i=1; i <= 8; ++i)
			if(! IsLegalHexSymbol(szLine[uiStringLength-i]))
				bCrcOK = FALSE;
		if(bCrcOK){
            fileinfoTmp.hashInfo[uiHashMode].dwFound = HASH_FOUND_FILE;
            fileinfoTmp.hashInfo[uiHashMode].f.dwCrc32Found = HexToDword(szLine + uiStringLength - 8, 8);
			fileinfoTmp.dwError = NOERROR;
		}
		else
			fileinfoTmp.dwError = APPL_ERROR_ILLEGAL_CRC;

		uiStringLength -= 8;
		szLine[uiStringLength] = NULL; // keep only the filename
		//delete trailing spaces
		while( (szLine[uiStringLength - 1] == TEXT(' ')) && (uiStringLength > 0) ){
			szLine[uiStringLength - 1] = NULL;
			uiStringLength--;
		}

        ReplaceChar(szLine, MAX_PATH_EX, TEXT('/'), TEXT('\\'));

        bWasAbsolute = !ConstructCompleteFilename(fileinfoTmp.szFilename, fileList->g_szBasePath, szLine);

		fileList->fInfos.push_back(fileinfoTmp);
	}

    return bWasAbsolute;
}
Esempio n. 4
0
void InterpretBSDLine(TCHAR *szLine, UINT uiStringLength, lFILEINFO *fileList)
{
    BOOL	bHashOK;
    int     iHashIndex = -1;

    FILEINFO fileinfoTmp = {0};
    fileinfoTmp.parentList=fileList;

    if(uiStringLength < 5)
        return;

    for(int i=0; i < NUM_HASH_TYPES; i++) {
        if(!_tcsncmp(szLine, g_hash_names[i], lstrlen(g_hash_names[i]))) {
            iHashIndex = i;
            break;
        }
    }
    if(iHashIndex<0)
        return;

    TCHAR *szFirstBrace = _tcschr(szLine, TEXT('('));
    TCHAR *szLastBrace = _tcsrchr(szLine, TEXT(')'));
    if(!szFirstBrace || !szLastBrace || szFirstBrace > szLastBrace)
        return;

    *szLastBrace = TEXT('\0');
    szLastBrace++;
    fileinfoTmp.szFilename.Format(TEXT("%s%s"), fileList->g_szBasePath, szFirstBrace + 1);
    fileinfoTmp.szFilename.Replace(TEXT("/"), TEXT("\\"));

    while(!IsLegalHexSymbol(*szLastBrace) && *szLastBrace != TEXT('\0') )
        szLastBrace++;

    UINT    uiHashLengthChars = g_hash_lengths[iHashIndex] * 2;

    if(lstrlen(szLastBrace) < uiHashLengthChars)
        return;

    FILEINFO *fileInfo = &fileinfoTmp;
    bool alreadyInList = false;
    for(list<FILEINFO>::reverse_iterator it = fileList->fInfos.rbegin(); it != fileList->fInfos.rend(); it++) {
        if(it->szFilename == fileinfoTmp.szFilename) {
            fileInfo = &(*it);
            alreadyInList = true;
            break;
        }
    }

    if( IsLegalHexSymbol(*szLastBrace) ) {
        bHashOK = TRUE;
        for(UINT uiIndex=0; uiIndex < uiHashLengthChars; ++uiIndex)
            if(! IsLegalHexSymbol(szLastBrace[uiIndex]))
                bHashOK = FALSE;
        if(bHashOK) {
            fileInfo->hashInfo[iHashIndex].dwFound = TRUE;
            if(iHashIndex == HASH_TYPE_CRC32) {
                fileInfo->hashInfo[HASH_TYPE_CRC32].f.dwCrc32Found = HexToDword(szLastBrace, 8);
            } else {
                for(UINT uiIndex=0; uiIndex < g_hash_lengths[iHashIndex]; ++uiIndex)
                    *((BYTE *)&fileInfo->hashInfo[iHashIndex].f + uiIndex) = (BYTE)HexToDword(szLastBrace + uiIndex * 2, 2);
            }
            fileInfo->dwError = NOERROR;
        }
        else
            fileInfo->dwError = APPL_ERROR_ILLEGAL_CRC;
        if(!alreadyInList)
            fileList->fInfos.push_back(fileinfoTmp);
        fileList->bDoCalculate[iHashIndex] = true;
    }
}