bool Decoder7zipCreator is7Zip DataInfo datainfo IDecodableObject inpu

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
bool Decoder7zipCreator::is7Zip(DataInfo& datainfo, IDecodableObject * inputObj, const uint8_t * data, size_t size)
{
if (!inputObj)
{
return false;
}
DEBUG_SEVENZIP_DECODER("Tasting 7ZIP\n")
static constexpr std::array<uint8_t, 6> sign7zip = {0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C};
if (memcmp(data, sign7zip.data(), sign7zip.size()) == 0)
{
auto dataChunks = inputObj->getData();
if(dataChunks.size())
{
std::list<std::shared_ptr<data_chunk_base>>::iterator lastChunkIt = std::prev(dataChunks.end());
std::vector<uint8_t> tmpBuf((*lastChunkIt)->size);
tmpBuf.insert(tmpBuf.end(), (*lastChunkIt)->data, (*lastChunkIt)->data + (*lastChunkIt)->size);
if(dataChunks.size() > 1)
{
std::list<std::shared_ptr<data_chunk_base>>::iterator preLastChunkIt = std::prev(lastChunkIt);
tmpBuf.insert(tmpBuf.end(), (*preLastChunkIt)->data, (*preLastChunkIt)->data + (*preLastChunkIt)->size);
}
if(isEncoded(tmpBuf.data(), tmpBuf.size()))
{
DEBUG_SEVENZIP_DECODER("This is encoded 7zip archive\n")
addMimeType(datainfo, *inputObj, mime_types::getMimeTypeSEVEN_ZIP_PSWD());
return true;
}
}
addMimeType(datainfo, *inputObj, mime_types::getMimeTypeSEVEN_ZIP());
return true;
}
return false;
}