Remove duplicated code

This commit is contained in:
Oleg Korshul
2023-11-23 22:39:26 +03:00
parent 4988c1853e
commit 6ebdc0f530
6 changed files with 580 additions and 1309 deletions

View File

@ -65,7 +65,7 @@ std::string ReadStringFromOle(POLE::Stream *stream, unsigned int max_size)
if (cch > max_size)
{
// error ... skip to 0
unsigned int pos_orinal = stream->tell();
unsigned int pos_orinal = (unsigned int)stream->tell();
unsigned int pos = 0;
stream->read(stringBytes, max_size);
@ -83,7 +83,7 @@ std::string ReadStringFromOle(POLE::Stream *stream, unsigned int max_size)
if (cch > 0)
{
// dont read the terminating zero
cch = stream->read(stringBytes, cch);
cch = (_UINT32)stream->read(stringBytes, cch);
result = std::string((char *)stringBytes, cch);
}
}
@ -243,7 +243,7 @@ bool COfficeFileFormatChecker::isPdfFormatFile(unsigned char *pBuffer, int dwByt
if (NULL != pLast)
{
std::string s(pFirst, pLast - pFirst);
documentID = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE *)s.c_str(), s.length());
documentID = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE*)pFirst, (LONG)(pLast - pFirst));
}
}
return true;
@ -300,17 +300,17 @@ bool COfficeFileFormatChecker::isOleObjectFile(POLE::Storage *storage)
{
streamCompObject.seek(28); // skip Header
unsigned int sz_obj = streamCompObject.size() - streamCompObject.tell();
unsigned int sz_obj = (unsigned int)(streamCompObject.size() - streamCompObject.tell());
if (sz_obj > 4)
{
UserType = ReadStringFromOle(&streamCompObject, sz_obj);
sz_obj = streamCompObject.size() - streamCompObject.tell();
sz_obj = (unsigned int)(streamCompObject.size() - streamCompObject.tell());
if (sz_obj > 4)
ClipboardFormat = ReadStringFromOle(&streamCompObject, sz_obj);
sz_obj = streamCompObject.size() - streamCompObject.tell();
sz_obj = (unsigned int)(streamCompObject.size() - streamCompObject.tell());
if (sz_obj > 4)
Program = ReadStringFromOle(&streamCompObject, sz_obj);
}
@ -346,7 +346,7 @@ bool COfficeFileFormatChecker::isOleObjectFile(POLE::Storage *storage)
if (2 == streamLinkInfo.read((BYTE *)&cch, 2))
{
unsigned char *str = new unsigned char[cch];
cch = streamLinkInfo.read(str, cch);
cch = (short)streamLinkInfo.read(str, cch);
ClipboardFormat = std::string((char *)str, cch);
RELEASEARRAYOBJECTS(str);
@ -590,7 +590,7 @@ bool COfficeFileFormatChecker::isMS_OFFICECRYPTOFormatFile(POLE::Storage *storag
sData.resize(stream.size());
if (stream.read((BYTE *)sData.c_str(), stream.size()) > 0)
{
documentID = NSFile::CUtf8Converter::GetUnicodeStringFromUTF8((BYTE *)sData.c_str(), sData.length());
documentID = UTF8_TO_U(sData);
}
}
return result;
@ -765,7 +765,6 @@ bool COfficeFileFormatChecker::isOfficeFile(const std::wstring &_fileName)
{
file.SeekFile(fileSize - MIN_SIZE_BUFFER);
file.ReadFile(bufferDetect, MIN_SIZE_BUFFER, dwDetectdBytes);
int sizeRead = (int)dwDetectdBytes;
}
if (isHtmlFormatFile(bufferDetect, sizeRead, true)) // min size - 6
{
@ -1247,7 +1246,7 @@ bool COfficeFileFormatChecker::isOOXFlatFormatFile(unsigned char *pBuffer, int d
{ // utf-16- big
// swap bytes
DWORD file_size_round = (dwBytes / 2) * 2;
for (long i = 0; i < file_size_round; i += 2)
for (DWORD i = 0; i < file_size_round; i += 2)
{
char v = pBuffer[i];
pBuffer[i] = pBuffer[i + 1];