Implement Qualcomm Sahara VIP and fix a few bugs

* Qualcomm Sahara VIP
* Project Cleanup
* Allow unlocking an already unlocked phone
This commit is contained in:
Gustave Monce
2021-08-11 14:33:49 +02:00
parent 9f4c92f437
commit c5fcb1ec8d
72 changed files with 987 additions and 861 deletions
+2 -2
View File
@@ -35,14 +35,14 @@ namespace SevenZip
public void UpdateByte(byte b)
{
_value = Table[((byte)(_value)) ^ b] ^ (_value >> 8);
_value = Table[((byte)_value) ^ b] ^ (_value >> 8);
}
public void Update(byte[] data, uint offset, uint size)
{
for (uint i = 0; i < size; i++)
{
_value = Table[((byte)(_value)) ^ data[offset + i]] ^ (_value >> 8);
_value = Table[((byte)_value) ^ data[offset + i]] ^ (_value >> 8);
}
}
+1 -1
View File
@@ -134,7 +134,7 @@ namespace SevenZip.CommandLineParser
}
else
{
matchedSwitch.WithMinus = (srcString[pos] == kSwitchMinus);
matchedSwitch.WithMinus = srcString[pos] == kSwitchMinus;
if (matchedSwitch.WithMinus)
{
pos++;
+5 -11
View File
@@ -38,7 +38,7 @@ namespace SevenZip.Buffer
int aNumProcessedBytes = m_Stream.Read(m_Buffer, 0, (int)m_BufferSize);
m_Pos = 0;
m_Limit = (uint)aNumProcessedBytes;
m_StreamWasExhausted = (aNumProcessedBytes == 0);
m_StreamWasExhausted = aNumProcessedBytes == 0;
return !m_StreamWasExhausted;
}
@@ -50,12 +50,9 @@ namespace SevenZip.Buffer
public bool ReadByte(byte b) // check it
{
if (m_Pos >= m_Limit)
if (m_Pos >= m_Limit && !ReadBlock())
{
if (!ReadBlock())
{
return false;
}
return false;
}
b = m_Buffer[m_Pos++];
@@ -65,12 +62,9 @@ namespace SevenZip.Buffer
public byte ReadByte()
{
// return (byte)m_Stream.ReadByte();
if (m_Pos >= m_Limit)
if (m_Pos >= m_Limit && !ReadBlock())
{
if (!ReadBlock())
{
return 0xFF;
}
return 0xFF;
}
return m_Buffer[m_Pos++];
+27 -36
View File
@@ -33,7 +33,7 @@ namespace SevenZip.Compression.LZ
public void SetType(int numHashBytes)
{
HASH_ARRAY = (numHashBytes > 2);
HASH_ARRAY = numHashBytes > 2;
if (HASH_ARRAY)
{
kNumHashDirectBytes = 0;
@@ -97,7 +97,7 @@ namespace SevenZip.Compression.LZ
UInt32 windowReservSize = ((historySize + keepAddBufferBefore +
matchMaxLen + keepAddBufferAfter) / 2) + 256;
base.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);
Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);
_matchMaxLen = matchMaxLen;
@@ -112,10 +112,10 @@ namespace SevenZip.Compression.LZ
if (HASH_ARRAY)
{
hs = historySize - 1;
hs |= (hs >> 1);
hs |= (hs >> 2);
hs |= (hs >> 4);
hs |= (hs >> 8);
hs |= hs >> 1;
hs |= hs >> 2;
hs |= hs >> 4;
hs |= hs >> 8;
hs >>= 1;
hs |= 0xFFFF;
if (hs > (1 << 24))
@@ -160,13 +160,13 @@ namespace SevenZip.Compression.LZ
{
UInt32 temp = CRC.Table[_bufferBase[cur]] ^ _bufferBase[cur + 1];
hash2Value = temp & (kHash2Size - 1);
temp ^= ((UInt32)(_bufferBase[cur + 2]) << 8);
temp ^= (UInt32)_bufferBase[cur + 2] << 8;
hash3Value = temp & (kHash3Size - 1);
hashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;
}
else
{
hashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);
hashValue = _bufferBase[cur] ^ ((UInt32)_bufferBase[cur + 1] << 8);
}
UInt32 curMatch = _hash[kFixHashSize + hashValue];
@@ -176,28 +176,22 @@ namespace SevenZip.Compression.LZ
UInt32 curMatch3 = _hash[kHash3Offset + hash3Value];
_hash[hash2Value] = _pos;
_hash[kHash3Offset + hash3Value] = _pos;
if (curMatch2 > matchMinPos)
if (curMatch2 > matchMinPos && _bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])
{
if (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])
{
distances[offset++] = maxLen = 2;
distances[offset++] = _pos - curMatch2 - 1;
}
distances[offset++] = maxLen = 2;
distances[offset++] = _pos - curMatch2 - 1;
}
if (curMatch3 > matchMinPos)
if (curMatch3 > matchMinPos && _bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])
{
if (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])
if (curMatch3 == curMatch2)
{
if (curMatch3 == curMatch2)
{
offset -= 2;
}
distances[offset++] = maxLen = 3;
distances[offset++] = _pos - curMatch3 - 1;
curMatch2 = curMatch3;
offset -= 2;
}
distances[offset++] = maxLen = 3;
distances[offset++] = _pos - curMatch3 - 1;
curMatch2 = curMatch3;
}
if (offset != 0 && curMatch2 == curMatch)
@@ -210,21 +204,18 @@ namespace SevenZip.Compression.LZ
_hash[kFixHashSize + hashValue] = _pos;
UInt32 ptr0 = (_cyclicBufferPos << 1) + 1;
UInt32 ptr1 = (_cyclicBufferPos << 1);
UInt32 ptr1 = _cyclicBufferPos << 1;
UInt32 len0, len1;
len0 = len1 = kNumHashDirectBytes;
if (kNumHashDirectBytes != 0)
if (kNumHashDirectBytes != 0 && curMatch > matchMinPos)
{
if (curMatch > matchMinPos)
if (_bufferBase[_bufferOffset + curMatch + kNumHashDirectBytes] !=
_bufferBase[cur + kNumHashDirectBytes])
{
if (_bufferBase[_bufferOffset + curMatch + kNumHashDirectBytes] !=
_bufferBase[cur + kNumHashDirectBytes])
{
distances[offset++] = maxLen = kNumHashDirectBytes;
distances[offset++] = _pos - curMatch - 1;
}
distances[offset++] = maxLen = kNumHashDirectBytes;
distances[offset++] = _pos - curMatch - 1;
}
}
@@ -314,21 +305,21 @@ namespace SevenZip.Compression.LZ
UInt32 temp = CRC.Table[_bufferBase[cur]] ^ _bufferBase[cur + 1];
UInt32 hash2Value = temp & (kHash2Size - 1);
_hash[hash2Value] = _pos;
temp ^= ((UInt32)(_bufferBase[cur + 2]) << 8);
temp ^= (UInt32)_bufferBase[cur + 2] << 8;
UInt32 hash3Value = temp & (kHash3Size - 1);
_hash[kHash3Offset + hash3Value] = _pos;
hashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;
}
else
{
hashValue = _bufferBase[cur] ^ ((UInt32)(_bufferBase[cur + 1]) << 8);
hashValue = _bufferBase[cur] ^ ((UInt32)_bufferBase[cur + 1] << 8);
}
UInt32 curMatch = _hash[kFixHashSize + hashValue];
_hash[kFixHashSize + hashValue] = _pos;
UInt32 ptr0 = (_cyclicBufferPos << 1) + 1;
UInt32 ptr1 = (_cyclicBufferPos << 1);
UInt32 ptr1 = _cyclicBufferPos << 1;
UInt32 len0, len1;
len0 = len1 = kNumHashDirectBytes;
+3 -6
View File
@@ -50,7 +50,7 @@ namespace SevenZip.Compression.LZ
while (true)
{
int size = (int)((0 - _bufferOffset) + _blockSize - _streamPos);
int size = (int)(0 - _bufferOffset + _blockSize - _streamPos);
if (size == 0)
{
return;
@@ -125,12 +125,9 @@ namespace SevenZip.Compression.LZ
// index + limit have not to exceed _keepSizeAfter;
public UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)
{
if (_streamEndWasReached)
if (_streamEndWasReached && _pos + index + limit > _streamPos)
{
if (_pos + index + limit > _streamPos)
{
limit = _streamPos - (UInt32)(_pos + index);
}
limit = _streamPos - (UInt32)(_pos + index);
}
distance++;
+3 -3
View File
@@ -60,7 +60,7 @@ namespace SevenZip.Compression.LZMA
public const int kNumAlignBits = 4;
public const uint kAlignTableSize = 1 << kNumAlignBits;
public const uint kAlignMask = (kAlignTableSize - 1);
public const uint kAlignMask = kAlignTableSize - 1;
public const uint kStartPosModelIndex = 4;
public const uint kEndPosModelIndex = 14;
@@ -72,9 +72,9 @@ namespace SevenZip.Compression.LZMA
public const uint kNumLitContextBitsMax = 8;
public const int kNumPosStatesBitsMax = 4;
public const uint kNumPosStatesMax = (1 << kNumPosStatesBitsMax);
public const uint kNumPosStatesMax = 1 << kNumPosStatesBitsMax;
public const int kNumPosStatesBitsEncodingMax = 4;
public const uint kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);
public const uint kNumPosStatesEncodingMax = 1 << kNumPosStatesBitsEncodingMax;
public const int kNumLowLenBits = 3;
public const int kNumMidLenBits = 3;
+4 -4
View File
@@ -362,7 +362,7 @@ namespace SevenZip.Compression.LZMA
if (posSlot >= Base.kStartPosModelIndex)
{
int numDirectBits = (int)((posSlot >> 1) - 1);
rep0 = ((2 | (posSlot & 1)) << numDirectBits);
rep0 = (2 | (posSlot & 1)) << numDirectBits;
if (posSlot < Base.kEndPosModelIndex)
{
rep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,
@@ -370,8 +370,8 @@ namespace SevenZip.Compression.LZMA
}
else
{
rep0 += (m_RangeDecoder.DecodeDirectBits(
numDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);
rep0 += m_RangeDecoder.DecodeDirectBits(
numDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits;
rep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);
}
}
@@ -423,7 +423,7 @@ namespace SevenZip.Compression.LZMA
UInt32 dictionarySize = 0;
for (int i = 0; i < 4; i++)
{
dictionarySize += ((UInt32)(properties[1 + i])) << (i * 8);
dictionarySize += ((UInt32)properties[1 + i]) << (i * 8);
}
SetDictionarySize(dictionarySize);
+21 -21
View File
@@ -27,7 +27,7 @@ namespace SevenZip.Compression.LZMA
g_FastPos[1] = 1;
for (Byte slotFast = 2; slotFast < kFastSlots; slotFast++)
{
UInt32 k = ((UInt32)1 << ((slotFast >> 1) - 1));
UInt32 k = (UInt32)1 << ((slotFast >> 1) - 1);
for (UInt32 j = 0; j < k; j++, c++)
{
g_FastPos[c] = slotFast;
@@ -118,8 +118,8 @@ namespace SevenZip.Compression.LZMA
if (same)
{
uint matchBit = (uint)((matchByte >> i) & 1);
state += ((1 + matchBit) << 8);
same = (matchBit == bit);
state += (1 + matchBit) << 8;
same = matchBit == bit;
}
m_Encoders[state].Encode(rangeEncoder, bit);
context = (context << 1) | bit;
@@ -379,14 +379,14 @@ namespace SevenZip.Compression.LZMA
private readonly UInt32[] _alignPrices = new UInt32[Base.kAlignTableSize];
private UInt32 _alignPriceCount;
private UInt32 _distTableSize = (kDefaultDictionaryLogSize * 2);
private UInt32 _distTableSize = kDefaultDictionaryLogSize * 2;
private int _posStateBits = 2;
private UInt32 _posStateMask = (4 - 1);
private UInt32 _posStateMask = 4 - 1;
private int _numLiteralPosStateBits = 0;
private int _numLiteralContextBits = 3;
private UInt32 _dictionarySize = (1 << kDefaultDictionaryLogSize);
private UInt32 _dictionarySize = 1 << kDefaultDictionaryLogSize;
private UInt32 _dictionarySizePrev = 0xFFFFFFFF;
private UInt32 _numFastBytesPrev = 0xFFFFFFFF;
@@ -665,7 +665,7 @@ namespace SevenZip.Compression.LZMA
_optimum[0].State = _state;
UInt32 posState = (position & _posStateMask);
UInt32 posState = position & _posStateMask;
_optimum[1].Price = _isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +
_literalEncoder.GetSubCoder(position, _previousByte).GetPrice(!_state.IsCharState(), matchByte, currentByte);
@@ -684,7 +684,7 @@ namespace SevenZip.Compression.LZMA
}
}
UInt32 lenEnd = ((lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex]);
UInt32 lenEnd = (lenMain >= repLens[repMaxIndex]) ? lenMain : repLens[repMaxIndex];
if (lenEnd < 2)
{
@@ -732,7 +732,7 @@ namespace SevenZip.Compression.LZMA
UInt32 normalMatchPrice = matchPrice + _isRep[_state.Index].GetPrice0();
len = ((repLens[0] >= 2) ? repLens[0] + 1 : 2);
len = (repLens[0] >= 2) ? repLens[0] + 1 : 2;
if (len <= lenMain)
{
UInt32 offs = 0;
@@ -878,7 +878,7 @@ namespace SevenZip.Compression.LZMA
}
else
{
reps[0] = (pos - Base.kNumRepDistances);
reps[0] = pos - Base.kNumRepDistances;
reps[1] = opt.Backs0;
reps[2] = opt.Backs1;
reps[3] = opt.Backs2;
@@ -894,7 +894,7 @@ namespace SevenZip.Compression.LZMA
currentByte = _matchFinder.GetIndexByte(0 - 1);
matchByte = _matchFinder.GetIndexByte((Int32)(0 - reps[0] - 1 - 1));
posState = (position & _posStateMask);
posState = position & _posStateMask;
UInt32 curAnd1Price = curPrice +
_isMatch[(state.Index << Base.kNumPosStatesBitsMax) + posState].GetPrice0() +
@@ -1154,7 +1154,7 @@ namespace SevenZip.Compression.LZMA
private bool ChangePair(UInt32 smallDist, UInt32 bigDist)
{
const int kDif = 7;
return smallDist < ((UInt32)(1) << (32 - kDif)) && bigDist >= (smallDist << kDif);
return smallDist < ((UInt32)1 << (32 - kDif)) && bigDist >= (smallDist << kDif);
}
private void WriteEndMarker(UInt32 posState)
@@ -1173,7 +1173,7 @@ namespace SevenZip.Compression.LZMA
UInt32 lenToPosState = Base.GetLenToPosState(len);
_posSlotEncoder[lenToPosState].Encode(_rangeEncoder, posSlot);
const int footerBits = 30;
UInt32 posReduced = (((UInt32)1) << footerBits) - 1;
const UInt32 posReduced = (((UInt32)1) << footerBits) - 1;
_rangeEncoder.EncodeDirectBits(posReduced >> Base.kNumAlignBits, footerBits - Base.kNumAlignBits);
_posAlignEncoder.ReverseEncode(_rangeEncoder, posReduced & Base.kAlignMask);
}
@@ -1221,11 +1221,11 @@ namespace SevenZip.Compression.LZMA
}
// it's not used
ReadMatchDistances(out uint len, out uint numDistancePairs);
UInt32 posState = (UInt32)(nowPos64) & _posStateMask;
UInt32 posState = (UInt32)nowPos64 & _posStateMask;
_isMatch[(_state.Index << Base.kNumPosStatesBitsMax) + posState].Encode(_rangeEncoder, 0);
_state.UpdateChar();
Byte curByte = _matchFinder.GetIndexByte((Int32)(0 - _additionalOffset));
_literalEncoder.GetSubCoder((UInt32)(nowPos64), _previousByte).Encode(_rangeEncoder, curByte);
_literalEncoder.GetSubCoder((UInt32)nowPos64, _previousByte).Encode(_rangeEncoder, curByte);
_previousByte = curByte;
_additionalOffset--;
nowPos64++;
@@ -1323,12 +1323,12 @@ namespace SevenZip.Compression.LZMA
if (posSlot >= Base.kStartPosModelIndex)
{
int footerBits = (int)((posSlot >> 1) - 1);
UInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);
UInt32 baseVal = (2 | (posSlot & 1)) << footerBits;
UInt32 posReduced = pos - baseVal;
if (posSlot < Base.kEndPosModelIndex)
{
RangeCoder.BitTreeEncoder.ReverseEncode(_posEncoders,
BitTreeEncoder.ReverseEncode(_posEncoders,
baseVal - posSlot - 1, _rangeEncoder, footerBits, posReduced);
}
else
@@ -1471,7 +1471,7 @@ namespace SevenZip.Compression.LZMA
{
UInt32 posSlot = GetPosSlot(i);
int footerBits = (int)((posSlot >> 1) - 1);
UInt32 baseVal = ((2 | (posSlot & 1)) << footerBits);
UInt32 baseVal = (2 | (posSlot & 1)) << footerBits;
tempPrices[i] = BitTreeEncoder.ReverseGetPrice(_posEncoders,
baseVal - posSlot - 1, footerBits, i - baseVal);
}
@@ -1481,7 +1481,7 @@ namespace SevenZip.Compression.LZMA
UInt32 posSlot;
BitTreeEncoder encoder = _posSlotEncoder[lenToPosState];
UInt32 st = (lenToPosState << Base.kNumPosSlotBits);
UInt32 st = lenToPosState << Base.kNumPosSlotBits;
for (posSlot = 0; posSlot < _distTableSize; posSlot++)
{
_posSlotPrices[st + posSlot] = encoder.GetPrice(posSlot);
@@ -1489,7 +1489,7 @@ namespace SevenZip.Compression.LZMA
for (posSlot = Base.kEndPosModelIndex; posSlot < _distTableSize; posSlot++)
{
_posSlotPrices[st + posSlot] += (((posSlot >> 1) - 1 - Base.kNumAlignBits) << RangeCoder.BitEncoder.kNumBitPriceShiftBits);
_posSlotPrices[st + posSlot] += ((posSlot >> 1) - 1 - Base.kNumAlignBits) << BitEncoder.kNumBitPriceShiftBits;
}
UInt32 st2 = lenToPosState * Base.kNumFullDistances;
@@ -1610,7 +1610,7 @@ namespace SevenZip.Compression.LZMA
int dicLogSize;
for (dicLogSize = 0; dicLogSize < (UInt32)kDicLogSizeMaxCompress; dicLogSize++)
{
if (dictionarySize <= ((UInt32)(1) << dicLogSize))
if (dictionarySize <= ((UInt32)1 << dicLogSize))
{
break;
}
+2 -2
View File
@@ -4,7 +4,7 @@ namespace SevenZip.Compression.RangeCoder
{
internal class Encoder
{
public const uint kTopValue = (1 << 24);
public const uint kTopValue = 1 << 24;
private System.IO.Stream Stream;
@@ -128,7 +128,7 @@ namespace SevenZip.Compression.RangeCoder
internal class Decoder
{
public const uint kTopValue = (1 << 24);
public const uint kTopValue = 1 << 24;
public uint Range;
public uint Code;
// public Buffer.InBuffer Stream = new Buffer.InBuffer(1 << 16);
+3 -3
View File
@@ -5,7 +5,7 @@ namespace SevenZip.Compression.RangeCoder
internal struct BitEncoder
{
public const int kNumBitModelTotalBits = 11;
public const uint kBitModelTotal = (1 << kNumBitModelTotalBits);
public const uint kBitModelTotal = 1 << kNumBitModelTotalBits;
private const int kNumMoveBits = 5;
private const int kNumMoveReducingBits = 2;
public const int kNumBitPriceShiftBits = 6;
@@ -53,7 +53,7 @@ namespace SevenZip.Compression.RangeCoder
static BitEncoder()
{
const int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);
const int kNumBits = kNumBitModelTotalBits - kNumMoveReducingBits;
for (int i = kNumBits - 1; i >= 0; i--)
{
UInt32 start = (UInt32)1 << (kNumBits - i - 1);
@@ -77,7 +77,7 @@ namespace SevenZip.Compression.RangeCoder
internal struct BitDecoder
{
public const int kNumBitModelTotalBits = 11;
public const uint kBitModelTotal = (1 << kNumBitModelTotalBits);
public const uint kBitModelTotal = 1 << kNumBitModelTotalBits;
private const int kNumMoveBits = 5;
private uint Prob;
@@ -141,7 +141,7 @@ namespace SevenZip.Compression.RangeCoder
uint bit = Models[m].Decode(rangeDecoder);
m <<= 1;
m += bit;
symbol |= (bit << bitIndex);
symbol |= bit << bitIndex;
}
return symbol;
}
@@ -156,7 +156,7 @@ namespace SevenZip.Compression.RangeCoder
uint bit = Models[startIndex + m].Decode(rangeDecoder);
m <<= 1;
m += bit;
symbol |= (bit << bitIndex);
symbol |= bit << bitIndex;
}
return symbol;
}
+16
View File
@@ -11,6 +11,14 @@ namespace SevenZip
internal class DataErrorException : ApplicationException
{
public DataErrorException() : base("Data Error") { }
public DataErrorException(string message) : base(message)
{
}
public DataErrorException(string message, Exception innerException) : base(message, innerException)
{
}
}
/// <summary>
@@ -19,6 +27,14 @@ namespace SevenZip
internal class InvalidParamException : ApplicationException
{
public InvalidParamException() : base("Invalid Parameter") { }
public InvalidParamException(string message) : base(message)
{
}
public InvalidParamException(string message, Exception innerException) : base(message, innerException)
{
}
}
public interface ICodeProgress