2014-04-21 02:14:48 +00:00
|
|
|
/* Copyright (c) 2008-2014, Avian Contributors
|
2012-06-02 15:06:22 +00:00
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software
|
|
|
|
for any purpose with or without fee is hereby granted, provided
|
|
|
|
that the above copyright notice and this permission notice appear
|
|
|
|
in all copies.
|
|
|
|
|
|
|
|
There is NO WARRANTY for this software. See license.txt for
|
|
|
|
details. */
|
|
|
|
|
2013-03-02 21:26:24 +00:00
|
|
|
#include "avian/lzma-util.h"
|
2012-06-02 21:43:42 +00:00
|
|
|
#include "C/LzmaDec.h"
|
2012-06-02 15:06:22 +00:00
|
|
|
|
|
|
|
using namespace vm;
|
|
|
|
|
2012-06-06 18:58:24 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
read4(const uint8_t* in)
|
|
|
|
{
|
|
|
|
return (static_cast<int32_t>(in[3]) << 24)
|
|
|
|
| (static_cast<int32_t>(in[2]) << 16)
|
|
|
|
| (static_cast<int32_t>(in[1]) << 8)
|
|
|
|
| (static_cast<int32_t>(in[0]) );
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2012-06-02 15:06:22 +00:00
|
|
|
namespace vm {
|
|
|
|
|
|
|
|
uint8_t*
|
2014-03-25 21:10:24 +00:00
|
|
|
decodeLZMA(System* s, avian::util::Allocator* a, uint8_t* in, unsigned inSize,
|
2012-06-02 15:06:22 +00:00
|
|
|
unsigned* outSize)
|
|
|
|
{
|
|
|
|
const unsigned PropHeaderSize = 5;
|
|
|
|
const unsigned HeaderSize = 13;
|
|
|
|
|
2012-06-06 18:58:24 +00:00
|
|
|
int32_t outSize32 = read4(in + PropHeaderSize);
|
2012-06-02 15:06:22 +00:00
|
|
|
expect(s, outSize32 >= 0);
|
|
|
|
SizeT outSizeT = outSize32;
|
|
|
|
|
|
|
|
uint8_t* out = static_cast<uint8_t*>(a->allocate(outSize32));
|
|
|
|
|
|
|
|
SizeT inSizeT = inSize;
|
|
|
|
LzmaAllocator allocator(a);
|
|
|
|
|
|
|
|
ELzmaStatus status;
|
|
|
|
int result = LzmaDecode
|
|
|
|
(out, &outSizeT, in + HeaderSize, &inSizeT, in, PropHeaderSize,
|
|
|
|
LZMA_FINISH_END, &status, &(allocator.allocator));
|
|
|
|
|
|
|
|
expect(s, result == SZ_OK);
|
|
|
|
expect(s, status == LZMA_STATUS_FINISHED_WITH_MARK);
|
|
|
|
|
|
|
|
*outSize = outSize32;
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace vm
|
|
|
|
|