int AndPredicate::Evaluate(void* p) const { RETURN_ZERO_IF_EMPTY(mItems); FOR_EACH_COLLECTION(i, mItems) { const IPredicate* item = *i; RETURN_ZERO_IF_ZERO(item->Evaluate(p)); } return 1; }
size_t LZMADecoder::OnCode(const MemoryData& input, MemoryData& output) const { RETURN_ZERO_IF_EMPTY(input); const byte* inBuffer = input.Data(); size_t inSize = input.Size(); ELzmaStatus outStatus; ISzAlloc myAlloc; myAlloc.Alloc = LZMAAlloc; myAlloc.Free = LZMAFree; CLzmaDec p; SRes res; LzmaDec_Construct(&p); res = LzmaDec_AllocateProbs(&p, inBuffer, LZMA_PROPS_SIZE, &myAlloc); uint64 fileSize = 0; for (int i = 0; i < 8; i++) fileSize |= ((uint64)inBuffer[LZMA_PROPS_SIZE + i]) << (8 * i); if (output.Size()<(size_t)fileSize) { Log::AssertFailedFormat("output size:{} < expected size{}", output.Size(), fileSize); LzmaDec_FreeProbs(&p, &myAlloc); return 0; } LzmaDec_Init(&p); p.dic = output.MutableData(); p.dicBufSize = (size_t)fileSize; size_t outSize = inSize - 13; res = LzmaDec_DecodeToDic(&p, (size_t)fileSize, inBuffer + 13, &outSize, LZMA_FINISH_ANY, &outStatus); if (res == SZ_OK && outStatus == LZMA_STATUS_NEEDS_MORE_INPUT) res = SZ_ERROR_INPUT_EOF; LzmaDec_FreeProbs(&p, &myAlloc); return (size_t)fileSize; }
size_t XORDecoder::OnCode(const MemoryByteData& input, MemoryByteData& output) const { RETURN_ZERO_IF_EMPTY(input); if (output.Size()<input.Size()) { Log::AssertFailedFormat("output size:{} < expected size{}", output.Size(), input.Size()); return 0; } const byte* data = input.Data(); byte* result = output.MutableData(); size_t keyIndex = 0; size_t srcSize = input.Size(); size_t keySize = mKey.Size(); if (keySize != srcSize) { for (size_t i = 0; i < srcSize; ++i) { result[i] = data[i] ^ mKey[keyIndex]; if (keyIndex < keySize - 1) { ++keyIndex; } else { keyIndex = 0; } } } else { for (size_t i = 0; i < srcSize; ++i) { result[i] = (char)(data[i] ^ mKey[i]); } } return srcSize; }