2026-03-28 16:54:11 +11:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
class BitStream3
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
BitStream3();
|
|
|
|
|
BitStream3(int bitCount);
|
|
|
|
|
~BitStream3();
|
|
|
|
|
|
|
|
|
|
void Create(int bitCount);
|
|
|
|
|
void Attach(void * buf, int bitCount);
|
|
|
|
|
int Write(const unsigned char * buf, int bitCount);
|
|
|
|
|
int WriteUInt16(unsigned short val);
|
|
|
|
|
int Read(unsigned char * buf, int bitCount);
|
|
|
|
|
int ReadUInt16(unsigned short * val);
|
|
|
|
|
unsigned char * GetBuffer();
|
|
|
|
|
|
|
|
|
|
protected:
|
2026-07-27 09:29:05 +10:00
|
|
|
// Bounds-safe accessors: every Write/Read goes through these so a caller
|
|
|
|
|
// that under-sizes the stream can no longer corrupt the heap (the 125-vs-147
|
|
|
|
|
// bug in GetCurrentHardwareId overflowed 3 bytes for years). Out-of-range
|
|
|
|
|
// reads return 0 — identical to the base32 padding zeros the hardware-id
|
|
|
|
|
// Match path has always effectively read there.
|
|
|
|
|
unsigned char byteAt(int i) const
|
|
|
|
|
{
|
|
|
|
|
return (buffer && i >= 0 && i < bufSize) ? buffer[i] : 0;
|
|
|
|
|
}
|
|
|
|
|
void setByte(int i, unsigned char v)
|
|
|
|
|
{
|
|
|
|
|
if (buffer && i >= 0 && i < bufSize) buffer[i] = v;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-28 16:54:11 +11:00
|
|
|
bool ownMemory;
|
|
|
|
|
unsigned char * buffer;
|
|
|
|
|
int bufSize, bitSize;
|
|
|
|
|
int currentBit, currentByte;
|
|
|
|
|
static const unsigned char hiMask[];
|
|
|
|
|
};
|