mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-07-09 02:16:46 +00:00
Create Compression models subfolder
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
namespace BurnOutSharp.Models.MicrosoftCabinet.LZX
|
||||
namespace BurnOutSharp.Models.Compression.LZX
|
||||
{
|
||||
/// <summary>
|
||||
/// An aligned offset block is identical to the verbatim block except for the presence of the aligned offset
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace BurnOutSharp.Models.MicrosoftCabinet.LZX
|
||||
namespace BurnOutSharp.Models.Compression.LZX
|
||||
{
|
||||
/// <summary>
|
||||
/// An LZXD block represents a sequence of compressed data that is encoded with the same set of
|
||||
@@ -15,7 +15,7 @@ namespace BurnOutSharp.Models.MicrosoftCabinet.LZX
|
||||
public class BlockHeader
|
||||
{
|
||||
/// <remarks>3 bits</remarks>
|
||||
public LZXBlockType BlockType;
|
||||
public BlockType BlockType;
|
||||
|
||||
/// <summary>
|
||||
/// Block size is the high 8 bits of 24
|
||||
48
BurnOutSharp.Models/Compression/LZX/Enums.cs
Normal file
48
BurnOutSharp.Models/Compression/LZX/Enums.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
namespace BurnOutSharp.Models.Compression.LZX
|
||||
{
|
||||
/// <summary>
|
||||
/// 3-bit block type
|
||||
/// </summary>
|
||||
public enum BlockType : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// Not valid
|
||||
/// </summary>
|
||||
INVALID_0 = 0b000,
|
||||
|
||||
/// <summary>
|
||||
/// Verbatim block
|
||||
/// </summary>
|
||||
Verbatim = 0b001,
|
||||
|
||||
/// <summary>
|
||||
/// Aligned offset block
|
||||
/// </summary>
|
||||
AlignedOffset = 0b010,
|
||||
|
||||
/// <summary>
|
||||
/// Uncompressed block
|
||||
/// </summary>
|
||||
Uncompressed = 0b011,
|
||||
|
||||
/// <summary>
|
||||
/// Not valid
|
||||
/// </summary>
|
||||
INVALID_4 = 0b100,
|
||||
|
||||
/// <summary>
|
||||
/// Not valid
|
||||
/// </summary>
|
||||
INVALID_5 = 0b101,
|
||||
|
||||
/// <summary>
|
||||
/// Not valid
|
||||
/// </summary>
|
||||
INVALID_6 = 0b110,
|
||||
|
||||
/// <summary>
|
||||
/// Not valid
|
||||
/// </summary>
|
||||
INVALID_7 = 0b111,
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace BurnOutSharp.Models.MicrosoftCabinet.LZX
|
||||
namespace BurnOutSharp.Models.Compression.LZX
|
||||
{
|
||||
public class Header
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace BurnOutSharp.Models.MicrosoftCabinet.LZX
|
||||
namespace BurnOutSharp.Models.Compression.LZX
|
||||
{
|
||||
/// <summary>
|
||||
/// Following the generic block header, an uncompressed block begins with 1 to 16 bits of zero padding
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace BurnOutSharp.Models.MicrosoftCabinet.LZX
|
||||
namespace BurnOutSharp.Models.Compression.LZX
|
||||
{
|
||||
/// <summary>
|
||||
/// The fields of a verbatim block that follow the generic block header
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace BurnOutSharp.Models.MicrosoftCabinet.MSZIP
|
||||
namespace BurnOutSharp.Models.Compression.MSZIP
|
||||
{
|
||||
/// <summary>
|
||||
/// Each MSZIP block MUST consist of a 2-byte MSZIP signature and one or more RFC 1951 blocks. The
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace BurnOutSharp.Models.MicrosoftCabinet.MSZIP
|
||||
namespace BurnOutSharp.Models.Compression.MSZIP
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for compressed block headers
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace BurnOutSharp.Models.MicrosoftCabinet.MSZIP
|
||||
namespace BurnOutSharp.Models.Compression.MSZIP
|
||||
{
|
||||
/// <see href="https://www.rfc-editor.org/rfc/rfc1951"/>
|
||||
public class DeflateBlockHeader
|
||||
@@ -13,7 +13,7 @@ namespace BurnOutSharp.Models.MicrosoftCabinet.MSZIP
|
||||
/// Specifies how the data are compressed
|
||||
/// </summary>
|
||||
/// <remarks>Bits 1-2</remarks>
|
||||
public DeflateCompressionType BTYPE { get; set; }
|
||||
public CompressionType BTYPE { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Block data as defined by the compression type
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace BurnOutSharp.Models.MicrosoftCabinet.MSZIP
|
||||
namespace BurnOutSharp.Models.Compression.MSZIP
|
||||
{
|
||||
/// <summary>
|
||||
/// Compression with dynamic Huffman codes (BTYPE=10)
|
||||
25
BurnOutSharp.Models/Compression/MSZIP/Enums.cs
Normal file
25
BurnOutSharp.Models/Compression/MSZIP/Enums.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
namespace BurnOutSharp.Models.Compression.MSZIP
|
||||
{
|
||||
public enum CompressionType : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// no compression
|
||||
/// </summary>
|
||||
NoCompression = 0b00,
|
||||
|
||||
/// <summary>
|
||||
/// Compressed with fixed Huffman codes
|
||||
/// </summary>
|
||||
FixedHuffman = 0b01,
|
||||
|
||||
/// <summary>
|
||||
/// Compressed with dynamic Huffman codes
|
||||
/// </summary>
|
||||
DynamicHuffman = 0b10,
|
||||
|
||||
/// <summary>
|
||||
/// Reserved (error)
|
||||
/// </summary>
|
||||
Reserved = 0b11,
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace BurnOutSharp.Models.MicrosoftCabinet.MSZIP
|
||||
namespace BurnOutSharp.Models.Compression.MSZIP
|
||||
{
|
||||
/// <summary>
|
||||
/// Compression with fixed Huffman codes (BTYPE=01)
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace BurnOutSharp.Models.MicrosoftCabinet.MSZIP
|
||||
namespace BurnOutSharp.Models.Compression.MSZIP
|
||||
{
|
||||
/// <summary>
|
||||
/// Empty interface defining block header types
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace BurnOutSharp.Models.MicrosoftCabinet.MSZIP
|
||||
namespace BurnOutSharp.Models.Compression.MSZIP
|
||||
{
|
||||
/// <summary>
|
||||
/// Non-compressed blocks (BTYPE=00)
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace BurnOutSharp.Models.MicrosoftCabinet.Quantum
|
||||
namespace BurnOutSharp.Models.Compression.Quantum
|
||||
{
|
||||
/// <summary>
|
||||
/// Quantum archive file structure
|
||||
45
BurnOutSharp.Models/Compression/Quantum/Enums.cs
Normal file
45
BurnOutSharp.Models/Compression/Quantum/Enums.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
namespace BurnOutSharp.Models.Compression.Quantum
|
||||
{
|
||||
public enum SelectorModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Literal model, 64 entries, start at symbol 0
|
||||
/// </summary>
|
||||
SELECTOR_0 = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Literal model, 64 entries, start at symbol 64
|
||||
/// </summary>
|
||||
SELECTOR_1 = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Literal model, 64 entries, start at symbol 128
|
||||
/// </summary>
|
||||
SELECTOR_2 = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Literal model, 64 entries, start at symbol 192
|
||||
/// </summary>
|
||||
SELECTOR_3 = 3,
|
||||
|
||||
/// <summary>
|
||||
/// LZ model, 3 character matches, max 24 entries, start at symbol 0
|
||||
/// </summary>
|
||||
SELECTOR_4 = 4,
|
||||
|
||||
/// <summary>
|
||||
/// LZ model, 4 character matches, max 36 entries, start at symbol 0
|
||||
/// </summary>
|
||||
SELECTOR_5 = 5,
|
||||
|
||||
/// <summary>
|
||||
/// LZ model, 5+ character matches, max 42 entries, start at symbol 0
|
||||
/// </summary>
|
||||
SELECTOR_6_POSITION = 6,
|
||||
|
||||
/// <summary>
|
||||
/// LZ model, 5+ character matches, 27 entries, start at symbol 0
|
||||
/// </summary>
|
||||
SELECTOR_6_LENGTH = 7,
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace BurnOutSharp.Models.MicrosoftCabinet.Quantum
|
||||
namespace BurnOutSharp.Models.Compression.Quantum
|
||||
{
|
||||
/// <remarks>
|
||||
/// Strings are prefixed with their length. If the length is less than
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace BurnOutSharp.Models.MicrosoftCabinet.Quantum
|
||||
namespace BurnOutSharp.Models.Compression.Quantum
|
||||
{
|
||||
/// <see href="http://www.russotto.net/quantumcomp.html"/>
|
||||
public class Model
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace BurnOutSharp.Models.MicrosoftCabinet.Quantum
|
||||
namespace BurnOutSharp.Models.Compression.Quantum
|
||||
{
|
||||
/// <see href="http://www.russotto.net/quantumcomp.html"/>
|
||||
public class ModelSymbol
|
||||
@@ -30,29 +30,6 @@ namespace BurnOutSharp.Models.MicrosoftCabinet
|
||||
TYPE_LZX = 0x0003,
|
||||
}
|
||||
|
||||
public enum DeflateCompressionType : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// no compression
|
||||
/// </summary>
|
||||
NoCompression = 0b00,
|
||||
|
||||
/// <summary>
|
||||
/// Compressed with fixed Huffman codes
|
||||
/// </summary>
|
||||
FixedHuffman = 0b01,
|
||||
|
||||
/// <summary>
|
||||
/// Compressed with dynamic Huffman codes
|
||||
/// </summary>
|
||||
DynamicHuffman = 0b10,
|
||||
|
||||
/// <summary>
|
||||
/// Reserved (error)
|
||||
/// </summary>
|
||||
Reserved = 0b11,
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum FileAttributes : ushort
|
||||
{
|
||||
@@ -138,93 +115,4 @@ namespace BurnOutSharp.Models.MicrosoftCabinet
|
||||
/// </summary>
|
||||
RESERVE_PRESENT = 0x0004,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 3-bit block type
|
||||
/// </summary>
|
||||
public enum LZXBlockType : byte
|
||||
{
|
||||
/// <summary>
|
||||
/// Not valid
|
||||
/// </summary>
|
||||
INVALID_0 = 0b000,
|
||||
|
||||
/// <summary>
|
||||
/// Verbatim block
|
||||
/// </summary>
|
||||
Verbatim = 0b001,
|
||||
|
||||
/// <summary>
|
||||
/// Aligned offset block
|
||||
/// </summary>
|
||||
AlignedOffset = 0b010,
|
||||
|
||||
/// <summary>
|
||||
/// Uncompressed block
|
||||
/// </summary>
|
||||
Uncompressed = 0b011,
|
||||
|
||||
/// <summary>
|
||||
/// Not valid
|
||||
/// </summary>
|
||||
INVALID_4 = 0b100,
|
||||
|
||||
/// <summary>
|
||||
/// Not valid
|
||||
/// </summary>
|
||||
INVALID_5 = 0b101,
|
||||
|
||||
/// <summary>
|
||||
/// Not valid
|
||||
/// </summary>
|
||||
INVALID_6 = 0b110,
|
||||
|
||||
/// <summary>
|
||||
/// Not valid
|
||||
/// </summary>
|
||||
INVALID_7 = 0b111,
|
||||
}
|
||||
|
||||
public enum QuantumSelectorModel
|
||||
{
|
||||
/// <summary>
|
||||
/// Literal model, 64 entries, start at symbol 0
|
||||
/// </summary>
|
||||
SELECTOR_0 = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Literal model, 64 entries, start at symbol 64
|
||||
/// </summary>
|
||||
SELECTOR_1 = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Literal model, 64 entries, start at symbol 128
|
||||
/// </summary>
|
||||
SELECTOR_2 = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Literal model, 64 entries, start at symbol 192
|
||||
/// </summary>
|
||||
SELECTOR_3 = 3,
|
||||
|
||||
/// <summary>
|
||||
/// LZ model, 3 character matches, max 24 entries, start at symbol 0
|
||||
/// </summary>
|
||||
SELECTOR_4 = 4,
|
||||
|
||||
/// <summary>
|
||||
/// LZ model, 4 character matches, max 36 entries, start at symbol 0
|
||||
/// </summary>
|
||||
SELECTOR_5 = 5,
|
||||
|
||||
/// <summary>
|
||||
/// LZ model, 5+ character matches, max 42 entries, start at symbol 0
|
||||
/// </summary>
|
||||
SELECTOR_6_POSITION = 6,
|
||||
|
||||
/// <summary>
|
||||
/// LZ model, 5+ character matches, 27 entries, start at symbol 0
|
||||
/// </summary>
|
||||
SELECTOR_6_LENGTH = 7,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,13 +166,13 @@ namespace BurnOutSharp.Wrappers
|
||||
/// <param name="data">BitStream representing the block</param>
|
||||
/// <param name="offset">Offset within the array to parse</param>
|
||||
/// <returns>Filled block header on success, null on error</returns>
|
||||
private static Models.MicrosoftCabinet.MSZIP.BlockHeader AsBlockHeader(BitStream data)
|
||||
private static Models.Compression.MSZIP.BlockHeader AsBlockHeader(BitStream data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
var header = new Models.MicrosoftCabinet.MSZIP.BlockHeader();
|
||||
var header = new Models.Compression.MSZIP.BlockHeader();
|
||||
|
||||
header.Signature = data.ReadAlignedUInt16();
|
||||
if (header.Signature != 0x4B43)
|
||||
@@ -187,16 +187,16 @@ namespace BurnOutSharp.Wrappers
|
||||
/// <param name="data">Byte array representing the block</param>
|
||||
/// <param name="offset">Offset within the array to parse</param>
|
||||
/// <returns>Filled deflate block header on success, null on error</returns>
|
||||
private static Models.MicrosoftCabinet.MSZIP.DeflateBlockHeader AsDeflateBlockHeader(BitStream data)
|
||||
private static Models.Compression.MSZIP.DeflateBlockHeader AsDeflateBlockHeader(BitStream data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
var header = new Models.MicrosoftCabinet.MSZIP.DeflateBlockHeader();
|
||||
var header = new Models.Compression.MSZIP.DeflateBlockHeader();
|
||||
|
||||
header.BFINAL = data.ReadBits(1)[0];
|
||||
header.BTYPE = (Models.MicrosoftCabinet.DeflateCompressionType)data.ReadBits(2).AsByte();
|
||||
header.BTYPE = (Models.Compression.MSZIP.CompressionType)data.ReadBits(2).AsByte();
|
||||
|
||||
return header;
|
||||
}
|
||||
@@ -207,13 +207,13 @@ namespace BurnOutSharp.Wrappers
|
||||
/// <param name="data">Byte array representing the block</param>
|
||||
/// <param name="offset">Offset within the array to parse</param>
|
||||
/// <returns>Filled dynamic Huffman compressed block header on success, null on error</returns>
|
||||
private static Models.MicrosoftCabinet.MSZIP.DynamicHuffmanCompressedBlockHeader AsDynamicHuffmanCompressedBlockHeader(BitStream data)
|
||||
private static Models.Compression.MSZIP.DynamicHuffmanCompressedBlockHeader AsDynamicHuffmanCompressedBlockHeader(BitStream data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
var header = new Models.MicrosoftCabinet.MSZIP.DynamicHuffmanCompressedBlockHeader();
|
||||
var header = new Models.Compression.MSZIP.DynamicHuffmanCompressedBlockHeader();
|
||||
|
||||
// # of Literal/Length codes - 257
|
||||
ushort HLIT = (ushort)(data.ReadBits(5).AsUInt16() + 257);
|
||||
@@ -255,13 +255,13 @@ namespace BurnOutSharp.Wrappers
|
||||
/// <param name="data">Byte array representing the block</param>
|
||||
/// <param name="offset">Offset within the array to parse</param>
|
||||
/// <returns>Filled non-compressed block header on success, null on error</returns>
|
||||
private static Models.MicrosoftCabinet.MSZIP.NonCompressedBlockHeader AsNonCompressedBlockHeader(BitStream data)
|
||||
private static Models.Compression.MSZIP.NonCompressedBlockHeader AsNonCompressedBlockHeader(BitStream data)
|
||||
{
|
||||
// If the data is invalid
|
||||
if (data == null)
|
||||
return null;
|
||||
|
||||
var header = new Models.MicrosoftCabinet.MSZIP.NonCompressedBlockHeader();
|
||||
var header = new Models.Compression.MSZIP.NonCompressedBlockHeader();
|
||||
|
||||
header.LEN = data.ReadAlignedUInt16();
|
||||
header.NLEN = data.ReadAlignedUInt16();
|
||||
@@ -508,18 +508,18 @@ namespace BurnOutSharp.Wrappers
|
||||
List<byte> decodedBytes = new List<byte>();
|
||||
|
||||
// Create the loop variable block
|
||||
Models.MicrosoftCabinet.MSZIP.DeflateBlockHeader deflateBlockHeader;
|
||||
Models.Compression.MSZIP.DeflateBlockHeader deflateBlockHeader;
|
||||
|
||||
do
|
||||
{
|
||||
deflateBlockHeader = AsDeflateBlockHeader(dataStream);
|
||||
|
||||
// We should never get a reserved block
|
||||
if (deflateBlockHeader.BTYPE == Models.MicrosoftCabinet.DeflateCompressionType.Reserved)
|
||||
if (deflateBlockHeader.BTYPE == Models.Compression.MSZIP.CompressionType.Reserved)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
// If stored with no compression
|
||||
if (deflateBlockHeader.BTYPE == Models.MicrosoftCabinet.DeflateCompressionType.NoCompression)
|
||||
if (deflateBlockHeader.BTYPE == Models.Compression.MSZIP.CompressionType.NoCompression)
|
||||
{
|
||||
// Skip any remaining bits in current partially processed byte
|
||||
dataStream.DiscardBuffer();
|
||||
@@ -528,7 +528,7 @@ namespace BurnOutSharp.Wrappers
|
||||
deflateBlockHeader.BlockDataHeader = AsNonCompressedBlockHeader(dataStream);
|
||||
|
||||
// Copy LEN bytes of data to output
|
||||
var header = deflateBlockHeader.BlockDataHeader as Models.MicrosoftCabinet.MSZIP.NonCompressedBlockHeader;
|
||||
var header = deflateBlockHeader.BlockDataHeader as Models.Compression.MSZIP.NonCompressedBlockHeader;
|
||||
ushort length = header.LEN;
|
||||
decodedBytes.AddRange(dataStream.ReadAlignedBytes(length));
|
||||
}
|
||||
@@ -539,15 +539,15 @@ namespace BurnOutSharp.Wrappers
|
||||
// If compressed with dynamic Huffman codes read representation of code trees
|
||||
switch (deflateBlockHeader.BTYPE)
|
||||
{
|
||||
case Models.MicrosoftCabinet.DeflateCompressionType.FixedHuffman:
|
||||
deflateBlockHeader.BlockDataHeader = new Models.MicrosoftCabinet.MSZIP.FixedHuffmanCompressedBlockHeader();
|
||||
case Models.Compression.MSZIP.CompressionType.FixedHuffman:
|
||||
deflateBlockHeader.BlockDataHeader = new Models.Compression.MSZIP.FixedHuffmanCompressedBlockHeader();
|
||||
break;
|
||||
case Models.MicrosoftCabinet.DeflateCompressionType.DynamicHuffman:
|
||||
case Models.Compression.MSZIP.CompressionType.DynamicHuffman:
|
||||
deflateBlockHeader.BlockDataHeader = AsDynamicHuffmanCompressedBlockHeader(dataStream);
|
||||
break;
|
||||
}
|
||||
|
||||
var header = deflateBlockHeader.BlockDataHeader as Models.MicrosoftCabinet.MSZIP.CompressedBlockHeader;
|
||||
var header = deflateBlockHeader.BlockDataHeader as Models.Compression.MSZIP.CompressedBlockHeader;
|
||||
|
||||
// 9 bits per entry, 288 max symbols
|
||||
int[] literalDecodeTable = CreateTable(288, 9, header.LiteralLengths, (1 << 9) + (288 * 2));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using BurnOutSharp.Models.MicrosoftCabinet.Quantum;
|
||||
using BurnOutSharp.Models.Compression.Quantum;
|
||||
|
||||
/// <see href="http://www.russotto.net/quantumcomp.html"/>
|
||||
/// <see href="https://handwiki.org/wiki/Software:Quantum_compression"/>
|
||||
|
||||
Reference in New Issue
Block a user