5
#include "Common/Defs.h"
7
#include "Lzx86Converter.h"
12
static const int kResidue = 6 + 4;
14
void Cx86ConvertOutStream::MakeTranslation()
16
if (m_Pos <= kResidue)
18
UInt32 numBytes = m_Pos - kResidue;
19
Byte *buffer = m_Buffer;
20
for (UInt32 i = 0; i < numBytes;)
22
if (buffer[i++] == 0xE8)
26
for(j = 0; j < 4; j++)
27
absValue += (UInt32)buffer[i + j] << (j * 8);
28
Int32 pos = (Int32)(m_ProcessedSize + i - 1);
29
if (absValue >= -pos && absValue < (Int32)m_TranslationSize)
31
UInt32 offset = (absValue >= 0) ?
33
absValue + m_TranslationSize;
34
for(j = 0; j < 4; j++)
36
buffer[i + j] = (Byte)(offset & 0xFF);
45
STDMETHODIMP Cx86ConvertOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize)
47
if (processedSize != NULL)
49
if (!m_TranslationMode)
50
return m_Stream->Write(data, size, processedSize);
51
UInt32 realProcessedSize = 0;
52
while (realProcessedSize < size)
54
UInt32 writeSize = MyMin(size - realProcessedSize, kUncompressedBlockSize - m_Pos);
55
memmove(m_Buffer + m_Pos, (const Byte *)data + realProcessedSize, writeSize);
57
realProcessedSize += writeSize;
58
if (m_Pos == kUncompressedBlockSize)
63
if (processedSize != NULL)
64
*processedSize = realProcessedSize;
68
HRESULT Cx86ConvertOutStream::Flush()
72
if (m_TranslationMode)
78
RINOK(m_Stream->Write(m_Buffer + pos, m_Pos - pos, &processed));
84
m_ProcessedSize += m_Pos;
86
m_TranslationMode = (m_TranslationMode && (m_ProcessedSize < (1 << 30)));