Skip to content

Commit

Permalink
Added GPL license.
Browse files Browse the repository at this point in the history
  • Loading branch information
coderforlife committed May 17, 2012
1 parent 60ba940 commit fc8e433
Show file tree
Hide file tree
Showing 19 changed files with 1,010 additions and 8 deletions.
674 changes: 674 additions & 0 deletions gpl.txt

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions library/Bitstream.cpp
@@ -1,3 +1,20 @@
// ms-compress: implements Microsoft compression algorithms
// Copyright (C) 2012 Jeffrey Bush jeff@coderforlife.com
//
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.


#include "Bitstream.h"

#ifdef __cplusplus_cli
Expand Down
17 changes: 17 additions & 0 deletions library/Bitstream.h
@@ -1,3 +1,20 @@
// ms-compress: implements Microsoft compression algorithms
// Copyright (C) 2012 Jeffrey Bush jeff@coderforlife.com
//
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.


////////////////////////////// Bitstreams //////////////////////////////////////////////////////////
// A bitstream that allows either reading or writing, but not both at the same time.
// It reads uint16s for bits and 16 bits can be reliably read at a time
Expand Down
17 changes: 17 additions & 0 deletions library/Dictionary.cpp
@@ -1,3 +1,20 @@
// ms-compress: implements Microsoft compression algorithms
// Copyright (C) 2012 Jeffrey Bush jeff@coderforlife.com
//
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.


#include "Dictionary.h"

// Implementation designed for being extremely fast at the expense of memory
Expand Down
17 changes: 17 additions & 0 deletions library/Dictionary.h
@@ -1,3 +1,20 @@
// ms-compress: implements Microsoft compression algorithms
// Copyright (C) 2012 Jeffrey Bush jeff@coderforlife.com
//
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.


/////////////////// Dictionary /////////////////////////////////////////////////
// The dictionary system used for LZNT1 and XPRESS compression.
//
Expand Down
21 changes: 20 additions & 1 deletion library/compression-api.h
@@ -1,3 +1,22 @@
// ms-compress: implements Microsoft compression algorithms
// Copyright (C) 2012 Jeffrey Bush jeff@coderforlife.com
//
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.


// General include file which includes necessary files, defines, and typedefs.

#ifndef COMPRESSION_API_H
#define COMPRESSION_API_H

Expand Down Expand Up @@ -142,7 +161,7 @@
#define E_INVALID_DATA 0x103

// Define types used
typedef uint8_t byte;
typedef uint8_t byte; // should always be unsigned char (there is a check for CHAR_BIT == 8 above)
typedef byte* bytes;
typedef const byte const_byte;
typedef const_byte* const_bytes;
Expand Down
18 changes: 18 additions & 0 deletions library/compression.cpp
@@ -1,3 +1,20 @@
// ms-compress: implements Microsoft compression algorithms
// Copyright (C) 2012 Jeffrey Bush jeff@coderforlife.com
//
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.


#include "compression.h"

#include "lznt1.h"
Expand All @@ -13,6 +30,7 @@
#define ARRAYSIZE(x) sizeof(x)/sizeof(x[0])
#endif

