我需要找到MSDN网站上描述的 LZ77 和 Direct2 算法的实现。我期待它可能是 SDK 的一部分。到目前为止,我没有运气。
有人可以指导我到哪里可以找到这些算法,以便我可以在我的代码中使用它们吗?
谢谢
我需要找到MSDN网站上描述的 LZ77 和 Direct2 算法的实现。我期待它可能是 SDK 的一部分。到目前为止,我没有运气。
有人可以指导我到哪里可以找到这些算法,以便我可以在我的代码中使用它们吗?
谢谢
你找到解决办法了吗?我在 Michael Cohen 的帮助下将其翻译成 C# 进行解压。 http://volatility.googlecode.com/svn-history/r1609/branches/scudette/contrib/pyxpress/pyxpress.c
我的测试表明它工作正常,但请为您自己测试:)
private static int PAGE_SIZE = 0x00001000;
private static int XPRESS_ENCODE_MAGIC = 0x19880922;
private static int DELTA_PAGE = ((2 * PAGE_SIZE) - 1);
private static int UNCOMPRESSED_BLOCK_SIZE = (PAGE_SIZE * 0x10);
public static byte[] Xpress_Decompress(byte[] inputBuffer, int outputSize)
{
int outputIndex, inputIndex;
int indicator, indicatorBit;
int length;
int offset;
int nibbleIndex;
int nibbleIndicator;
int inputSize = inputBuffer.Length;
outputIndex = 0;
inputIndex = 0;
indicator = 0;
indicatorBit = 0;
length = 0;
offset = 0;
nibbleIndex = 0;
nibbleIndicator = XPRESS_ENCODE_MAGIC;
var outputBuffer = new byte[outputSize];
while ((outputIndex < outputSize) && (inputIndex < inputSize))
{
if (indicatorBit == 0)
{
if (inputIndex + 3 >= inputSize) goto Done;
indicator = GetInt(inputBuffer, inputIndex);
inputIndex += sizeof(int);
indicatorBit = 32;
}
indicatorBit--;
//* check whether the bit specified by IndicatorBit is set or not
//* set in Indicator. For example, if IndicatorBit has value 4
//* check whether the 4th bit of the value in Indicator is set
if (((indicator >> indicatorBit) & 1) == 0)
{
if (outputIndex >= outputSize)
goto Done;
outputBuffer[outputIndex] = inputBuffer[inputIndex];
inputIndex += sizeof(byte);
outputIndex += sizeof(byte);
}
else
{
if (inputIndex + 1 >= inputSize)
goto Done;
length = (inputBuffer[inputIndex + 1] << 8) | inputBuffer[inputIndex];
/*
if ((OutputIndex > 0xD0) && (OutputIndex < 0xF0))
{
printf("DECOMP: READ AT [0x%08X] = %04X \n", InputIndex, Length);
}
*/
inputIndex += sizeof(ushort);
offset = length / 8;
length = length % 8;
//if ((OutputIndex > 0xD0) && (OutputIndex < 0xF0)) printf("--1 Len: %02X (%d)\n", Length, Length);
if (length == 7)
{
if (nibbleIndex == 0)
{
nibbleIndex = inputIndex;
if (inputIndex >= inputSize)
goto Done;
length = inputBuffer[inputIndex] % 16;
//if ((OutputIndex > 0xD0) && (OutputIndex < 0xF0)) printf("--2 Len: %02X (%d)\n", Length, Length);
inputIndex += sizeof(byte);
}
else
{
length = inputBuffer[nibbleIndex] / 16;
//if ((OutputIndex > 0xD0) && (OutputIndex < 0xF0)) printf("--3 Len: %02X (%d)\n", Length, Length);
nibbleIndex = 0;
}
if (length == 15)
{
if (inputIndex >= inputSize) goto Done;
length = inputBuffer[inputIndex];
//if ((OutputIndex > 0xD0) && (OutputIndex < 0xF0)) printf("--4 Len: %02X (%d)\n", Length, Length);
inputIndex += sizeof(byte);
if (length == 255)
{
if (inputIndex + 2 >= inputSize) goto Done;
length = (inputBuffer[inputIndex + 1] << 8) | inputBuffer[inputIndex];
inputIndex += sizeof(ushort);
length -= (15 + 7);
}
length += 15;
//if ((OutputIndex > 0xD0) && (OutputIndex < 0xF0)) printf("--5 Len: %02X (%d)\n", Length, Length);
}
length += 7;
//if ((OutputIndex > 0xD0) && (OutputIndex < 0xF0)) printf("--6 Len: %02X (%d)\n", Length, Length);
}
length += 3;
//if ((OutputIndex > 0xD0) && (OutputIndex < 0xF0)) printf("--7 Len: %02X (%d)\n", Length, Length);
//if (Length > 280) printf("DECOMP DEBUG: [0x%08X]->[0x%08X] Len: %d Offset: %08X\n",
// OutputIndex, InputIndex, Length, Offset);
while (length != 0)
{
if ((outputIndex >= outputSize) || ((offset + 1) >= outputIndex)) break;
outputBuffer[outputIndex] = outputBuffer[outputIndex - offset - 1];
outputIndex += sizeof(byte);
length -= sizeof(byte);
}
}
}
Done:
if (outputIndex < outputBuffer.Length)
{
var buffer = new byte[outputIndex];
Buffer.BlockCopy(outputBuffer, 0, buffer, 0, outputIndex);
outputBuffer = buffer;
}
return outputBuffer;
}
public static int GetInt(byte[] buffer, int offset)
{
return
((int)buffer[offset]) |
((int)buffer[offset + 1] << 8) |
((int)buffer[offset + 2] << 16) |
((int)buffer[offset + 3] << 24);
}