-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathXpress2.cs
47 lines (38 loc) · 1.62 KB
/
Xpress2.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.Runtime.InteropServices;
namespace Prefetch.XpressStream;
public static class Xpress2
{
// const ushort COMPRESSION_FORMAT_LZNT1 = 2;
// const ushort COMPRESSION_FORMAT_XPRESS = 3;
private const ushort CompressionFormatXpressHuff = 4;
[DllImport("ntdll.dll")]
private static extern uint RtlGetCompressionWorkSpaceSize(ushort compressionFormat,
ref ulong compressBufferWorkSpaceSize, ref ulong compressFragmentWorkSpaceSize);
[DllImport("ntdll.dll")]
private static extern uint RtlDecompressBufferEx(ushort compressionFormat, byte[] uncompressedBuffer,
int uncompressedBufferSize, byte[] compressedBuffer, int compressedBufferSize, ref int finalUncompressedSize,
byte[] workSpace);
public static byte[] Decompress(byte[] buffer, ulong decompressedSize)
{
// our uncompressed data will go here
var outBuf = new byte[decompressedSize];
ulong compressBufferWorkSpaceSize = 0;
ulong compressFragmentWorkSpaceSize = 0;
//get the size of what our workspace needs to be
var ret = RtlGetCompressionWorkSpaceSize(CompressionFormatXpressHuff, ref compressBufferWorkSpaceSize,
ref compressFragmentWorkSpaceSize);
if (ret != 0)
{
return null;
}
var workSpace = new byte[compressFragmentWorkSpaceSize];
var dstSize = 0;
ret = RtlDecompressBufferEx(CompressionFormatXpressHuff, outBuf, outBuf.Length, buffer, buffer.Length,
ref dstSize, workSpace);
//if (ret == 0)
// {
return outBuf;
// }
//return null;
}
}