// no-compression compression function
size_t copy_data(const_bytes in, size_t in_len, bytes out, size_t out_len)
{
if (in_len > out_len)
Expand Down
27 changes: 22 additions & 5 deletions library/compression.h
@@ -1,17 +1,34 @@
// Compression and Decompression Functions
// ms-compress: implements Microsoft compression algorithms
// Copyright (C) 2012 Jeffrey Bush jeff@coderforlife.com
//
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.


// Compression and Decompression Functions
//
// These mimic RtlCompressBuffer and RtlDecompressBuffer from NTDLL.DLL. They provide access to
// LZX (WIM), LZNT1, Xpress (LZ), and Xpress Huffman algorithms. They attempt to provide results
// similar to the RTL functions in terms of speed and compression rate. The RTL functions do not
// accept the LZX format. Also, the provided functions always use the 'maximum engine'. For
// differences in the specific algorithms see their header files.

// Here is how to convert between the RTL functions and these functions:

//err = RtlCompressBuffer(FORMAT|MAX, in, in_len, out, out_len, 4096, &size, ***);
//
//err = RtlCompressBuffer(FORMAT|MAX, in, in_len, out, out_len, 4096, &size, ***); // chunk size and temporary buffer arguments dropped
//size = compress(FORMAT, in, in_len, out, out_len); if (size == 0) err = errno;

//err = RtlDecompressBuffer(FORMAT, out, out_len, in, in_len, &size); // (switched order of in and out!)
//
//err = RtlDecompressBuffer(FORMAT, out, out_len, in, in_len, &size); // switched order of in and out!
//size = decompress(FORMAT, in, in_len, out, out_len); if (size == 0) err = errno;

#ifndef COMPRESSION_H
Expand Down
17 changes: 17 additions & 0 deletions library/lznt1.cpp
@@ -1,3 +1,20 @@
// ms-compress: implements Microsoft compression algorithms
// Copyright (C) 2012 Jeffrey Bush jeff@coderforlife.com
//
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.


#include "lznt1.h"

#include "Dictionary.h"
Expand Down
17 changes: 17 additions & 0 deletions library/lznt1.h
@@ -1,3 +1,20 @@
// ms-compress: implements Microsoft compression algorithms
// Copyright (C) 2012 Jeffrey Bush jeff@coderforlife.com
//
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.


// LZNT1 Compression and Decompression Functions
//
// This algorithm is used for NTFS file compression, Windows 2000 hibernation file, Active
Expand Down
18 changes: 18 additions & 0 deletions library/lzx.cpp
@@ -1,3 +1,21 @@
// ms-compress: implements Microsoft compression algorithms
// Copyright (C) 2012 Jeffrey Bush jeff@coderforlife.com
//
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

// This code is adapted from 7-zip. See http://www.7-zip.org/.

#include "lzx.h"

#include "Bitstream.h"
Expand Down
17 changes: 17 additions & 0 deletions library/lzx.h
@@ -1,3 +1,20 @@
// ms-compress: implements Microsoft compression algorithms
// Copyright (C) 2012 Jeffrey Bush jeff@coderforlife.com
//
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.


// Implements the LZX decompression algorithm used in WIM files.
// This is very similar to LZX decompression for CAB files with some minor differences.
//
Expand Down
35 changes: 35 additions & 0 deletions library/xpress.cpp
@@ -1,3 +1,20 @@
// ms-compress: implements Microsoft compression algorithms
// Copyright (C) 2012 Jeffrey Bush jeff@coderforlife.com
//
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.


#include "xpress.h"

#ifdef __cplusplus_cli
Expand Down Expand Up @@ -68,6 +85,24 @@ static void xpress_hashes_init_lcg()
}
xpress_hashes_initialized = true;
}
// Common LCG parameters:
//MSVCRT: inline static void xpress_hashes_init() { xpress_hashes_init_lcg<SEED, 214013ul, 2531011ul, (1ull << 32), 16>(); }
//RtlUniform: inline static void xpress_hashes_init() { xpress_hashes_init_lcg<SEED, 0x 7FFFFFEDul, 0x7FFFFFC3ul, (1ull << 31)-1, 15>(); }
//Java: inline static void xpress_hashes_init() { xpress_hashes_init_lcg<SEED, 0x5DEECE66Dul, 11ul, (1ull << 48), 48-15>(); } // the SEED is processed with (SEED ^ 0x5DEECE66Dul) % (1ull << 48)
//GLIBC: inline static void xpress_hashes_init() { xpress_hashes_init_lcg<SEED, 0x 41C64E6Dul, 12345ul, (1ull << 32), 16>(); }
//CarbonLib: inline static void xpress_hashes_init() { xpress_hashes_init_lcg<SEED, 16807ul, 0ul, (1ull << 31)-1, 15>(); } // Also called MINSTD
// The real Microsoft one for XPRESS is similar to a LCG but not quite the same. It uses a seed of 0x13579BDFul. The inside loop of the LCG is changed to:
// uint32_t a = 0, b = hash, c = 0x87654321u;
// int k;
// for (k = 0; k < 32; ++k)
// {
// uint32_t d;
// a -= 0x61C88647u; b += a; c += a;
// d = ((c + 0x3B2A1908) ^ (b + 0x43B2A19) ^ (a - 0x789ABCDF)) + hash;
// hash = ((a + d) ^ (c + (d >> 5)) ^ (b + (d << 3))) + d;
// }
// table[j] = (hash -= 0x789ABCDFu) & (MAX_HASH - 1);

// Initialize using the LCG with constants from GLIBC rand() and a "random" seed
inline static void xpress_hashes_init() { xpress_hashes_init_lcg<0x001A5BA5u, 0x41C64E6Du, 12345u, 1ull << 32, 16>(); }
inline static uint_fast16_t xpress_hash(const const_bytes x) { return xpress_hashes[0][x[0]] ^ xpress_hashes[1][x[1]] ^ xpress_hashes[2][x[2]]; }
Expand Down
17 changes: 17 additions & 0 deletions library/xpress.h
@@ -1,3 +1,20 @@
// ms-compress: implements Microsoft compression algorithms
// Copyright (C) 2012 Jeffrey Bush jeff@coderforlife.com
//
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.


// Xpress Compression and Decompression Functions
//
// This is the LZ version of the Xpress algorithm, used for Windows XP and newer hibernation file,
Expand Down
17 changes: 17 additions & 0 deletions library/xpress_huff.cpp
@@ -1,3 +1,20 @@
// ms-compress: implements Microsoft compression algorithms
// Copyright (C) 2012 Jeffrey Bush jeff@coderforlife.com
//
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.


#include "xpress_huff.h"

#include "Dictionary.h"
Expand Down
17 changes: 17 additions & 0 deletions library/xpress_huff.h
@@ -1,3 +1,20 @@
// ms-compress: implements Microsoft compression algorithms
// Copyright (C) 2012 Jeffrey Bush jeff@coderforlife.com
//
// This library is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.


// Xpress Huffman Compression and Decompression Functions
//
// This is the Xpress compression used in WIM files not the hibernation file.
Expand Down
17 changes: 17 additions & 0 deletions stdafx.cpp
@@ -1 +1,18 @@
// ms-compress-test: implements Microsoft compression algorithms
// Copyright (C) 2012 Jeffrey Bush jeff@coderforlife.com
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.


#include "stdafx.h"

0 comments on commit fc8e433

Please sign in to comment.