2022-12-20 15:06:44 +00:00
|
|
|
#if !Rar2017_64bit
|
2017-12-17 20:59:34 -05:00
|
|
|
using size_t = System.UInt32;
|
|
|
|
|
#else
|
|
|
|
|
using nint = System.Int64;
|
|
|
|
|
using nuint = System.UInt64;
|
|
|
|
|
using size_t = System.UInt64;
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-05-23 16:27:55 -07:00
|
|
|
#nullable disable
|
|
|
|
|
|
2022-12-20 15:06:44 +00:00
|
|
|
namespace SharpCompress.Compressors.Rar.UnpackV2017;
|
|
|
|
|
|
|
|
|
|
internal partial class BitInput
|
2017-12-17 20:59:34 -05:00
|
|
|
{
|
2022-12-20 15:06:44 +00:00
|
|
|
public BitInput(bool AllocBuffer)
|
2017-12-17 20:59:34 -05:00
|
|
|
{
|
2022-12-20 15:06:44 +00:00
|
|
|
ExternalBuffer = false;
|
|
|
|
|
if (AllocBuffer)
|
2021-01-09 13:33:34 +00:00
|
|
|
{
|
2022-12-20 15:06:44 +00:00
|
|
|
// getbits32 attempts to read data from InAddr, ... InAddr+3 positions.
|
|
|
|
|
// So let's allocate 3 additional bytes for situation, when we need to
|
|
|
|
|
// read only 1 byte from the last position of buffer and avoid a crash
|
|
|
|
|
// from access to next 3 bytes, which contents we do not need.
|
|
|
|
|
size_t BufSize = MAX_SIZE + 3;
|
|
|
|
|
InBuf = new byte[BufSize];
|
2017-12-17 20:59:34 -05:00
|
|
|
|
2022-12-20 15:06:44 +00:00
|
|
|
// Ensure that we get predictable results when accessing bytes in area
|
|
|
|
|
// not filled with read data.
|
|
|
|
|
//memset(InBuf,0,BufSize);
|
2021-01-09 13:33:34 +00:00
|
|
|
}
|
2022-12-20 15:06:44 +00:00
|
|
|
else
|
2021-01-09 13:33:34 +00:00
|
|
|
{
|
2022-12-20 15:06:44 +00:00
|
|
|
InBuf = null;
|
2021-01-09 13:33:34 +00:00
|
|
|
}
|
2022-12-20 15:06:44 +00:00
|
|
|
}
|
2017-12-17 20:59:34 -05:00
|
|
|
|
2022-12-20 15:06:44 +00:00
|
|
|
//BitInput::~BitInput()
|
|
|
|
|
//{
|
|
|
|
|
// if (!ExternalBuffer)
|
|
|
|
|
// delete[] InBuf;
|
|
|
|
|
//}
|
|
|
|
|
//
|
2017-12-17 20:59:34 -05:00
|
|
|
|
2022-12-20 15:06:44 +00:00
|
|
|
public void faddbits(uint Bits)
|
|
|
|
|
{
|
|
|
|
|
// Function wrapped version of inline addbits to save code size.
|
|
|
|
|
addbits(Bits);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint fgetbits()
|
|
|
|
|
{
|
|
|
|
|
// Function wrapped version of inline getbits to save code size.
|
|
|
|
|
return getbits();
|
2017-12-17 20:59:34 -05:00
|
|
|
}
|
|
|
|
|
}
|