`

AndyDecryptFile

J# 
阅读更多

BOOL AndyDecryptFile(const char* pInFile, const char* pOutFile)
{
	FILE* fpIn = fopen(pInFile, "rb");
	FILE* fpOut = fopen(pOutFile, "wb");

	BOOL bRet = TRUE;
	
	BOOL bDo = FALSE;
	int i = 0;
	int j = 0;
	int k = 0;
	int nRead = 0;

	char szIn[1024 * 2] = {0};
	char szOut[1024 * 2] = {0};
	char szRead[1024 * 2] = {0};	
	
	do 
	{
		if ( (NULL == fpIn) || (NULL == fpOut) )
		{
			bRet = FALSE;
			break;
		}		

		while (TRUE)
		{
			BOOL bEnd = FALSE;
			bDo = FALSE;

			for (i = 0; 1; i++)
			{
				if ('\0' == szRead[i])
				{
					break;
				}
				else if ('#' == szRead[i])
				{
					//重设szRead
					j = i;
					j++;//移动到#之后
					for (k = 0; '\0' != szRead[j]; k++, j++)
					{
						szRead[k] = szRead[j];
					}

					szRead[k] = '\0';

					bDo = TRUE;
					break;
				}

				szIn[i] = szRead[i];
			}

			szIn[i] = '\0';			

			if (!bDo)
			{
				nRead = fread(szRead, 1, 1024 * 2 - 1, fpIn);
				szRead[nRead] = '\0';

				if (nRead <= 0)
				{
					bEnd = TRUE;
					bDo = TRUE;
					break;
				}

                for (j = 0; j < nRead; j++)
                {
					if ('#' == szRead[j])
					{
						//重设szRead
						j++;//移动到#之后						
						for (k = 0; j < nRead; j++, k++)
						{
							szRead[k] = szRead[j];
						}

						szRead[k] = '\0';

						bDo = TRUE;
						break;
					}

					szIn[i++] = szRead[j];
                }

				szIn[i] = '\0';
			}

            long lLen = AndyDecrypt(szOut, sizeof(szOut) - 1, szIn, i);
			fwrite(szOut, lLen, 1, fpOut);

			if (bEnd)
			{
				break;
			}
		}	

	} while (0);

	if (NULL != fpIn) 
	{
		fclose(fpIn);
		fpIn = NULL;
	}

	if (NULL != fpOut)
	{
		fclose(fpOut);
		fpOut = NULL;
	}

	return bRet;
}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics