├── Developing PE Packer Article by Hamid.Memar.html ├── LICENSE ├── README.md ├── aes.c ├── aes.h ├── lzma2 ├── atomic.h ├── compiler.h ├── count.h ├── data_block.h ├── dict_buffer.h ├── fast-lzma2.h ├── fast-lzma2.lib ├── fastpos_table.h ├── fl2_compress_internal.h ├── fl2_errors.h ├── fl2_internal.h ├── fl2_pool.h ├── fl2_threading.h ├── lzma2_dec.h ├── lzma2_enc.h ├── mem.h ├── platform.h ├── radix_engine.h ├── radix_get.h ├── radix_internal.h ├── radix_mf.h ├── range_enc.h ├── util.h └── xxhash.h ├── mmLoader.c ├── mmLoader.h ├── packer.cpp ├── packer.vcxproj ├── packer.vcxproj.user ├── pe_packer_tutorial.sln ├── resolvers ├── kernel32.lib └── msvcrt.lib ├── unpacker.cpp ├── unpacker_stub.h ├── unpacker_stub.vcxproj ├── utilities └── hmrclib64_vc16.lib └── win64 ├── app.ico ├── dll ├── input_pe.dll └── pe_dll_tester.exe ├── exe └── input_pe.exe ├── pe_packer_test_dll.bat ├── pe_packer_test_exe.bat └── pe_packer_test_self.bat /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 The Ænema (Hamid.Memar) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HM PE Packer 2 | A x64 PE Packer/Protector Developed in C++ and VisualStudio 3 | 4 | 5 | This is a source repo for complete tutorial : 6 | https://www.codeproject.com/Articles/5317556/Creating-Your-Very-Own-x64-PE-Packer-Protector 7 | -------------------------------------------------------------------------------- /aes.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | This is an implementation of the AES algorithm, specifically ECB, CTR and CBC mode. 4 | Block size can be chosen in aes.h - available choices are AES128, AES192, AES256. 5 | 6 | The implementation is verified against the test vectors in: 7 | National Institute of Standards and Technology Special Publication 800-38A 2001 ED 8 | 9 | ECB-AES128 10 | ---------- 11 | 12 | plain-text: 13 | 6bc1bee22e409f96e93d7e117393172a 14 | ae2d8a571e03ac9c9eb76fac45af8e51 15 | 30c81c46a35ce411e5fbc1191a0a52ef 16 | f69f2445df4f9b17ad2b417be66c3710 17 | 18 | key: 19 | 2b7e151628aed2a6abf7158809cf4f3c 20 | 21 | resulting cipher 22 | 3ad77bb40d7a3660a89ecaf32466ef97 23 | f5d3d58503b9699de785895a96fdbaaf 24 | 43b1cd7f598ece23881b00e3ed030688 25 | 7b0c785e27e8ad3f8223207104725dd4 26 | 27 | 28 | NOTE: String length must be evenly divisible by 16byte (str_len % 16 == 0) 29 | You should pad the end of the string with zeros if this is not the case. 30 | For AES192/256 the key size is proportionally larger. 31 | 32 | */ 33 | 34 | 35 | /*****************************************************************************/ 36 | /* Includes: */ 37 | /*****************************************************************************/ 38 | #include // CBC mode, for memset 39 | #include "aes.h" 40 | 41 | /*****************************************************************************/ 42 | /* Defines: */ 43 | /*****************************************************************************/ 44 | // The number of columns comprising a state in AES. This is a constant in AES. Value=4 45 | #define Nb 4 46 | 47 | #if defined(AES256) && (AES256 == 1) 48 | #define Nk 8 49 | #define Nr 14 50 | #elif defined(AES192) && (AES192 == 1) 51 | #define Nk 6 52 | #define Nr 12 53 | #else 54 | #define Nk 4 // The number of 32 bit words in a key. 55 | #define Nr 10 // The number of rounds in AES Cipher. 56 | #endif 57 | 58 | // jcallan@github points out that declaring Multiply as a function 59 | // reduces code size considerably with the Keil ARM compiler. 60 | // See this link for more information: https://github.com/kokke/tiny-AES-C/pull/3 61 | #ifndef MULTIPLY_AS_A_FUNCTION 62 | #define MULTIPLY_AS_A_FUNCTION 0 63 | #endif 64 | 65 | 66 | 67 | 68 | /*****************************************************************************/ 69 | /* Private variables: */ 70 | /*****************************************************************************/ 71 | // state - array holding the intermediate results during decryption. 72 | typedef uint8_t state_t[4][4]; 73 | 74 | 75 | 76 | // The lookup-tables are marked const so they can be placed in read-only storage instead of RAM 77 | // The numbers below can be computed dynamically trading ROM for RAM - 78 | // This can be useful in (embedded) bootloader applications, where ROM is often limited. 79 | static const uint8_t sbox[256] = { 80 | //0 1 2 3 4 5 6 7 8 9 A B C D E F 81 | 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, 82 | 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 83 | 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, 84 | 0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, 85 | 0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, 86 | 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, 87 | 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, 88 | 0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 89 | 0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, 90 | 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, 91 | 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 92 | 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, 93 | 0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, 94 | 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, 95 | 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, 96 | 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 }; 97 | 98 | #if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1) 99 | static const uint8_t rsbox[256] = { 100 | 0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38, 0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb, 101 | 0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87, 0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb, 102 | 0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d, 0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e, 103 | 0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2, 0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25, 104 | 0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16, 0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92, 105 | 0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda, 0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84, 106 | 0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a, 0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06, 107 | 0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02, 0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b, 108 | 0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea, 0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73, 109 | 0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85, 0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e, 110 | 0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89, 0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b, 111 | 0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20, 0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4, 112 | 0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31, 0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f, 113 | 0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d, 0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef, 114 | 0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0, 0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61, 115 | 0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26, 0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d }; 116 | #endif 117 | 118 | // The round constant word array, Rcon[i], contains the values given by 119 | // x to the power (i-1) being powers of x (x is denoted as {02}) in the field GF(2^8) 120 | static const uint8_t Rcon[11] = { 121 | 0x8d, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 }; 122 | 123 | /* 124 | * Jordan Goulder points out in PR #12 (https://github.com/kokke/tiny-AES-C/pull/12), 125 | * that you can remove most of the elements in the Rcon array, because they are unused. 126 | * 127 | * From Wikipedia's article on the Rijndael key schedule @ https://en.wikipedia.org/wiki/Rijndael_key_schedule#Rcon 128 | * 129 | * "Only the first some of these constants are actually used – up to rcon[10] for AES-128 (as 11 round keys are needed), 130 | * up to rcon[8] for AES-192, up to rcon[7] for AES-256. rcon[0] is not used in AES algorithm." 131 | */ 132 | 133 | 134 | /*****************************************************************************/ 135 | /* Private functions: */ 136 | /*****************************************************************************/ 137 | /* 138 | static uint8_t getSBoxValue(uint8_t num) 139 | { 140 | return sbox[num]; 141 | } 142 | */ 143 | #define getSBoxValue(num) (sbox[(num)]) 144 | 145 | // This function produces Nb(Nr+1) round keys. The round keys are used in each round to decrypt the states. 146 | static void KeyExpansion(uint8_t* RoundKey, const uint8_t* Key) 147 | { 148 | unsigned i, j, k; 149 | uint8_t tempa[4]; // Used for the column/row operations 150 | 151 | // The first round key is the key itself. 152 | for (i = 0; i < Nk; ++i) 153 | { 154 | RoundKey[(i * 4) + 0] = Key[(i * 4) + 0]; 155 | RoundKey[(i * 4) + 1] = Key[(i * 4) + 1]; 156 | RoundKey[(i * 4) + 2] = Key[(i * 4) + 2]; 157 | RoundKey[(i * 4) + 3] = Key[(i * 4) + 3]; 158 | } 159 | 160 | // All other round keys are found from the previous round keys. 161 | for (i = Nk; i < Nb * (Nr + 1); ++i) 162 | { 163 | { 164 | k = (i - 1) * 4; 165 | tempa[0]=RoundKey[k + 0]; 166 | tempa[1]=RoundKey[k + 1]; 167 | tempa[2]=RoundKey[k + 2]; 168 | tempa[3]=RoundKey[k + 3]; 169 | 170 | } 171 | 172 | if (i % Nk == 0) 173 | { 174 | // This function shifts the 4 bytes in a word to the left once. 175 | // [a0,a1,a2,a3] becomes [a1,a2,a3,a0] 176 | 177 | // Function RotWord() 178 | { 179 | const uint8_t u8tmp = tempa[0]; 180 | tempa[0] = tempa[1]; 181 | tempa[1] = tempa[2]; 182 | tempa[2] = tempa[3]; 183 | tempa[3] = u8tmp; 184 | } 185 | 186 | // SubWord() is a function that takes a four-byte input word and 187 | // applies the S-box to each of the four bytes to produce an output word. 188 | 189 | // Function Subword() 190 | { 191 | tempa[0] = getSBoxValue(tempa[0]); 192 | tempa[1] = getSBoxValue(tempa[1]); 193 | tempa[2] = getSBoxValue(tempa[2]); 194 | tempa[3] = getSBoxValue(tempa[3]); 195 | } 196 | 197 | tempa[0] = tempa[0] ^ Rcon[i/Nk]; 198 | } 199 | #if defined(AES256) && (AES256 == 1) 200 | if (i % Nk == 4) 201 | { 202 | // Function Subword() 203 | { 204 | tempa[0] = getSBoxValue(tempa[0]); 205 | tempa[1] = getSBoxValue(tempa[1]); 206 | tempa[2] = getSBoxValue(tempa[2]); 207 | tempa[3] = getSBoxValue(tempa[3]); 208 | } 209 | } 210 | #endif 211 | j = i * 4; k=(i - Nk) * 4; 212 | RoundKey[j + 0] = RoundKey[k + 0] ^ tempa[0]; 213 | RoundKey[j + 1] = RoundKey[k + 1] ^ tempa[1]; 214 | RoundKey[j + 2] = RoundKey[k + 2] ^ tempa[2]; 215 | RoundKey[j + 3] = RoundKey[k + 3] ^ tempa[3]; 216 | } 217 | } 218 | 219 | void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key) 220 | { 221 | KeyExpansion(ctx->RoundKey, key); 222 | } 223 | #if (defined(CBC) && (CBC == 1)) || (defined(CTR) && (CTR == 1)) 224 | void AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, const uint8_t* iv) 225 | { 226 | KeyExpansion(ctx->RoundKey, key); 227 | memcpy (ctx->Iv, iv, AES_BLOCKLEN); 228 | } 229 | void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv) 230 | { 231 | memcpy (ctx->Iv, iv, AES_BLOCKLEN); 232 | } 233 | #endif 234 | 235 | // This function adds the round key to state. 236 | // The round key is added to the state by an XOR function. 237 | static void AddRoundKey(uint8_t round, state_t* state, const uint8_t* RoundKey) 238 | { 239 | uint8_t i,j; 240 | for (i = 0; i < 4; ++i) 241 | { 242 | for (j = 0; j < 4; ++j) 243 | { 244 | (*state)[i][j] ^= RoundKey[(round * Nb * 4) + (i * Nb) + j]; 245 | } 246 | } 247 | } 248 | 249 | // The SubBytes Function Substitutes the values in the 250 | // state matrix with values in an S-box. 251 | static void SubBytes(state_t* state) 252 | { 253 | uint8_t i, j; 254 | for (i = 0; i < 4; ++i) 255 | { 256 | for (j = 0; j < 4; ++j) 257 | { 258 | (*state)[j][i] = getSBoxValue((*state)[j][i]); 259 | } 260 | } 261 | } 262 | 263 | // The ShiftRows() function shifts the rows in the state to the left. 264 | // Each row is shifted with different offset. 265 | // Offset = Row number. So the first row is not shifted. 266 | static void ShiftRows(state_t* state) 267 | { 268 | uint8_t temp; 269 | 270 | // Rotate first row 1 columns to left 271 | temp = (*state)[0][1]; 272 | (*state)[0][1] = (*state)[1][1]; 273 | (*state)[1][1] = (*state)[2][1]; 274 | (*state)[2][1] = (*state)[3][1]; 275 | (*state)[3][1] = temp; 276 | 277 | // Rotate second row 2 columns to left 278 | temp = (*state)[0][2]; 279 | (*state)[0][2] = (*state)[2][2]; 280 | (*state)[2][2] = temp; 281 | 282 | temp = (*state)[1][2]; 283 | (*state)[1][2] = (*state)[3][2]; 284 | (*state)[3][2] = temp; 285 | 286 | // Rotate third row 3 columns to left 287 | temp = (*state)[0][3]; 288 | (*state)[0][3] = (*state)[3][3]; 289 | (*state)[3][3] = (*state)[2][3]; 290 | (*state)[2][3] = (*state)[1][3]; 291 | (*state)[1][3] = temp; 292 | } 293 | 294 | static uint8_t xtime(uint8_t x) 295 | { 296 | return ((x<<1) ^ (((x>>7) & 1) * 0x1b)); 297 | } 298 | 299 | // MixColumns function mixes the columns of the state matrix 300 | static void MixColumns(state_t* state) 301 | { 302 | uint8_t i; 303 | uint8_t Tmp, Tm, t; 304 | for (i = 0; i < 4; ++i) 305 | { 306 | t = (*state)[i][0]; 307 | Tmp = (*state)[i][0] ^ (*state)[i][1] ^ (*state)[i][2] ^ (*state)[i][3] ; 308 | Tm = (*state)[i][0] ^ (*state)[i][1] ; Tm = xtime(Tm); (*state)[i][0] ^= Tm ^ Tmp ; 309 | Tm = (*state)[i][1] ^ (*state)[i][2] ; Tm = xtime(Tm); (*state)[i][1] ^= Tm ^ Tmp ; 310 | Tm = (*state)[i][2] ^ (*state)[i][3] ; Tm = xtime(Tm); (*state)[i][2] ^= Tm ^ Tmp ; 311 | Tm = (*state)[i][3] ^ t ; Tm = xtime(Tm); (*state)[i][3] ^= Tm ^ Tmp ; 312 | } 313 | } 314 | 315 | // Multiply is used to multiply numbers in the field GF(2^8) 316 | // Note: The last call to xtime() is unneeded, but often ends up generating a smaller binary 317 | // The compiler seems to be able to vectorize the operation better this way. 318 | // See https://github.com/kokke/tiny-AES-c/pull/34 319 | #if MULTIPLY_AS_A_FUNCTION 320 | static uint8_t Multiply(uint8_t x, uint8_t y) 321 | { 322 | return (((y & 1) * x) ^ 323 | ((y>>1 & 1) * xtime(x)) ^ 324 | ((y>>2 & 1) * xtime(xtime(x))) ^ 325 | ((y>>3 & 1) * xtime(xtime(xtime(x)))) ^ 326 | ((y>>4 & 1) * xtime(xtime(xtime(xtime(x)))))); /* this last call to xtime() can be omitted */ 327 | } 328 | #else 329 | #define Multiply(x, y) \ 330 | ( ((y & 1) * x) ^ \ 331 | ((y>>1 & 1) * xtime(x)) ^ \ 332 | ((y>>2 & 1) * xtime(xtime(x))) ^ \ 333 | ((y>>3 & 1) * xtime(xtime(xtime(x)))) ^ \ 334 | ((y>>4 & 1) * xtime(xtime(xtime(xtime(x)))))) \ 335 | 336 | #endif 337 | 338 | #if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1) 339 | /* 340 | static uint8_t getSBoxInvert(uint8_t num) 341 | { 342 | return rsbox[num]; 343 | } 344 | */ 345 | #define getSBoxInvert(num) (rsbox[(num)]) 346 | 347 | // MixColumns function mixes the columns of the state matrix. 348 | // The method used to multiply may be difficult to understand for the inexperienced. 349 | // Please use the references to gain more information. 350 | static void InvMixColumns(state_t* state) 351 | { 352 | int i; 353 | uint8_t a, b, c, d; 354 | for (i = 0; i < 4; ++i) 355 | { 356 | a = (*state)[i][0]; 357 | b = (*state)[i][1]; 358 | c = (*state)[i][2]; 359 | d = (*state)[i][3]; 360 | 361 | (*state)[i][0] = Multiply(a, 0x0e) ^ Multiply(b, 0x0b) ^ Multiply(c, 0x0d) ^ Multiply(d, 0x09); 362 | (*state)[i][1] = Multiply(a, 0x09) ^ Multiply(b, 0x0e) ^ Multiply(c, 0x0b) ^ Multiply(d, 0x0d); 363 | (*state)[i][2] = Multiply(a, 0x0d) ^ Multiply(b, 0x09) ^ Multiply(c, 0x0e) ^ Multiply(d, 0x0b); 364 | (*state)[i][3] = Multiply(a, 0x0b) ^ Multiply(b, 0x0d) ^ Multiply(c, 0x09) ^ Multiply(d, 0x0e); 365 | } 366 | } 367 | 368 | 369 | // The SubBytes Function Substitutes the values in the 370 | // state matrix with values in an S-box. 371 | static void InvSubBytes(state_t* state) 372 | { 373 | uint8_t i, j; 374 | for (i = 0; i < 4; ++i) 375 | { 376 | for (j = 0; j < 4; ++j) 377 | { 378 | (*state)[j][i] = getSBoxInvert((*state)[j][i]); 379 | } 380 | } 381 | } 382 | 383 | static void InvShiftRows(state_t* state) 384 | { 385 | uint8_t temp; 386 | 387 | // Rotate first row 1 columns to right 388 | temp = (*state)[3][1]; 389 | (*state)[3][1] = (*state)[2][1]; 390 | (*state)[2][1] = (*state)[1][1]; 391 | (*state)[1][1] = (*state)[0][1]; 392 | (*state)[0][1] = temp; 393 | 394 | // Rotate second row 2 columns to right 395 | temp = (*state)[0][2]; 396 | (*state)[0][2] = (*state)[2][2]; 397 | (*state)[2][2] = temp; 398 | 399 | temp = (*state)[1][2]; 400 | (*state)[1][2] = (*state)[3][2]; 401 | (*state)[3][2] = temp; 402 | 403 | // Rotate third row 3 columns to right 404 | temp = (*state)[0][3]; 405 | (*state)[0][3] = (*state)[1][3]; 406 | (*state)[1][3] = (*state)[2][3]; 407 | (*state)[2][3] = (*state)[3][3]; 408 | (*state)[3][3] = temp; 409 | } 410 | #endif // #if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1) 411 | 412 | // Cipher is the main function that encrypts the PlainText. 413 | static void Cipher(state_t* state, const uint8_t* RoundKey) 414 | { 415 | uint8_t round = 0; 416 | 417 | // Add the First round key to the state before starting the rounds. 418 | AddRoundKey(0, state, RoundKey); 419 | 420 | // There will be Nr rounds. 421 | // The first Nr-1 rounds are identical. 422 | // These Nr rounds are executed in the loop below. 423 | // Last one without MixColumns() 424 | for (round = 1; ; ++round) 425 | { 426 | SubBytes(state); 427 | ShiftRows(state); 428 | if (round == Nr) { 429 | break; 430 | } 431 | MixColumns(state); 432 | AddRoundKey(round, state, RoundKey); 433 | } 434 | // Add round key to last round 435 | AddRoundKey(Nr, state, RoundKey); 436 | } 437 | 438 | #if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1) 439 | static void InvCipher(state_t* state, const uint8_t* RoundKey) 440 | { 441 | uint8_t round = 0; 442 | 443 | // Add the First round key to the state before starting the rounds. 444 | AddRoundKey(Nr, state, RoundKey); 445 | 446 | // There will be Nr rounds. 447 | // The first Nr-1 rounds are identical. 448 | // These Nr rounds are executed in the loop below. 449 | // Last one without InvMixColumn() 450 | for (round = (Nr - 1); ; --round) 451 | { 452 | InvShiftRows(state); 453 | InvSubBytes(state); 454 | AddRoundKey(round, state, RoundKey); 455 | if (round == 0) { 456 | break; 457 | } 458 | InvMixColumns(state); 459 | } 460 | 461 | } 462 | #endif // #if (defined(CBC) && CBC == 1) || (defined(ECB) && ECB == 1) 463 | 464 | /*****************************************************************************/ 465 | /* Public functions: */ 466 | /*****************************************************************************/ 467 | #if defined(ECB) && (ECB == 1) 468 | 469 | 470 | void AES_ECB_encrypt(const struct AES_ctx* ctx, uint8_t* buf) 471 | { 472 | // The next function call encrypts the PlainText with the Key using AES algorithm. 473 | Cipher((state_t*)buf, ctx->RoundKey); 474 | } 475 | 476 | void AES_ECB_decrypt(const struct AES_ctx* ctx, uint8_t* buf) 477 | { 478 | // The next function call decrypts the PlainText with the Key using AES algorithm. 479 | InvCipher((state_t*)buf, ctx->RoundKey); 480 | } 481 | 482 | 483 | #endif // #if defined(ECB) && (ECB == 1) 484 | 485 | 486 | 487 | 488 | 489 | #if defined(CBC) && (CBC == 1) 490 | 491 | 492 | static void XorWithIv(uint8_t* buf, const uint8_t* Iv) 493 | { 494 | uint8_t i; 495 | for (i = 0; i < AES_BLOCKLEN; ++i) // The block in AES is always 128bit no matter the key size 496 | { 497 | buf[i] ^= Iv[i]; 498 | } 499 | } 500 | 501 | void AES_CBC_encrypt_buffer(struct AES_ctx *ctx, uint8_t* buf, size_t length) 502 | { 503 | size_t i; 504 | uint8_t *Iv = ctx->Iv; 505 | for (i = 0; i < length; i += AES_BLOCKLEN) 506 | { 507 | XorWithIv(buf, Iv); 508 | Cipher((state_t*)buf, ctx->RoundKey); 509 | Iv = buf; 510 | buf += AES_BLOCKLEN; 511 | } 512 | /* store Iv in ctx for next call */ 513 | memcpy(ctx->Iv, Iv, AES_BLOCKLEN); 514 | } 515 | 516 | void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length) 517 | { 518 | size_t i; 519 | uint8_t storeNextIv[AES_BLOCKLEN]; 520 | for (i = 0; i < length; i += AES_BLOCKLEN) 521 | { 522 | memcpy(storeNextIv, buf, AES_BLOCKLEN); 523 | InvCipher((state_t*)buf, ctx->RoundKey); 524 | XorWithIv(buf, ctx->Iv); 525 | memcpy(ctx->Iv, storeNextIv, AES_BLOCKLEN); 526 | buf += AES_BLOCKLEN; 527 | } 528 | 529 | } 530 | 531 | #endif // #if defined(CBC) && (CBC == 1) 532 | 533 | 534 | 535 | #if defined(CTR) && (CTR == 1) 536 | 537 | /* Symmetrical operation: same function for encrypting as for decrypting. Note any IV/nonce should never be reused with the same key */ 538 | void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length) 539 | { 540 | uint8_t buffer[AES_BLOCKLEN]; 541 | 542 | size_t i; 543 | int bi; 544 | for (i = 0, bi = AES_BLOCKLEN; i < length; ++i, ++bi) 545 | { 546 | if (bi == AES_BLOCKLEN) /* we need to regen xor compliment in buffer */ 547 | { 548 | 549 | memcpy(buffer, ctx->Iv, AES_BLOCKLEN); 550 | Cipher((state_t*)buffer,ctx->RoundKey); 551 | 552 | /* Increment Iv and handle overflow */ 553 | for (bi = (AES_BLOCKLEN - 1); bi >= 0; --bi) 554 | { 555 | /* inc will overflow */ 556 | if (ctx->Iv[bi] == 255) 557 | { 558 | ctx->Iv[bi] = 0; 559 | continue; 560 | } 561 | ctx->Iv[bi] += 1; 562 | break; 563 | } 564 | bi = 0; 565 | } 566 | 567 | buf[i] = (buf[i] ^ buffer[bi]); 568 | } 569 | } 570 | 571 | #endif // #if defined(CTR) && (CTR == 1) 572 | 573 | -------------------------------------------------------------------------------- /aes.h: -------------------------------------------------------------------------------- 1 | #ifndef _AES_H_ 2 | #define _AES_H_ 3 | 4 | #include 5 | #include 6 | 7 | // #define the macros below to 1/0 to enable/disable the mode of operation. 8 | // 9 | // CBC enables AES encryption in CBC-mode of operation. 10 | // CTR enables encryption in counter-mode. 11 | // ECB enables the basic ECB 16-byte block algorithm. All can be enabled simultaneously. 12 | 13 | // The #ifndef-guard allows it to be configured before #include'ing or at compile time. 14 | #ifndef CBC 15 | #define CBC 1 16 | #endif 17 | 18 | #ifndef ECB 19 | #define ECB 1 20 | #endif 21 | 22 | #ifndef CTR 23 | #define CTR 1 24 | #endif 25 | 26 | 27 | #define AES128 1 28 | //#define AES192 1 29 | //#define AES256 1 30 | 31 | #define AES_BLOCKLEN 16 // Block length in bytes - AES is 128b block only 32 | 33 | #if defined(AES256) && (AES256 == 1) 34 | #define AES_KEYLEN 32 35 | #define AES_keyExpSize 240 36 | #elif defined(AES192) && (AES192 == 1) 37 | #define AES_KEYLEN 24 38 | #define AES_keyExpSize 208 39 | #else 40 | #define AES_KEYLEN 16 // Key length in bytes 41 | #define AES_keyExpSize 176 42 | #endif 43 | 44 | struct AES_ctx 45 | { 46 | uint8_t RoundKey[AES_keyExpSize]; 47 | #if (defined(CBC) && (CBC == 1)) || (defined(CTR) && (CTR == 1)) 48 | uint8_t Iv[AES_BLOCKLEN]; 49 | #endif 50 | }; 51 | 52 | void AES_init_ctx(struct AES_ctx* ctx, const uint8_t* key); 53 | #if (defined(CBC) && (CBC == 1)) || (defined(CTR) && (CTR == 1)) 54 | void AES_init_ctx_iv(struct AES_ctx* ctx, const uint8_t* key, const uint8_t* iv); 55 | void AES_ctx_set_iv(struct AES_ctx* ctx, const uint8_t* iv); 56 | #endif 57 | 58 | #if defined(ECB) && (ECB == 1) 59 | // buffer size is exactly AES_BLOCKLEN bytes; 60 | // you need only AES_init_ctx as IV is not used in ECB 61 | // NB: ECB is considered insecure for most uses 62 | void AES_ECB_encrypt(const struct AES_ctx* ctx, uint8_t* buf); 63 | void AES_ECB_decrypt(const struct AES_ctx* ctx, uint8_t* buf); 64 | 65 | #endif // #if defined(ECB) && (ECB == !) 66 | 67 | 68 | #if defined(CBC) && (CBC == 1) 69 | // buffer size MUST be mutile of AES_BLOCKLEN; 70 | // Suggest https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7 for padding scheme 71 | // NOTES: you need to set IV in ctx via AES_init_ctx_iv() or AES_ctx_set_iv() 72 | // no IV should ever be reused with the same key 73 | void AES_CBC_encrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length); 74 | void AES_CBC_decrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length); 75 | 76 | #endif // #if defined(CBC) && (CBC == 1) 77 | 78 | 79 | #if defined(CTR) && (CTR == 1) 80 | 81 | // Same function for encrypting as for decrypting. 82 | // IV is incremented for every block, and used after encryption as XOR-compliment for output 83 | // Suggesting https://en.wikipedia.org/wiki/Padding_(cryptography)#PKCS7 for padding scheme 84 | // NOTES: you need to set IV in ctx with AES_init_ctx_iv() or AES_ctx_set_iv() 85 | // no IV should ever be reused with the same key 86 | void AES_CTR_xcrypt_buffer(struct AES_ctx* ctx, uint8_t* buf, size_t length); 87 | 88 | #endif // #if defined(CTR) && (CTR == 1) 89 | 90 | 91 | #endif // _AES_H_ 92 | -------------------------------------------------------------------------------- /lzma2/atomic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018 Conor McCarthy 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under both the BSD-style license (found in the 6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found 7 | * in the COPYING file in the root directory of this source tree). 8 | * 9 | */ 10 | 11 | #ifndef FL2_ATOMIC_H 12 | #define FL2_ATOMIC_H 13 | 14 | #if defined (__cplusplus) 15 | extern "C" { 16 | #endif 17 | 18 | /* atomic add */ 19 | 20 | #if !defined(FL2_SINGLETHREAD) && defined(_WIN32) 21 | 22 | #ifdef WINVER 23 | #undef WINVER 24 | #endif 25 | #define WINVER 0x0600 26 | 27 | #ifdef _WIN32_WINNT 28 | #undef _WIN32_WINNT 29 | #endif 30 | #define _WIN32_WINNT 0x0600 31 | 32 | #ifndef WIN32_LEAN_AND_MEAN 33 | #define WIN32_LEAN_AND_MEAN 34 | #endif 35 | 36 | #include 37 | 38 | 39 | typedef LONG volatile FL2_atomic; 40 | #define ATOMIC_INITIAL_VALUE -1 41 | #define FL2_atomic_increment(n) InterlockedIncrement(&n) 42 | #define FL2_atomic_add(n, a) InterlockedAdd(&n, a) 43 | #define FL2_nonAtomic_increment(n) (++n) 44 | 45 | #elif !defined(FL2_SINGLETHREAD) && defined(__GNUC__) 46 | 47 | typedef long FL2_atomic; 48 | #define ATOMIC_INITIAL_VALUE 0 49 | #define FL2_atomic_increment(n) __sync_fetch_and_add(&n, 1) 50 | #define FL2_atomic_add(n, a) __sync_fetch_and_add(&n, a) 51 | #define FL2_nonAtomic_increment(n) (n++) 52 | 53 | #elif !defined(FL2_SINGLETHREAD) && defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && !defined(__STDC_NO_ATOMICS__) /* C11 */ 54 | 55 | #include 56 | 57 | typedef _Atomic long FL2_atomic; 58 | #define ATOMIC_INITIAL_VALUE 0 59 | #define FL2_atomic_increment(n) atomic_fetch_add(&n, 1) 60 | #define FL2_atomic_add(n, a) atomic_fetch_add(&n, a) 61 | #define FL2_nonAtomic_increment(n) (n++) 62 | 63 | #else /* No atomics */ 64 | 65 | # ifndef FL2_SINGLETHREAD 66 | # error No atomic operations available. Change compiler config or define FL2_SINGLETHREAD for the entire build. 67 | # endif 68 | 69 | typedef long FL2_atomic; 70 | #define ATOMIC_INITIAL_VALUE 0 71 | #define FL2_atomic_increment(n) (n++) 72 | #define FL2_atomic_add(n, a) (n += (a)) 73 | #define FL2_nonAtomic_increment(n) (n++) 74 | 75 | #endif /* FL2_SINGLETHREAD */ 76 | 77 | 78 | #if defined (__cplusplus) 79 | } 80 | #endif 81 | 82 | #endif /* FL2_ATOMIC_H */ 83 | -------------------------------------------------------------------------------- /lzma2/compiler.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. 3 | * All rights reserved. 4 | * Modified for FL2 by Conor McCarthy 5 | * 6 | * This source code is licensed under both the BSD-style license (found in the 7 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found 8 | * in the COPYING file in the root directory of this source tree). 9 | * You may select, at your option, one of the above-listed licenses. 10 | */ 11 | 12 | #ifndef FL2_COMPILER_H 13 | #define FL2_COMPILER_H 14 | 15 | /*-******************************************************* 16 | * Compiler specifics 17 | *********************************************************/ 18 | /* force inlining */ 19 | 20 | #if !defined(FL2_NO_INLINE) 21 | #if defined (__GNUC__) || defined(__cplusplus) || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */ 22 | # define INLINE_KEYWORD inline 23 | #else 24 | # define INLINE_KEYWORD 25 | #endif 26 | 27 | #if defined(__GNUC__) 28 | # define FORCE_INLINE_ATTR __attribute__((always_inline)) 29 | #elif defined(_MSC_VER) 30 | # define FORCE_INLINE_ATTR __forceinline 31 | #else 32 | # define FORCE_INLINE_ATTR 33 | #endif 34 | 35 | #else 36 | 37 | #define INLINE_KEYWORD 38 | #define FORCE_INLINE_ATTR 39 | 40 | #endif 41 | 42 | /** 43 | * FORCE_INLINE_TEMPLATE is used to define C "templates", which take constant 44 | * parameters. They must be inlined for the compiler to eliminate the constant 45 | * branches. 46 | */ 47 | #define FORCE_INLINE_TEMPLATE static INLINE_KEYWORD FORCE_INLINE_ATTR 48 | /** 49 | * HINT_INLINE is used to help the compiler generate better code. It is *not* 50 | * used for "templates", so it can be tweaked based on the compilers 51 | * performance. 52 | * 53 | * gcc-4.8 and gcc-4.9 have been shown to benefit from leaving off the 54 | * always_inline attribute. 55 | * 56 | * clang up to 5.0.0 (trunk) benefit tremendously from the always_inline 57 | * attribute. 58 | */ 59 | #if !defined(__clang__) && defined(__GNUC__) && __GNUC__ >= 4 && __GNUC_MINOR__ >= 8 && __GNUC__ < 5 60 | # define HINT_INLINE static INLINE_KEYWORD 61 | #else 62 | # define HINT_INLINE static INLINE_KEYWORD FORCE_INLINE_ATTR 63 | #endif 64 | 65 | /* force no inlining */ 66 | #ifdef _MSC_VER 67 | # define FORCE_NOINLINE __declspec(noinline) 68 | #else 69 | # ifdef __GNUC__ 70 | # define FORCE_NOINLINE __attribute__((__noinline__)) 71 | # else 72 | # define FORCE_NOINLINE 73 | # endif 74 | #endif 75 | 76 | /* target attribute */ 77 | #ifndef __has_attribute 78 | #define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */ 79 | #endif 80 | #if defined(__GNUC__) 81 | # define TARGET_ATTRIBUTE(target) __attribute__((__target__(target))) 82 | #else 83 | # define TARGET_ATTRIBUTE(target) 84 | #endif 85 | 86 | /* Enable runtime BMI2 dispatch based on the CPU. 87 | * Enabled for clang & gcc >=4.8 on x86 when BMI2 isn't enabled by default. 88 | */ 89 | #ifndef DYNAMIC_BMI2 90 | #if ((defined(__clang__) && __has_attribute(__target__)) \ 91 | || (defined(__GNUC__) \ 92 | && (__GNUC__ >= 5 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8)))) \ 93 | && (defined(__x86_64__) || defined(_M_X86)) \ 94 | && !defined(__BMI2__) 95 | # define DYNAMIC_BMI2 1 96 | #else 97 | # define DYNAMIC_BMI2 0 98 | #endif 99 | #endif 100 | 101 | /* prefetch 102 | * can be disabled, by declaring NO_PREFETCH build macro */ 103 | #if defined(NO_PREFETCH) 104 | # define PREFETCH_L1(ptr) (void)(ptr) /* disabled */ 105 | # define PREFETCH_L2(ptr) (void)(ptr) /* disabled */ 106 | #else 107 | # if defined(_MSC_VER) && (defined(_M_X64) || defined(_M_I86)) /* _mm_prefetch() is not defined outside of x86/x64 */ 108 | # include /* https://msdn.microsoft.com/fr-fr/library/84szxsww(v=vs.90).aspx */ 109 | # define PREFETCH_L1(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T0) 110 | # define PREFETCH_L2(ptr) _mm_prefetch((const char*)(ptr), _MM_HINT_T1) 111 | # elif defined(__GNUC__) && ( (__GNUC__ >= 4) || ( (__GNUC__ == 3) && (__GNUC_MINOR__ >= 1) ) ) 112 | # define PREFETCH_L1(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 3 /* locality */) 113 | # define PREFETCH_L2(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 2 /* locality */) 114 | # else 115 | # define PREFETCH_L1(ptr) (void)(ptr) /* disabled */ 116 | # define PREFETCH_L2(ptr) (void)(ptr) /* disabled */ 117 | # endif 118 | #endif /* NO_PREFETCH */ 119 | 120 | #define CACHELINE_SIZE 64 121 | 122 | #define PREFETCH_AREA(p, s) { \ 123 | const char* const _ptr = (const char*)(p); \ 124 | size_t const _size = (size_t)(s); \ 125 | size_t _pos; \ 126 | for (_pos=0; _pos<_size; _pos+=CACHELINE_SIZE) { \ 127 | PREFETCH_L2(_ptr + _pos); \ 128 | } \ 129 | } 130 | 131 | /* disable warnings */ 132 | #ifdef _MSC_VER /* Visual Studio */ 133 | # include /* For Visual 2005 */ 134 | # pragma warning(disable : 4100) /* disable: C4100: unreferenced formal parameter */ 135 | # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */ 136 | # pragma warning(disable : 4204) /* disable: C4204: non-constant aggregate initializer */ 137 | # pragma warning(disable : 4214) /* disable: C4214: non-int bitfields */ 138 | # pragma warning(disable : 4324) /* disable: C4324: padded structure */ 139 | #endif 140 | 141 | #endif /* FL2_COMPILER_H */ 142 | -------------------------------------------------------------------------------- /lzma2/count.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under both the BSD-style license (found in the 6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found 7 | * in the COPYING file in the root directory of this source tree). 8 | * You may select, at your option, one of the above-listed licenses. 9 | */ 10 | 11 | #ifndef ZSTD_COUNT_H_ 12 | #define ZSTD_COUNT_H_ 13 | 14 | #include "mem.h" 15 | 16 | #if defined (__cplusplus) 17 | extern "C" { 18 | #endif 19 | 20 | /*-************************************* 21 | * Match length counter 22 | ***************************************/ 23 | static unsigned ZSTD_NbCommonBytes(register size_t val) 24 | { 25 | if (MEM_isLittleEndian()) { 26 | if (MEM_64bits()) { 27 | # if defined(_MSC_VER) && defined(_WIN64) 28 | unsigned long r = 0; 29 | _BitScanForward64(&r, (U64)val); 30 | return (unsigned)(r >> 3); 31 | # elif defined(__GNUC__) && (__GNUC__ >= 4) 32 | return (__builtin_ctzll((U64)val) >> 3); 33 | # else 34 | static const int DeBruijnBytePos[64] = { 0, 0, 0, 0, 0, 1, 1, 2, 35 | 0, 3, 1, 3, 1, 4, 2, 7, 36 | 0, 2, 3, 6, 1, 5, 3, 5, 37 | 1, 3, 4, 4, 2, 5, 6, 7, 38 | 7, 0, 1, 2, 3, 3, 4, 6, 39 | 2, 6, 5, 5, 3, 4, 5, 6, 40 | 7, 1, 2, 4, 6, 4, 4, 5, 41 | 7, 2, 6, 5, 7, 6, 7, 7 }; 42 | return DeBruijnBytePos[((U64)((val & -(long long)val) * 0x0218A392CDABBD3FULL)) >> 58]; 43 | # endif 44 | } 45 | else { /* 32 bits */ 46 | # if defined(_MSC_VER) 47 | unsigned long r = 0; 48 | _BitScanForward(&r, (U32)val); 49 | return (unsigned)(r >> 3); 50 | # elif defined(__GNUC__) && (__GNUC__ >= 3) 51 | return (__builtin_ctz((U32)val) >> 3); 52 | # else 53 | static const int DeBruijnBytePos[32] = { 0, 0, 3, 0, 3, 1, 3, 0, 54 | 3, 2, 2, 1, 3, 2, 0, 1, 55 | 3, 3, 1, 2, 2, 2, 2, 0, 56 | 3, 1, 2, 0, 1, 0, 1, 1 }; 57 | return DeBruijnBytePos[((U32)((val & -(S32)val) * 0x077CB531U)) >> 27]; 58 | # endif 59 | } 60 | } 61 | else { /* Big Endian CPU */ 62 | if (MEM_64bits()) { 63 | # if defined(_MSC_VER) && defined(_WIN64) 64 | unsigned long r = 0; 65 | _BitScanReverse64(&r, val); 66 | return (unsigned)(r >> 3); 67 | # elif defined(__GNUC__) && (__GNUC__ >= 4) 68 | return (__builtin_clzll(val) >> 3); 69 | # else 70 | unsigned r; 71 | const unsigned n32 = sizeof(size_t) * 4; /* calculate this way due to compiler complaining in 32-bits mode */ 72 | if (!(val >> n32)) { r = 4; } 73 | else { r = 0; val >>= n32; } 74 | if (!(val >> 16)) { r += 2; val >>= 8; } 75 | else { val >>= 24; } 76 | r += (!val); 77 | return r; 78 | # endif 79 | } 80 | else { /* 32 bits */ 81 | # if defined(_MSC_VER) 82 | unsigned long r = 0; 83 | _BitScanReverse(&r, (unsigned long)val); 84 | return (unsigned)(r >> 3); 85 | # elif defined(__GNUC__) && (__GNUC__ >= 3) 86 | return (__builtin_clz((U32)val) >> 3); 87 | # else 88 | unsigned r; 89 | if (!(val >> 16)) { r = 2; val >>= 8; } 90 | else { r = 0; val >>= 24; } 91 | r += (!val); 92 | return r; 93 | # endif 94 | } 95 | } 96 | } 97 | 98 | 99 | static size_t ZSTD_count(const BYTE* pIn, const BYTE* pMatch, const BYTE* const pInLimit) 100 | { 101 | const BYTE* const pStart = pIn; 102 | const BYTE* const pInLoopLimit = pInLimit - (sizeof(size_t) - 1); 103 | 104 | if (pIn < pInLoopLimit) { 105 | { size_t const diff = MEM_readST(pMatch) ^ MEM_readST(pIn); 106 | if (diff) return ZSTD_NbCommonBytes(diff); } 107 | pIn += sizeof(size_t); pMatch += sizeof(size_t); 108 | while (pIn < pInLoopLimit) { 109 | size_t const diff = MEM_readST(pMatch) ^ MEM_readST(pIn); 110 | if (!diff) { pIn += sizeof(size_t); pMatch += sizeof(size_t); continue; } 111 | pIn += ZSTD_NbCommonBytes(diff); 112 | return (size_t)(pIn - pStart); 113 | } 114 | } 115 | if (MEM_64bits() && (pIn<(pInLimit - 3)) && (MEM_read32(pMatch) == MEM_read32(pIn))) { pIn += 4; pMatch += 4; } 116 | if ((pIn<(pInLimit - 1)) && (MEM_read16(pMatch) == MEM_read16(pIn))) { pIn += 2; pMatch += 2; } 117 | if ((pIn /* size_t */ 20 | 21 | 22 | /* ===== FL2LIB_API : control library symbols visibility ===== */ 23 | #ifndef FL2LIB_VISIBILITY 24 | # if defined(__GNUC__) && (__GNUC__ >= 4) 25 | # define FL2LIB_VISIBILITY __attribute__ ((visibility ("default"))) 26 | # else 27 | # define FL2LIB_VISIBILITY 28 | # endif 29 | #endif 30 | #if defined(FL2_DLL_EXPORT) && (FL2_DLL_EXPORT==1) 31 | # define FL2LIB_API __declspec(dllexport) FL2LIB_VISIBILITY 32 | #elif defined(FL2_DLL_IMPORT) && (FL2_DLL_IMPORT==1) 33 | # define FL2LIB_API __declspec(dllimport) FL2LIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/ 34 | #else 35 | # define FL2LIB_API FL2LIB_VISIBILITY 36 | #endif 37 | 38 | /* ====== Calling convention ======*/ 39 | 40 | #if !defined _WIN32 || defined __x86_64__s || defined _M_X64 || (defined __SIZEOF_POINTER__ && __SIZEOF_POINTER__ == 8) 41 | # define FL2LIB_CALL 42 | #elif defined(__GNUC__) 43 | # define FL2LIB_CALL __attribute__((cdecl)) 44 | #elif defined(_MSC_VER) 45 | # define FL2LIB_CALL __cdecl 46 | #else 47 | # define FL2LIB_CALL 48 | #endif 49 | 50 | /******************************************************************************************************* 51 | Introduction 52 | 53 | *********************************************************************************************************/ 54 | 55 | /*------ Version ------*/ 56 | #define FL2_VERSION_MAJOR 1 57 | #define FL2_VERSION_MINOR 0 58 | #define FL2_VERSION_RELEASE 1 59 | 60 | #define FL2_VERSION_NUMBER (FL2_VERSION_MAJOR *100*100 + FL2_VERSION_MINOR *100 + FL2_VERSION_RELEASE) 61 | FL2LIB_API unsigned FL2LIB_CALL FL2_versionNumber(void); /**< useful to check dll version */ 62 | 63 | #define FL2_LIB_VERSION FL2_VERSION_MAJOR.FL2_VERSION_MINOR.FL2_VERSION_RELEASE 64 | #define FL2_QUOTE(str) #str 65 | #define FL2_EXPAND_AND_QUOTE(str) FL2_QUOTE(str) 66 | #define FL2_VERSION_STRING FL2_EXPAND_AND_QUOTE(FL2_LIB_VERSION) 67 | FL2LIB_API const char* FL2LIB_CALL FL2_versionString(void); 68 | 69 | 70 | #define FL2_MAXTHREADS 200 71 | 72 | 73 | /*************************************** 74 | * Simple API 75 | ***************************************/ 76 | 77 | /*! FL2_compress() : 78 | * Compresses `src` content as a single LZMA2 compressed stream into already allocated `dst`. 79 | * Call FL2_compressMt() to use > 1 thread. Specify nbThreads = 0 to use all cores. 80 | * @return : compressed size written into `dst` (<= `dstCapacity), 81 | * or an error code if it fails (which can be tested using FL2_isError()). */ 82 | FL2LIB_API size_t FL2LIB_CALL FL2_compress(void* dst, size_t dstCapacity, 83 | const void* src, size_t srcSize, 84 | int compressionLevel); 85 | 86 | FL2LIB_API size_t FL2LIB_CALL FL2_compressMt(void* dst, size_t dstCapacity, 87 | const void* src, size_t srcSize, 88 | int compressionLevel, 89 | unsigned nbThreads); 90 | 91 | /*! FL2_decompress() : 92 | * Decompresses a single LZMA2 compressed stream from `src` into already allocated `dst`. 93 | * `compressedSize` : must be at least the size of the LZMA2 stream. 94 | * `dstCapacity` is the original, uncompressed size to regenerate, returned by calling 95 | * FL2_findDecompressedSize(). 96 | * Call FL2_decompressMt() to use > 1 thread. Specify nbThreads = 0 to use all cores. The stream 97 | * must contain dictionary resets to use multiple threads. These are inserted during compression by 98 | * default. The frequency can be changed/disabled with the FL2_p_resetInterval parameter setting. 99 | * @return : the number of bytes decompressed into `dst` (<= `dstCapacity`), 100 | * or an errorCode if it fails (which can be tested using FL2_isError()). */ 101 | FL2LIB_API size_t FL2LIB_CALL FL2_decompress(void* dst, size_t dstCapacity, 102 | const void* src, size_t compressedSize); 103 | 104 | FL2LIB_API size_t FL2LIB_CALL FL2_decompressMt(void* dst, size_t dstCapacity, 105 | const void* src, size_t compressedSize, 106 | unsigned nbThreads); 107 | 108 | /*! FL2_findDecompressedSize() 109 | * `src` should point to the start of a LZMA2 encoded stream. 110 | * `srcSize` must be at least as large as the LZMA2 stream including end marker. 111 | * A property byte is assumed to exist at position 0 in `src`. If the stream was created without one, 112 | * subtract 1 byte from `src` when passing it to the function. 113 | * @return : - decompressed size of the stream in `src`, if known 114 | * - FL2_CONTENTSIZE_ERROR if an error occurred (e.g. corruption, srcSize too small) 115 | * note 1 : a 0 return value means the stream is valid but "empty". 116 | * note 2 : decompressed size can be very large (64-bits value), 117 | * potentially larger than what local system can handle as a single memory segment. 118 | * In which case, it's necessary to use streaming mode to decompress data. 119 | * note 5 : If source is untrusted, decompressed size could be wrong or intentionally modified. 120 | * Always ensure return value fits within application's authorized limits. 121 | * Each application can set its own limits. */ 122 | #define FL2_CONTENTSIZE_ERROR (size_t)-1 123 | FL2LIB_API unsigned long long FL2LIB_CALL FL2_findDecompressedSize(const void *src, size_t srcSize); 124 | 125 | 126 | /*====== Helper functions ======*/ 127 | FL2LIB_API size_t FL2LIB_CALL FL2_compressBound(size_t srcSize); /*!< maximum compressed size in worst case scenario */ 128 | FL2LIB_API unsigned FL2LIB_CALL FL2_isError(size_t code); /*!< tells if a `size_t` function result is an error code */ 129 | FL2LIB_API unsigned FL2LIB_CALL FL2_isTimedOut(size_t code); /*!< tells if a `size_t` function result is the timeout code */ 130 | FL2LIB_API const char* FL2LIB_CALL FL2_getErrorName(size_t code); /*!< provides readable string from an error code */ 131 | FL2LIB_API int FL2LIB_CALL FL2_maxCLevel(void); /*!< maximum compression level available */ 132 | FL2LIB_API int FL2LIB_CALL FL2_maxHighCLevel(void); /*!< maximum compression level available in high mode */ 133 | 134 | 135 | /*************************************** 136 | * Explicit memory management 137 | ***************************************/ 138 | 139 | /*= Compression context 140 | * When compressing many times, it is recommended to allocate a context just once, 141 | * and re-use it for each successive compression operation. This will make workload 142 | * friendlier for system's memory. The context may not use the number of threads requested 143 | * if the library is compiled for single-threaded compression or nbThreads > FL2_MAXTHREADS. 144 | * Call FL2_getCCtxThreadCount to obtain the actual number allocated. */ 145 | typedef struct FL2_CCtx_s FL2_CCtx; 146 | FL2LIB_API FL2_CCtx* FL2LIB_CALL FL2_createCCtx(void); 147 | FL2LIB_API FL2_CCtx* FL2LIB_CALL FL2_createCCtxMt(unsigned nbThreads); 148 | FL2LIB_API void FL2LIB_CALL FL2_freeCCtx(FL2_CCtx* cctx); 149 | 150 | FL2LIB_API unsigned FL2LIB_CALL FL2_getCCtxThreadCount(const FL2_CCtx* cctx); 151 | 152 | /*! FL2_compressCCtx() : 153 | * Same as FL2_compress(), but requires an allocated FL2_CCtx (see FL2_createCCtx()). */ 154 | FL2LIB_API size_t FL2LIB_CALL FL2_compressCCtx(FL2_CCtx* cctx, 155 | void* dst, size_t dstCapacity, 156 | const void* src, size_t srcSize, 157 | int compressionLevel); 158 | 159 | /*! FL2_getCCtxDictProp() : 160 | * Get the dictionary size property. 161 | * Intended for use with the FL2_p_omitProperties parameter for creating a 162 | * 7-zip or XZ compatible LZMA2 stream. */ 163 | FL2LIB_API unsigned char FL2LIB_CALL FL2_getCCtxDictProp(FL2_CCtx* cctx); 164 | 165 | 166 | /**************************** 167 | * Decompression 168 | ****************************/ 169 | 170 | /*= Decompression context 171 | * When decompressing many times, it is recommended to allocate a context only once, 172 | * and re-use it for each successive decompression operation. This will make the workload 173 | * friendlier for the system's memory. 174 | * The context may not allocate the number of threads requested if the library is 175 | * compiled for single-threaded compression or nbThreads > FL2_MAXTHREADS. 176 | * Call FL2_getDCtxThreadCount to obtain the actual number allocated. 177 | * At least nbThreads dictionary resets must exist in the stream to use all of the 178 | * threads. Dictionary resets are inserted into the stream according to the 179 | * FL2_p_resetInterval parameter used in the compression context. */ 180 | typedef struct FL2_DCtx_s FL2_DCtx; 181 | FL2LIB_API FL2_DCtx* FL2LIB_CALL FL2_createDCtx(void); 182 | FL2LIB_API FL2_DCtx* FL2LIB_CALL FL2_createDCtxMt(unsigned nbThreads); 183 | FL2LIB_API size_t FL2LIB_CALL FL2_freeDCtx(FL2_DCtx* dctx); 184 | 185 | FL2LIB_API unsigned FL2LIB_CALL FL2_getDCtxThreadCount(const FL2_DCtx* dctx); 186 | 187 | 188 | /*! FL2_initDCtx() : 189 | * Use only when a property byte is not present at input byte 0. No init is necessary otherwise. 190 | * The caller must store the result from FL2_getCCtxDictProp() and pass it to this function. */ 191 | FL2LIB_API size_t FL2LIB_CALL FL2_initDCtx(FL2_DCtx* dctx, unsigned char prop); 192 | 193 | /*! FL2_decompressDCtx() : 194 | * Same as FL2_decompress(), requires an allocated FL2_DCtx (see FL2_createDCtx()) */ 195 | FL2LIB_API size_t FL2LIB_CALL FL2_decompressDCtx(FL2_DCtx* cctx, 196 | void* dst, size_t dstCapacity, 197 | const void* src, size_t srcSize); 198 | 199 | /**************************** 200 | * Streaming 201 | ****************************/ 202 | 203 | typedef struct { 204 | const void* src; /**< start of input buffer */ 205 | size_t size; /**< size of input buffer */ 206 | size_t pos; /**< position where reading stopped. Will be updated. Necessarily 0 <= pos <= size */ 207 | } FL2_inBuffer; 208 | 209 | typedef struct { 210 | void* dst; /**< start of output buffer */ 211 | size_t size; /**< size of output buffer */ 212 | size_t pos; /**< position where writing stopped. Will be updated. Necessarily 0 <= pos <= size */ 213 | } FL2_outBuffer; 214 | 215 | /*** Push/pull structs ***/ 216 | 217 | typedef struct { 218 | void* dst; /**< start of available dict buffer */ 219 | unsigned long size; /**< size of dict remaining */ 220 | } FL2_dictBuffer; 221 | 222 | typedef struct { 223 | const void* src; /**< start of compressed data */ 224 | size_t size; /**< size of compressed data */ 225 | } FL2_cBuffer; 226 | 227 | /*-*********************************************************************** 228 | * Streaming compression 229 | * 230 | * A FL2_CStream object is required to track streaming operation. 231 | * Use FL2_createCStream() and FL2_freeCStream() to create/release resources. 232 | * FL2_CStream objects can be reused multiple times on consecutive compression operations. 233 | * It is recommended to re-use FL2_CStream in situations where many streaming operations will be done 234 | * consecutively, since it will reduce allocation and initialization time. 235 | * 236 | * Call FL2_createCStreamMt() with a nonzero dualBuffer parameter to use two input dictionary buffers. 237 | * The stream will not block on FL2_compressStream() and continues to accept data while compression is 238 | * underway, until both buffers are full. Useful when I/O is slow. 239 | * To compress with a single thread with dual buffering, call FL2_createCStreamMt with nbThreads=1. 240 | * 241 | * Use FL2_initCStream() on the FL2_CStream object to start a new compression operation. 242 | * 243 | * Use FL2_compressStream() repetitively to consume input stream. 244 | * The function will automatically update the `pos` field. 245 | * It will always consume the entire input unless an error occurs or the dictionary buffer is filled, 246 | * unlike the decompression function. 247 | * 248 | * The radix match finder allows compressed data to be stored in its match table during encoding. 249 | * Applications may call streaming compression functions with output == NULL. In this case, 250 | * when the function returns 1, the compressed data must be read from the internal buffers. 251 | * Call FL2_getNextCompressedBuffer() repeatedly until it returns 0. 252 | * Each call returns buffer information in the FL2_inBuffer parameter. Applications typically will 253 | * passed this to an I/O write function or downstream filter. 254 | * Alternately, applications may pass an FL2_outBuffer object pointer to receive the output. In this 255 | * case the return value is 1 if the buffer is full and more compressed data remains. 256 | * 257 | * FL2_endStream() instructs to finish a stream. It will perform a flush and write the LZMA2 258 | * termination byte (required). Call FL2_endStream() repeatedly until it returns 0. 259 | * 260 | * Most functions may return a size_t error code, which can be tested using FL2_isError(). 261 | * 262 | * *******************************************************************/ 263 | 264 | typedef struct FL2_CCtx_s FL2_CStream; 265 | 266 | /*===== FL2_CStream management functions =====*/ 267 | FL2LIB_API FL2_CStream* FL2LIB_CALL FL2_createCStream(void); 268 | FL2LIB_API FL2_CStream* FL2LIB_CALL FL2_createCStreamMt(unsigned nbThreads, int dualBuffer); 269 | FL2LIB_API void FL2LIB_CALL FL2_freeCStream(FL2_CStream * fcs); 270 | 271 | /*===== Streaming compression functions =====*/ 272 | 273 | /*! FL2_initCStream() : 274 | * Call this function before beginning a new compressed data stream. To keep the stream object's 275 | * current parameters, specify zero for the compression level. The object is set to the default 276 | * level upon creation. */ 277 | FL2LIB_API size_t FL2LIB_CALL FL2_initCStream(FL2_CStream* fcs, int compressionLevel); 278 | 279 | /*! FL2_setCStreamTimeout() : 280 | * Sets a timeout in milliseconds. Zero disables the timeout (default). If a nonzero timout is set, functions 281 | * FL2_compressStream(), FL2_getDictionaryBuffer(), FL2_updateDictionary(), FL2_getNextCompressedBuffer(), 282 | * FL2_flushStream(), and FL2_endStream() may return a timeout code before compression of the current 283 | * dictionary of data completes. FL2_isError() returns true for the timeout code, so check the code with 284 | * FL2_isTimedOut() before testing for errors. With the exception of FL2_updateDictionary(), the above 285 | * functions may be called again to wait for completion. A typical application for timeouts is to update the 286 | * user on compression progress. */ 287 | FL2LIB_API size_t FL2LIB_CALL FL2_setCStreamTimeout(FL2_CStream * fcs, unsigned timeout); 288 | 289 | /*! FL2_compressStream() : 290 | * Reads data from input into the dictionary buffer. Compression will begin if the buffer fills up. 291 | * A dual buffering stream will fill the second buffer while compression proceeds on the first. 292 | * A call to FL2_compressStream() will wait for ongoing compression to complete if all dictionary space 293 | * is filled. FL2_compressStream() must not be called with output == NULL unless the caller has read all 294 | * compressed data from the CStream object. 295 | * Returns 1 to indicate compressed data must be read (or output is full), or 0 otherwise. */ 296 | FL2LIB_API size_t FL2LIB_CALL FL2_compressStream(FL2_CStream* fcs, FL2_outBuffer *output, FL2_inBuffer* input); 297 | 298 | /*! FL2_copyCStreamOutput() : 299 | * Copies compressed data to the output buffer until the buffer is full or all available data is copied. 300 | * If asynchronous compression is in progress, the function returns 0 without waiting. 301 | * Returns 1 to indicate some compressed data remains, or 0 otherwise. */ 302 | FL2LIB_API size_t FL2LIB_CALL FL2_copyCStreamOutput(FL2_CStream* fcs, FL2_outBuffer *output); 303 | 304 | /*** Push/pull functions ***/ 305 | 306 | /*! FL2_getDictionaryBuffer() : 307 | * Returns a buffer in the FL2_outBuffer object, which the caller can directly read data into. 308 | * Applications will normally pass this buffer to an I/O read function or upstream filter. 309 | * Returns 0, or an error or timeout code. */ 310 | FL2LIB_API size_t FL2LIB_CALL FL2_getDictionaryBuffer(FL2_CStream* fcs, FL2_dictBuffer* dict); 311 | 312 | /*! FL2_updateDictionary() : 313 | * Informs the CStream how much data was added to the buffer. Compression begins if the dictionary 314 | * was filled. Returns 1 to indicate compressed data must be read, 0 if not, or an error code. */ 315 | FL2LIB_API size_t FL2LIB_CALL FL2_updateDictionary(FL2_CStream* fcs, size_t addedSize); 316 | 317 | /*! FL2_getNextCompressedBuffer() : 318 | * Returns a buffer containing a slice of the compressed data. Call this function and process the data 319 | * until the function returns zero. In most cases it will return a buffer for each compression thread 320 | * used. It is sometimes less but never more than nbThreads. If asynchronous compression is in progress, 321 | * this function will wait for completion before returning, or it will return the timeout code. */ 322 | FL2LIB_API size_t FL2LIB_CALL FL2_getNextCompressedBuffer(FL2_CStream* fcs, FL2_cBuffer* cbuf); 323 | 324 | /******/ 325 | 326 | /*! FL2_getCStreamProgress() : 327 | * Returns the number of bytes processed since the stream was initialized. This is a synthetic 328 | * estimate because the match finder does not proceed sequentially through the data. If 329 | * outputSize is not NULL, returns the number of bytes of compressed data generated. */ 330 | FL2LIB_API unsigned long long FL2LIB_CALL FL2_getCStreamProgress(const FL2_CStream * fcs, unsigned long long *outputSize); 331 | 332 | /*! FL2_waitCStream() : 333 | * Waits for compression to end. This function returns after the timeout set using 334 | * FL2_setCStreamTimeout has elapsed. Unnecessary when no timeout is set. 335 | * Returns 1 if compressed output is available, 0 if not, or the timeout code. */ 336 | FL2LIB_API size_t FL2LIB_CALL FL2_waitCStream(FL2_CStream * fcs); 337 | 338 | /*! FL2_cancelCStream() : 339 | * Cancels any compression operation underway. Useful only when dual buffering and/or timeouts 340 | * are enabled. The stream will be returned to an uninitialized state. */ 341 | FL2LIB_API void FL2LIB_CALL FL2_cancelCStream(FL2_CStream *fcs); 342 | 343 | /*! FL2_remainingOutputSize() : 344 | * The amount of compressed data remaining to be read from the CStream object. */ 345 | FL2LIB_API size_t FL2LIB_CALL FL2_remainingOutputSize(const FL2_CStream* fcs); 346 | 347 | /*! FL2_flushStream() : 348 | * Compress all data remaining in the dictionary buffer(s). It may be necessary to call 349 | * FL2_flushStream() more than once. If output == NULL the compressed data must be read from the 350 | * CStream object after each call. 351 | * Flushing is not normally useful and produces larger output. 352 | * Returns 1 if input or output still exists in the CStream object, 0 if complete, or an error code. */ 353 | FL2LIB_API size_t FL2LIB_CALL FL2_flushStream(FL2_CStream* fcs, FL2_outBuffer *output); 354 | 355 | /*! FL2_endStream() : 356 | * Compress all data remaining in the dictionary buffer(s) and write the stream end marker. It may 357 | * be necessary to call FL2_endStream() more than once. If output == NULL the compressed data must 358 | * be read from the CStream object after each call. 359 | * Returns 0 when compression is complete and all output has been flushed, 1 if not complete, or 360 | * an error code. */ 361 | FL2LIB_API size_t FL2LIB_CALL FL2_endStream(FL2_CStream* fcs, FL2_outBuffer *output); 362 | 363 | /*-*************************************************************************** 364 | * Streaming decompression 365 | * 366 | * A FL2_DStream object is required to track streaming operations. 367 | * Use FL2_createDStream() and FL2_freeDStream() to create/release resources. 368 | * FL2_DStream objects can be re-used multiple times. 369 | * 370 | * Use FL2_initDStream() to start a new decompression operation. 371 | * @return : zero or an error code 372 | * 373 | * Use FL2_decompressStream() repetitively to consume your input. 374 | * The function will update both `pos` fields. 375 | * If `input.pos < input.size`, some input has not been consumed. 376 | * It's up to the caller to present again the remaining data. 377 | * If `output.pos < output.size`, decoder has flushed everything it could. 378 | * @return : 0 when a stream is completely decoded and fully flushed, 379 | * 1, which means there is still some decoding to do to complete the stream, 380 | * or an error code, which can be tested using FL2_isError(). 381 | * *******************************************************************************/ 382 | 383 | typedef struct FL2_DStream_s FL2_DStream; 384 | 385 | /*===== FL2_DStream management functions =====*/ 386 | FL2LIB_API FL2_DStream* FL2LIB_CALL FL2_createDStream(void); 387 | FL2LIB_API FL2_DStream* FL2LIB_CALL FL2_createDStreamMt(unsigned nbThreads); 388 | FL2LIB_API size_t FL2LIB_CALL FL2_freeDStream(FL2_DStream* fds); 389 | 390 | /*! FL2_setDStreamMemoryLimitMt() : 391 | * Set a total size limit for multithreaded decoder input and output buffers. MT decoder memory 392 | * usage is unknown until the input is parsed. If the limit is exceeded, the decoder switches to 393 | * using a single thread. 394 | * MT decoding memory usage is typically dictionary_size * 4 * nbThreads for the output 395 | * buffers plus the size of the compressed input for that amount of output. */ 396 | FL2LIB_API void FL2LIB_CALL FL2_setDStreamMemoryLimitMt(FL2_DStream* fds, size_t limit); 397 | 398 | /*! FL2_setDStreamTimeout() : 399 | * Sets a timeout in milliseconds. Zero disables the timeout. If a nonzero timout is set, 400 | * FL2_decompressStream() may return a timeout code before decompression of the available data 401 | * completes. FL2_isError() returns true for the timeout code, so check the code with FL2_isTimedOut() 402 | * before testing for errors. After a timeout occurs, do not call FL2_decompressStream() again unless 403 | * a call to FL2_waitDStream() returns 1. A typical application for timeouts is to update the user on 404 | * decompression progress. */ 405 | FL2LIB_API size_t FL2LIB_CALL FL2_setDStreamTimeout(FL2_DStream * fds, unsigned timeout); 406 | 407 | /*! FL2_waitDStream() : 408 | * Waits for decompression to end after a timeout has occurred. This function returns after the 409 | * timeout set using FL2_setDStreamTimeout() has elapsed, or when decompression of available input is 410 | * complete. Unnecessary when no timeout is set. 411 | * Returns 0 if the stream is complete, 1 if not complete, or an error code. */ 412 | FL2LIB_API size_t FL2LIB_CALL FL2_waitDStream(FL2_DStream * fds); 413 | 414 | /*! FL2_cancelDStream() : 415 | * Frees memory allocated for MT decoding. If a timeout is set and the caller is waiting 416 | * for completion of MT decoding, decompression in progress will be canceled. */ 417 | FL2LIB_API void FL2LIB_CALL FL2_cancelDStream(FL2_DStream *fds); 418 | 419 | /*! FL2_getDStreamProgress() : 420 | * Returns the number of bytes decoded since the stream was initialized. */ 421 | FL2LIB_API unsigned long long FL2LIB_CALL FL2_getDStreamProgress(const FL2_DStream * fds); 422 | 423 | /*===== Streaming decompression functions =====*/ 424 | 425 | /*! FL2_initDStream() : 426 | * Call this function before decompressing a stream. FL2_initDStream_withProp() 427 | * must be used for streams which do not include a property byte at position zero. 428 | * The caller is responsible for storing and passing the property byte. 429 | * Returns 0 if okay, or an error if the stream object is still in use from a 430 | * previous call to FL2_decompressStream() (see timeout info above). */ 431 | FL2LIB_API size_t FL2LIB_CALL FL2_initDStream(FL2_DStream* fds); 432 | FL2LIB_API size_t FL2LIB_CALL FL2_initDStream_withProp(FL2_DStream* fds, unsigned char prop); 433 | 434 | /*! FL2_decompressStream() : 435 | * Reads data from input and decompresses to output. 436 | * Returns 1 if the stream is unfinished, 0 if the terminator was encountered (he'll be back) 437 | * and all data was written to output, or an error code. Call this function repeatedly if 438 | * necessary, removing data from output and/or loading data into input before each call. */ 439 | FL2LIB_API size_t FL2LIB_CALL FL2_decompressStream(FL2_DStream* fds, FL2_outBuffer* output, FL2_inBuffer* input); 440 | 441 | /*-*************************************************************************** 442 | * Compression parameters 443 | * 444 | * Any function that takes a 'compressionLevel' parameter will replace any 445 | * parameters affected by compression level that are already set. 446 | * To use a preset level and modify it, call FL2_CCtx_setParameter with 447 | * FL2_p_compressionLevel to set the level, then call FL2_CCtx_setParameter again 448 | * with any other settings to change. 449 | * Specify a compressionLevel of 0 when calling a compression function to keep 450 | * the current parameters. 451 | * *******************************************************************************/ 452 | 453 | #define FL2_DICTLOG_MIN 20 454 | #define FL2_DICTLOG_MAX_32 27 455 | #define FL2_DICTLOG_MAX_64 30 456 | #define FL2_DICTLOG_MAX ((unsigned)(sizeof(size_t) == 4 ? FL2_DICTLOG_MAX_32 : FL2_DICTLOG_MAX_64)) 457 | #define FL2_DICTSIZE_MAX (1U << FL2_DICTLOG_MAX) 458 | #define FL2_DICTSIZE_MIN (1U << FL2_DICTLOG_MIN) 459 | #define FL2_BLOCK_OVERLAP_MIN 0 460 | #define FL2_BLOCK_OVERLAP_MAX 14 461 | #define FL2_RESET_INTERVAL_MIN 1 462 | #define FL2_RESET_INTERVAL_MAX 16 /* small enough to fit FL2_DICTSIZE_MAX * FL2_RESET_INTERVAL_MAX in 32-bit size_t */ 463 | #define FL2_BUFFER_RESIZE_MIN 0 464 | #define FL2_BUFFER_RESIZE_MAX 4 465 | #define FL2_BUFFER_RESIZE_DEFAULT 2 466 | #define FL2_CHAINLOG_MIN 4 467 | #define FL2_CHAINLOG_MAX 14 468 | #define FL2_HYBRIDCYCLES_MIN 1 469 | #define FL2_HYBRIDCYCLES_MAX 64 470 | #define FL2_SEARCH_DEPTH_MIN 6 471 | #define FL2_SEARCH_DEPTH_MAX 254 472 | #define FL2_FASTLENGTH_MIN 6 /* only used by optimizer */ 473 | #define FL2_FASTLENGTH_MAX 273 /* only used by optimizer */ 474 | #define FL2_LC_MIN 0 475 | #define FL2_LC_MAX 4 476 | #define FL2_LP_MIN 0 477 | #define FL2_LP_MAX 4 478 | #define FL2_PB_MIN 0 479 | #define FL2_PB_MAX 4 480 | #define FL2_LCLP_MAX 4 481 | 482 | typedef enum { 483 | FL2_fast, 484 | FL2_opt, 485 | FL2_ultra 486 | } FL2_strategy; 487 | 488 | typedef struct { 489 | size_t dictionarySize; /* largest match distance : larger == more compression, more memory needed during decompression; > 64Mb == more memory per byte, slower */ 490 | unsigned overlapFraction; /* overlap between consecutive blocks in 1/16 units: larger == more compression, slower */ 491 | unsigned chainLog; /* HC3 sliding window : larger == more compression, slower; hybrid mode only (ultra) */ 492 | unsigned cyclesLog; /* nb of searches : larger == more compression, slower; hybrid mode only (ultra) */ 493 | unsigned searchDepth; /* maximum depth for resolving string matches : larger == more compression, slower */ 494 | unsigned fastLength; /* acceptable match size for parser : larger == more compression, slower; fast bytes parameter from 7-Zip */ 495 | unsigned divideAndConquer; /* split long chains of 2-byte matches into shorter chains with a small overlap : faster, somewhat less compression; enabled by default */ 496 | FL2_strategy strategy; /* encoder strategy : fast, optimized or ultra (hybrid) */ 497 | } FL2_compressionParameters; 498 | 499 | typedef enum { 500 | /* compression parameters */ 501 | FL2_p_compressionLevel, /* Update all compression parameters according to pre-defined cLevel table 502 | * Default level is FL2_CLEVEL_DEFAULT==6. 503 | * Setting FL2_p_highCompression to 1 switches to an alternate cLevel table. */ 504 | FL2_p_highCompression, /* Maximize compression ratio for a given dictionary size. 505 | * Levels 1..10 = dictionaryLog 20..29 (1 Mb..512 Mb). 506 | * Typically provides a poor speed/ratio tradeoff. */ 507 | FL2_p_dictionaryLog, /* Maximum allowed back-reference distance, expressed as power of 2. 508 | * Must be clamped between FL2_DICTLOG_MIN and FL2_DICTLOG_MAX. 509 | * Default = 24 */ 510 | FL2_p_dictionarySize, /* Same as above but expressed as an absolute value. 511 | * Must be clamped between FL2_DICTSIZE_MIN and FL2_DICTSIZE_MAX. 512 | * Default = 16 Mb */ 513 | FL2_p_overlapFraction, /* The radix match finder is block-based, so some overlap is retained from 514 | * each block to improve compression of the next. This value is expressed 515 | * as n / 16 of the block size (dictionary size). Larger values are slower. 516 | * Values above 2 mostly yield only a small improvement in compression. 517 | * A large value for a small dictionary may worsen multithreaded compression. 518 | * Default = 2 */ 519 | FL2_p_resetInterval, /* For multithreaded decompression. A dictionary reset will occur 520 | * after each dictionarySize * resetInterval bytes of input. 521 | * Default = 4 */ 522 | FL2_p_bufferResize, /* Buffering speeds up the matchfinder. Buffer resize determines the percentage of 523 | * the normal buffer size used, which depends on dictionary size. 524 | * 0=50, 1=75, 2=100, 3=150, 4=200. Higher number = slower, better 525 | * compression, higher memory usage. A CPU with a large memory cache 526 | * may make effective use of a larger buffer. 527 | * Default = 2 */ 528 | FL2_p_hybridChainLog, /* Size of the hybrid mode HC3 hash chain, as a power of 2. 529 | * Resulting table size is (1 << (chainLog+2)) bytes. 530 | * Larger tables result in better and slower compression. 531 | * This parameter is only used by the hybrid "ultra" strategy. 532 | * Default = 9 */ 533 | FL2_p_hybridCycles, /* Number of search attempts made by the HC3 match finder. 534 | * Used only by the hybrid "ultra" strategy. 535 | * More attempts result in slightly better and slower compression. 536 | * Default = 1 */ 537 | FL2_p_searchDepth, /* Match finder will resolve string matches up to this length. If a longer 538 | * match exists further back in the input, it will not be found. 539 | * Default = 42 */ 540 | FL2_p_fastLength, /* Only useful for strategies >= opt. 541 | * Length of match considered "good enough" to stop search. 542 | * Larger values make compression stronger and slower. 543 | * Default = 48 */ 544 | FL2_p_divideAndConquer, /* Split long chains of 2-byte matches into shorter chains with a small overlap 545 | * for further processing. Allows buffering of all chains at length 2. 546 | * Faster, less compression. Generally a good tradeoff. 547 | * Default = enabled */ 548 | FL2_p_strategy, /* 1 = fast; 2 = optimized, 3 = ultra (hybrid mode). 549 | * The higher the value of the selected strategy, the more complex it is, 550 | * resulting in stronger and slower compression. 551 | * Default = ultra */ 552 | FL2_p_literalCtxBits, /* lc value for LZMA2 encoder 553 | * Default = 3 */ 554 | FL2_p_literalPosBits, /* lp value for LZMA2 encoder 555 | * Default = 0 */ 556 | FL2_p_posBits, /* pb value for LZMA2 encoder 557 | * Default = 2 */ 558 | FL2_p_omitProperties, /* Omit the property byte at the start of the stream. For use within 7-zip */ 559 | /* or other containers which store the property byte elsewhere. */ 560 | /* A stream compressed under this setting cannot be decoded by this library. */ 561 | #ifndef NO_XXHASH 562 | FL2_p_doXXHash, /* Calculate a 32-bit xxhash value from the input data and store it 563 | * after the stream terminator. The value will be checked on decompression. 564 | * 0 = do not calculate; 1 = calculate (default) */ 565 | #endif 566 | #ifdef RMF_REFERENCE 567 | FL2_p_useReferenceMF /* Use the reference matchfinder for development purposes. SLOW. */ 568 | #endif 569 | } FL2_cParameter; 570 | 571 | 572 | /*! FL2_CCtx_setParameter() : 573 | * Set one compression parameter, selected by enum FL2_cParameter. 574 | * @result : informational value (typically, the one being set, possibly corrected), 575 | * or an error code (which can be tested with FL2_isError()). */ 576 | FL2LIB_API size_t FL2LIB_CALL FL2_CCtx_setParameter(FL2_CCtx* cctx, FL2_cParameter param, size_t value); 577 | 578 | /*! FL2_CCtx_getParameter() : 579 | * Get one compression parameter, selected by enum FL2_cParameter. 580 | * @result : the parameter value, or the parameter_unsupported error code 581 | * (which can be tested with FL2_isError()). */ 582 | FL2LIB_API size_t FL2LIB_CALL FL2_CCtx_getParameter(FL2_CCtx* cctx, FL2_cParameter param); 583 | 584 | /*! FL2_CStream_setParameter() : 585 | * Set one compression parameter, selected by enum FL2_cParameter. 586 | * @result : informational value (typically, the one being set, possibly corrected), 587 | * or an error code (which can be tested with FL2_isError()). */ 588 | FL2LIB_API size_t FL2LIB_CALL FL2_CStream_setParameter(FL2_CStream* fcs, FL2_cParameter param, size_t value); 589 | 590 | /*! FL2_CStream_getParameter() : 591 | * Get one compression parameter, selected by enum FL2_cParameter. 592 | * @result : the parameter value, or the parameter_unsupported error code 593 | * (which can be tested with FL2_isError()). */ 594 | FL2LIB_API size_t FL2LIB_CALL FL2_CStream_getParameter(FL2_CStream* fcs, FL2_cParameter param); 595 | 596 | /*! FL2_getLevelParameters() : 597 | * Get all compression parameter values defined by the preset compressionLevel. 598 | * @result : the values in a FL2_compressionParameters struct, or the parameter_outOfBound error code 599 | * (which can be tested with FL2_isError()) if compressionLevel is invalid. */ 600 | FL2LIB_API size_t FL2LIB_CALL FL2_getLevelParameters(int compressionLevel, int high, FL2_compressionParameters *params); 601 | 602 | 603 | /*************************************** 604 | * Context memory usage 605 | ***************************************/ 606 | 607 | /*! FL2_estimate*() : 608 | * These functions estimate memory usage of a CCtx before its creation or before any operation has begun. 609 | * FL2_estimateCCtxSize() will provide a budget large enough for any compression level up to selected one. 610 | * To use FL2_estimateCCtxSize_usingCCtx, set the compression level and any other settings for the context, 611 | * then call the function. Some allocation occurs when the context is created, but the large memory buffers 612 | * used for string matching are allocated only when compression is initialized. */ 613 | 614 | FL2LIB_API size_t FL2LIB_CALL FL2_estimateCCtxSize(int compressionLevel, unsigned nbThreads); /*!< memory usage determined by level */ 615 | FL2LIB_API size_t FL2LIB_CALL FL2_estimateCCtxSize_byParams(const FL2_compressionParameters *params, unsigned nbThreads); /*!< memory usage determined by params */ 616 | FL2LIB_API size_t FL2LIB_CALL FL2_estimateCCtxSize_usingCCtx(const FL2_CCtx* cctx); /*!< memory usage determined by settings */ 617 | FL2LIB_API size_t FL2LIB_CALL FL2_estimateCStreamSize(int compressionLevel, unsigned nbThreads, int dualBuffer); /*!< memory usage determined by level */ 618 | FL2LIB_API size_t FL2LIB_CALL FL2_estimateCStreamSize_byParams(const FL2_compressionParameters *params, unsigned nbThreads, int dualBuffer); /*!< memory usage determined by params */ 619 | FL2LIB_API size_t FL2LIB_CALL FL2_estimateCStreamSize_usingCStream(const FL2_CStream* fcs); /*!< memory usage determined by settings */ 620 | 621 | /*! FL2_getDictSizeFromProp() : 622 | * Get the dictionary size from the property byte for a stream. The property byte is the first byte 623 | * in the stream, unless omitProperties was enabled, in which case the caller must store it. */ 624 | FL2LIB_API size_t FL2LIB_CALL FL2_getDictSizeFromProp(unsigned char prop); 625 | 626 | /*! FL2_estimateDCtxSize() : 627 | * The size of a DCtx does not include a dictionary buffer because the caller must supply one. */ 628 | FL2LIB_API size_t FL2LIB_CALL FL2_estimateDCtxSize(unsigned nbThreads); 629 | 630 | /*! FL2_estimateDStreamSize() : 631 | * Estimate decompression memory use from the dictionary size and number of threads. 632 | * For nbThreads == 0 the number of available cores will be used. 633 | * Obtain dictSize by passing the property byte to FL2_getDictSizeFromProp. */ 634 | FL2LIB_API size_t FL2LIB_CALL FL2_estimateDStreamSize(size_t dictSize, unsigned nbThreads); /*!< obtain dictSize from FL2_getDictSizeFromProp() */ 635 | 636 | #endif /* FAST_LZMA2_H */ 637 | 638 | #if defined (__cplusplus) 639 | } 640 | #endif 641 | -------------------------------------------------------------------------------- /lzma2/fast-lzma2.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheAenema/hm-pe-packer/f16942ca4c1397150b7a76941bbd59ae252b7293/lzma2/fast-lzma2.lib -------------------------------------------------------------------------------- /lzma2/fastpos_table.h: -------------------------------------------------------------------------------- 1 | /* This file has been automatically generated by fastpos_tablegen.c. */ 2 | /* Copied from the XZ project */ 3 | 4 | 5 | static const BYTE distance_table[1 << kFastDistBits] = { 6 | 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7 | 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8 | 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9 | 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 10 | 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 11 | 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12 | 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13 | 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 16 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 17 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 18 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 19 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 20 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 21 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 22 | 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 23 | 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 24 | 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 25 | 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 26 | 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 27 | 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 28 | 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 29 | 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 30 | 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 31 | 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 32 | 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 33 | 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 34 | 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 35 | 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 36 | 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 37 | 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, 38 | 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 39 | 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 40 | 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 41 | 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 42 | 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 43 | 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 44 | 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 45 | 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 46 | 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 47 | 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 48 | 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 49 | 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 50 | 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 51 | 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 52 | 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 53 | 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 54 | 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 55 | 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 56 | 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 57 | 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 58 | 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 59 | 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 60 | 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 61 | 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 62 | 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 63 | 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 64 | 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 65 | 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 66 | 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 67 | 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 68 | 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 69 | 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, 70 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 71 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 72 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 73 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 74 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 75 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 76 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 77 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 78 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 79 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 80 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 81 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 82 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 83 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 84 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 85 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 86 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 87 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 88 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 89 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 90 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 91 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 92 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 93 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 94 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 95 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 96 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 97 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 98 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 99 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 100 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 101 | 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 102 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 103 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 104 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 105 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 106 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 107 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 108 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 109 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 110 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 111 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 112 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 113 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 114 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 115 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 116 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 117 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 118 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 119 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 120 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 121 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 122 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 123 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 124 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 125 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 126 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 127 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 128 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 129 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 130 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 131 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 132 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 133 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 134 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 135 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 136 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 137 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 138 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 139 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 140 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 141 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 142 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 143 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 144 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 145 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 146 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 147 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 148 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 149 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 150 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 151 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 152 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 153 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 154 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 155 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 156 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 157 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 158 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 159 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 160 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 161 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 162 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 163 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 164 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 165 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 166 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 167 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 168 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 169 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 170 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 171 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 172 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 173 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 174 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 175 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 176 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 177 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 178 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 179 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 180 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 181 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 182 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 183 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 184 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 185 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 186 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 187 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 188 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 189 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 190 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 191 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 192 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 193 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 194 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 195 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 196 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 197 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 198 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 199 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 200 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 201 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 202 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 203 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 204 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 205 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 206 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 207 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 208 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 209 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 210 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 211 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 212 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 213 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 214 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 215 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 216 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 217 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 218 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 219 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 220 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 221 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 222 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 223 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 224 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 225 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 226 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 227 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 228 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 229 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 230 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 231 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 232 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 233 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 234 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 235 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 236 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 237 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 238 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 239 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 240 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 241 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 242 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 243 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 244 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 245 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 246 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 247 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 248 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 249 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 250 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 251 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 252 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 253 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 254 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 255 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 256 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 257 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 258 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 259 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 260 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 261 | 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23 262 | }; 263 | -------------------------------------------------------------------------------- /lzma2/fl2_compress_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Conor McCarthy 3 | * All rights reserved. 4 | * Parts based on zstd_compress_internal.h copyright Yann Collet 5 | * 6 | * This source code is licensed under both the BSD-style license (found in the 7 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found 8 | * in the COPYING file in the root directory of this source tree). 9 | * You may select, at your option, one of the above-listed licenses. 10 | */ 11 | 12 | #ifndef FL2_COMPRESS_H 13 | #define FL2_COMPRESS_H 14 | 15 | /*-************************************* 16 | * Dependencies 17 | ***************************************/ 18 | #include "mem.h" 19 | #include "data_block.h" 20 | #include "radix_internal.h" 21 | #include "lzma2_enc.h" 22 | #include "fast-lzma2.h" 23 | #include "fl2_threading.h" 24 | #include "fl2_pool.h" 25 | #include "dict_buffer.h" 26 | #ifndef NO_XXHASH 27 | # include "xxhash.h" 28 | #endif 29 | 30 | #if defined (__cplusplus) 31 | extern "C" { 32 | #endif 33 | 34 | /*-************************************* 35 | * Context memory management 36 | ***************************************/ 37 | 38 | typedef struct { 39 | FL2_lzma2Parameters cParams; 40 | RMF_parameters rParams; 41 | unsigned compressionLevel; 42 | BYTE highCompression; 43 | #ifndef NO_XXHASH 44 | BYTE doXXH; 45 | #endif 46 | BYTE omitProp; 47 | } FL2_CCtx_params; 48 | 49 | typedef struct { 50 | FL2_CCtx* cctx; 51 | LZMA2_ECtx* enc; 52 | FL2_dataBlock block; 53 | size_t cSize; 54 | } FL2_job; 55 | 56 | struct FL2_CCtx_s { 57 | DICT_buffer buf; 58 | FL2_CCtx_params params; 59 | #ifndef FL2_SINGLETHREAD 60 | FL2POOL_ctx* factory; 61 | FL2POOL_ctx* compressThread; 62 | #endif 63 | FL2_dataBlock curBlock; 64 | size_t asyncRes; 65 | size_t threadCount; 66 | size_t outThread; 67 | size_t outPos; 68 | size_t dictMax; 69 | U64 streamTotal; 70 | U64 streamCsize; 71 | FL2_matchTable* matchTable; 72 | #ifndef FL2_SINGLETHREAD 73 | U32 timeout; 74 | #endif 75 | U32 rmfWeight; 76 | U32 encWeight; 77 | FL2_atomic progressIn; 78 | FL2_atomic progressOut; 79 | int canceled; 80 | BYTE wroteProp; 81 | BYTE endMarked; 82 | BYTE loopCount; 83 | BYTE lockParams; 84 | unsigned jobCount; 85 | FL2_job jobs[1]; 86 | }; 87 | 88 | #if defined (__cplusplus) 89 | } 90 | #endif 91 | 92 | 93 | #endif /* FL2_COMPRESS_H */ 94 | -------------------------------------------------------------------------------- /lzma2/fl2_errors.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. 3 | * All rights reserved. 4 | * Modified for FL2 by Conor McCarthy 5 | * 6 | * This source code is licensed under both the BSD-style license (found in the 7 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found 8 | * in the COPYING file in the root directory of this source tree). 9 | * You may select, at your option, one of the above-listed licenses. 10 | */ 11 | 12 | #ifndef FL2_ERRORS_H_398273423 13 | #define FL2_ERRORS_H_398273423 14 | 15 | #if defined (__cplusplus) 16 | extern "C" { 17 | #endif 18 | 19 | /*===== dependency =====*/ 20 | #include /* size_t */ 21 | 22 | #include "fast-lzma2.h" 23 | 24 | /*-**************************************** 25 | * error codes list 26 | * note : this API is still considered unstable 27 | * and shall not be used with a dynamic library. 28 | * only static linking is allowed 29 | ******************************************/ 30 | typedef enum { 31 | FL2_error_no_error = 0, 32 | FL2_error_GENERIC = 1, 33 | FL2_error_internal = 2, 34 | FL2_error_corruption_detected = 3, 35 | FL2_error_checksum_wrong = 4, 36 | FL2_error_parameter_unsupported = 5, 37 | FL2_error_parameter_outOfBound = 6, 38 | FL2_error_lclpMax_exceeded = 7, 39 | FL2_error_stage_wrong = 8, 40 | FL2_error_init_missing = 9, 41 | FL2_error_memory_allocation = 10, 42 | FL2_error_dstSize_tooSmall = 11, 43 | FL2_error_srcSize_wrong = 12, 44 | FL2_error_canceled = 13, 45 | FL2_error_buffer = 14, 46 | FL2_error_timedOut = 15, 47 | FL2_error_maxCode = 20 /* never EVER use this value directly, it can change in future versions! Use FL2_isError() instead */ 48 | } FL2_ErrorCode; 49 | 50 | /*! FL2_getErrorCode() : 51 | convert a `size_t` function result into a `FL2_ErrorCode` enum type, 52 | which can be used to compare with enum list published above */ 53 | FL2LIB_API FL2_ErrorCode FL2LIB_CALL FL2_getErrorCode(size_t functionResult); 54 | FL2LIB_API const char* FL2LIB_CALL FL2_getErrorString(FL2_ErrorCode code); /**< Same as FL2_getErrorName, but using a `FL2_ErrorCode` enum argument */ 55 | 56 | 57 | #if defined (__cplusplus) 58 | } 59 | #endif 60 | 61 | #endif /* FL2_ERRORS_H_398273423 */ 62 | -------------------------------------------------------------------------------- /lzma2/fl2_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. 3 | * All rights reserved. 4 | * Modified for FL2 by Conor McCarthy 5 | * 6 | * This source code is licensed under both the BSD-style license (found in the 7 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found 8 | * in the COPYING file in the root directory of this source tree). 9 | * You may select, at your option, one of the above-listed licenses. 10 | */ 11 | 12 | #ifndef FL2_INTERNAL_H_ 13 | #define FL2_INTERNAL_H_ 14 | 15 | 16 | /*-************************************* 17 | * Dependencies 18 | ***************************************/ 19 | #include "mem.h" 20 | #include "compiler.h" 21 | 22 | 23 | #if defined (__cplusplus) 24 | extern "C" { 25 | #endif 26 | 27 | 28 | /*-**************************************** 29 | * Error codes handling 30 | ******************************************/ 31 | #define PREFIX(name) FL2_error_##name 32 | #define FL2_ERROR(name) ((size_t)-PREFIX(name)) 33 | 34 | 35 | /*-************************************* 36 | * Stream properties 37 | ***************************************/ 38 | #define FL2_PROP_HASH_BIT 7 39 | #define FL2_LZMA_PROP_MASK 0x3FU 40 | #ifndef NO_XXHASH 41 | # define XXHASH_SIZEOF sizeof(XXH32_canonical_t) 42 | #endif 43 | 44 | 45 | /*-************************************* 46 | * Debug 47 | ***************************************/ 48 | #if defined(FL2_DEBUG) && (FL2_DEBUG>=1) 49 | # include 50 | #else 51 | # ifndef assert 52 | # define assert(condition) ((void)0) 53 | # endif 54 | #endif 55 | 56 | #define FL2_STATIC_ASSERT(c) { enum { FL2_static_assert = 1/(int)(!!(c)) }; } 57 | 58 | #if defined(FL2_DEBUG) && (FL2_DEBUG>=2) 59 | # include 60 | extern int g_debuglog_enable; 61 | /* recommended values for FL2_DEBUG display levels : 62 | * 1 : no display, enables assert() only 63 | * 2 : reserved for currently active debugging path 64 | * 3 : events once per object lifetime (CCtx, CDict) 65 | * 4 : events once per frame 66 | * 5 : events once per block 67 | * 6 : events once per sequence (*very* verbose) */ 68 | # define RAWLOG(l, ...) { \ 69 | if ((g_debuglog_enable) & (l<=FL2_DEBUG)) { \ 70 | fprintf(stderr, __VA_ARGS__); \ 71 | } } 72 | # define DEBUGLOG(l, ...) { \ 73 | if ((g_debuglog_enable) & (l<=FL2_DEBUG)) { \ 74 | fprintf(stderr, __FILE__ ": "); \ 75 | fprintf(stderr, __VA_ARGS__); \ 76 | fprintf(stderr, " \n"); \ 77 | } } 78 | #else 79 | # define RAWLOG(l, ...) {} /* disabled */ 80 | # define DEBUGLOG(l, ...) {} /* disabled */ 81 | #endif 82 | 83 | 84 | /*-************************************* 85 | * shared macros 86 | ***************************************/ 87 | #undef MIN 88 | #undef MAX 89 | #define MIN(a,b) ((a)<(b) ? (a) : (b)) 90 | #define MAX(a,b) ((a)>(b) ? (a) : (b)) 91 | #define CHECK_F(f) do { size_t const errcod = f; if (FL2_isError(errcod)) return errcod; } while(0) /* check and Forward error code */ 92 | #define CHECK_E(f, e) do { size_t const errcod = f; if (FL2_isError(errcod)) return FL2_ERROR(e); } while(0) /* check and send Error code */ 93 | 94 | MEM_STATIC U32 ZSTD_highbit32(U32 val) 95 | { 96 | assert(val != 0); 97 | { 98 | # if defined(_MSC_VER) /* Visual */ 99 | unsigned long r=0; 100 | _BitScanReverse(&r, val); 101 | return (unsigned)r; 102 | # elif defined(__GNUC__) && (__GNUC__ >= 3) /* GCC Intrinsic */ 103 | return 31 - __builtin_clz(val); 104 | # else /* Software version */ 105 | static const int DeBruijnClz[32] = { 0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30, 8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31 }; 106 | U32 v = val; 107 | int r; 108 | v |= v >> 1; 109 | v |= v >> 2; 110 | v |= v >> 4; 111 | v |= v >> 8; 112 | v |= v >> 16; 113 | r = DeBruijnClz[(U32)(v * 0x07C4ACDDU) >> 27]; 114 | return r; 115 | # endif 116 | } 117 | } 118 | 119 | 120 | #if defined (__cplusplus) 121 | } 122 | #endif 123 | 124 | #endif /* FL2_INTERNAL_H_ */ 125 | -------------------------------------------------------------------------------- /lzma2/fl2_pool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. 3 | * All rights reserved. 4 | * Modified for FL2 by Conor McCarthy 5 | * 6 | * This source code is licensed under both the BSD-style license (found in the 7 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found 8 | * in the COPYING file in the root directory of this source tree). 9 | * You may select, at your option, one of the above-listed licenses. 10 | */ 11 | 12 | #ifndef FL2POOL_H 13 | #define FL2POOL_H 14 | 15 | #if defined (__cplusplus) 16 | extern "C" { 17 | #endif 18 | 19 | 20 | #include /* size_t */ 21 | 22 | typedef struct FL2POOL_ctx_s FL2POOL_ctx; 23 | 24 | /*! FL2POOL_create() : 25 | * Create a thread pool with at most `numThreads` threads. 26 | * `numThreads` must be at least 1. 27 | * @return : FL2POOL_ctx pointer on success, else NULL. 28 | */ 29 | FL2POOL_ctx *FL2POOL_create(size_t numThreads); 30 | 31 | 32 | /*! FL2POOL_free() : 33 | Free a thread pool returned by FL2POOL_create(). 34 | */ 35 | void FL2POOL_free(FL2POOL_ctx *ctx); 36 | 37 | /*! FL2POOL_sizeof() : 38 | return memory usage of pool returned by FL2POOL_create(). 39 | */ 40 | size_t FL2POOL_sizeof(FL2POOL_ctx *ctx); 41 | 42 | /*! FL2POOL_function : 43 | The function type that can be added to a thread pool. 44 | */ 45 | typedef void(*FL2POOL_function)(void *, ptrdiff_t); 46 | 47 | /*! FL2POOL_add() : 48 | Add the job `function(opaque)` to the thread pool. 49 | FL2POOL_addRange adds multiple jobs with size_t parameter from first to less than end. 50 | Possibly blocks until there is room in the queue. 51 | Note : The function may be executed asynchronously, so `opaque` must live until the function has been completed. 52 | */ 53 | void FL2POOL_add(void* ctxVoid, FL2POOL_function function, void *opaque, ptrdiff_t n); 54 | void FL2POOL_addRange(void *ctx, FL2POOL_function function, void *opaque, ptrdiff_t first, ptrdiff_t end); 55 | 56 | int FL2POOL_waitAll(void *ctx, unsigned timeout); 57 | 58 | size_t FL2POOL_threadsBusy(void *ctx); 59 | 60 | #if defined (__cplusplus) 61 | } 62 | #endif 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /lzma2/fl2_threading.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2016 Tino Reichardt 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under both the BSD-style license (found in the 6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found 7 | * in the COPYING file in the root directory of this source tree). 8 | * 9 | * You can contact the author at: 10 | * - zstdmt source repository: https://github.com/mcmilk/zstdmt 11 | */ 12 | 13 | #ifndef THREADING_H_938743 14 | #define THREADING_H_938743 15 | 16 | #include "mem.h" 17 | 18 | #ifndef FL2_XZ_BUILD 19 | # ifdef _WIN32 20 | # define MYTHREAD_VISTA 21 | # else 22 | # define MYTHREAD_POSIX /* posix assumed ; need a better detection method */ 23 | # endif 24 | #elif defined(HAVE_CONFIG_H) 25 | # include 26 | #endif 27 | 28 | #if defined (__cplusplus) 29 | extern "C" { 30 | #endif 31 | 32 | unsigned FL2_checkNbThreads(unsigned nbThreads); 33 | 34 | 35 | #if !defined(FL2_SINGLETHREAD) && defined(MYTHREAD_VISTA) 36 | 37 | /** 38 | * Windows minimalist Pthread Wrapper, based on : 39 | * http://www.cse.wustl.edu/~schmidt/win32-cv-1.html 40 | */ 41 | #ifdef WINVER 42 | # undef WINVER 43 | #endif 44 | #define WINVER 0x0600 45 | 46 | #ifdef _WIN32_WINNT 47 | # undef _WIN32_WINNT 48 | #endif 49 | #define _WIN32_WINNT 0x0600 50 | 51 | #ifndef WIN32_LEAN_AND_MEAN 52 | # define WIN32_LEAN_AND_MEAN 53 | #endif 54 | 55 | #include 56 | #include 57 | 58 | 59 | /* mutex */ 60 | #define FL2_pthread_mutex_t CRITICAL_SECTION 61 | #define FL2_pthread_mutex_init(a, b) (InitializeCriticalSection((a)), 0) 62 | #define FL2_pthread_mutex_destroy(a) DeleteCriticalSection((a)) 63 | #define FL2_pthread_mutex_lock(a) EnterCriticalSection((a)) 64 | #define FL2_pthread_mutex_unlock(a) LeaveCriticalSection((a)) 65 | 66 | /* condition variable */ 67 | #define FL2_pthread_cond_t CONDITION_VARIABLE 68 | #define FL2_pthread_cond_init(a, b) (InitializeConditionVariable((a)), 0) 69 | #define FL2_pthread_cond_destroy(a) /* No delete */ 70 | #define FL2_pthread_cond_wait(a, b) SleepConditionVariableCS((a), (b), INFINITE) 71 | #define FL2_pthread_cond_timedwait(a, b, c) SleepConditionVariableCS((a), (b), (c)) 72 | #define FL2_pthread_cond_signal(a) WakeConditionVariable((a)) 73 | #define FL2_pthread_cond_broadcast(a) WakeAllConditionVariable((a)) 74 | 75 | /* FL2_pthread_create() and FL2_pthread_join() */ 76 | typedef struct { 77 | HANDLE handle; 78 | void* (*start_routine)(void*); 79 | void* arg; 80 | } FL2_pthread_t; 81 | 82 | int FL2_pthread_create(FL2_pthread_t* thread, const void* unused, 83 | void* (*start_routine) (void*), void* arg); 84 | 85 | int FL2_pthread_join(FL2_pthread_t thread, void** value_ptr); 86 | 87 | /** 88 | * add here more wrappers as required 89 | */ 90 | 91 | 92 | #elif !defined(FL2_SINGLETHREAD) && defined(MYTHREAD_POSIX) 93 | /* === POSIX Systems === */ 94 | # include 95 | # include 96 | 97 | #define FL2_pthread_mutex_t pthread_mutex_t 98 | #define FL2_pthread_mutex_init(a, b) pthread_mutex_init((a), (b)) 99 | #define FL2_pthread_mutex_destroy(a) pthread_mutex_destroy((a)) 100 | #define FL2_pthread_mutex_lock(a) pthread_mutex_lock((a)) 101 | #define FL2_pthread_mutex_unlock(a) pthread_mutex_unlock((a)) 102 | 103 | #define FL2_pthread_cond_t pthread_cond_t 104 | #define FL2_pthread_cond_init(a, b) pthread_cond_init((a), (b)) 105 | #define FL2_pthread_cond_destroy(a) pthread_cond_destroy((a)) 106 | #define FL2_pthread_cond_wait(a, b) pthread_cond_wait((a), (b)) 107 | #define FL2_pthread_cond_signal(a) pthread_cond_signal((a)) 108 | #define FL2_pthread_cond_broadcast(a) pthread_cond_broadcast((a)) 109 | 110 | #define FL2_pthread_t pthread_t 111 | #define FL2_pthread_create(a, b, c, d) pthread_create((a), (b), (c), (d)) 112 | #define FL2_pthread_join(a, b) pthread_join((a),(b)) 113 | 114 | /* Timed wait functions from XZ by Lasse Collin 115 | */ 116 | 117 | /* Sets condtime to the absolute time that is timeout_ms milliseconds 118 | * in the future. 119 | */ 120 | static inline void 121 | mythread_condtime_set(struct timespec *condtime, U32 timeout_ms) 122 | { 123 | condtime->tv_sec = timeout_ms / 1000; 124 | condtime->tv_nsec = (timeout_ms % 1000) * 1000000; 125 | 126 | struct timeval now; 127 | gettimeofday(&now, NULL); 128 | 129 | condtime->tv_sec += now.tv_sec; 130 | condtime->tv_nsec += now.tv_usec * 1000L; 131 | 132 | /* tv_nsec must stay in the range [0, 999_999_999]. */ 133 | if (condtime->tv_nsec >= 1000000000L) { 134 | condtime->tv_nsec -= 1000000000L; 135 | ++condtime->tv_sec; 136 | } 137 | } 138 | 139 | /* Waits on a condition or until a timeout expires. If the timeout expires, 140 | * non-zero is returned, otherwise zero is returned. 141 | */ 142 | static inline void 143 | FL2_pthread_cond_timedwait(FL2_pthread_cond_t *cond, FL2_pthread_mutex_t *mutex, 144 | U32 timeout_ms) 145 | { 146 | struct timespec condtime; 147 | mythread_condtime_set(&condtime, timeout_ms); 148 | pthread_cond_timedwait(cond, mutex, &condtime); 149 | } 150 | 151 | 152 | #elif defined(FL2_SINGLETHREAD) 153 | /* No multithreading support */ 154 | 155 | typedef int FL2_pthread_mutex_t; 156 | #define FL2_pthread_mutex_init(a, b) ((void)a, 0) 157 | #define FL2_pthread_mutex_destroy(a) 158 | #define FL2_pthread_mutex_lock(a) 159 | #define FL2_pthread_mutex_unlock(a) 160 | 161 | typedef int FL2_pthread_cond_t; 162 | #define FL2_pthread_cond_init(a, b) ((void)a, 0) 163 | #define FL2_pthread_cond_destroy(a) 164 | #define FL2_pthread_cond_wait(a, b) 165 | #define FL2_pthread_cond_signal(a) 166 | #define FL2_pthread_cond_broadcast(a) 167 | 168 | /* do not use FL2_pthread_t */ 169 | 170 | #else 171 | # error FL2_SINGLETHREAD not defined but no threading support found 172 | #endif /* FL2_SINGLETHREAD */ 173 | 174 | #if defined (__cplusplus) 175 | } 176 | #endif 177 | 178 | #endif /* THREADING_H_938743 */ 179 | -------------------------------------------------------------------------------- /lzma2/lzma2_dec.h: -------------------------------------------------------------------------------- 1 | /* lzma2_dec.h -- LZMA2 Decoder 2 | 2017-04-03 : Igor Pavlov : Public domain 3 | Modified for FL2 by Conor McCarthy */ 4 | 5 | #ifndef __LZMA_DEC_H 6 | #define __LZMA_DEC_H 7 | 8 | #include "mem.h" 9 | 10 | #if defined (__cplusplus) 11 | extern "C" { 12 | #endif 13 | 14 | /* #define LZMA_DEC_PROB16 */ 15 | /* 32-bit probs can increase the speed on some CPUs, 16 | but memory usage for LZMA2_DCtx::probs will be doubled in that case */ 17 | 18 | #ifdef LZMA_DEC_PROB16 19 | typedef U16 LZMA2_prob; 20 | #else 21 | typedef U32 LZMA2_prob; 22 | #endif 23 | 24 | 25 | /* ---------- LZMA Properties ---------- */ 26 | 27 | typedef struct 28 | { 29 | BYTE lc; 30 | BYTE lp; 31 | BYTE pb; 32 | BYTE pad_; 33 | U32 dic_size; 34 | } LZMA2_props; 35 | 36 | /* LzmaProps_Decode - decodes properties 37 | Returns: 38 | SZ_OK 39 | SZ_ERROR_UNSUPPORTED - Unsupported properties 40 | */ 41 | 42 | 43 | /* ---------- LZMA Decoder state ---------- */ 44 | 45 | /* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case. 46 | Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */ 47 | 48 | #define LZMA_REQUIRED_INPUT_MAX 20 49 | 50 | #define kNumPosBitsMax 4 51 | #define kNumPosStatesMax (1 << kNumPosBitsMax) 52 | 53 | #define kLenNumLowBits 3 54 | #define kLenNumLowSymbols (1 << kLenNumLowBits) 55 | #define kLenNumHighBits 8 56 | #define kLenNumHighSymbols (1 << kLenNumHighBits) 57 | 58 | #define LenLow 0 59 | #define LenHigh (LenLow + 2 * (kNumPosStatesMax << kLenNumLowBits)) 60 | #define kNumLenProbs (LenHigh + kLenNumHighSymbols) 61 | 62 | #define LenChoice LenLow 63 | #define LenChoice2 (LenLow + (1 << kLenNumLowBits)) 64 | 65 | #define kNumStates 12 66 | #define kNumStates2 16 67 | #define kNumLitStates 7 68 | 69 | #define kStartPosModelIndex 4 70 | #define kEndPosModelIndex 14 71 | #define kNumFullDistances (1 << (kEndPosModelIndex >> 1)) 72 | 73 | #define kNumPosSlotBits 6 74 | #define kNumLenToPosStates 4 75 | 76 | #define kNumAlignBits 4 77 | #define kAlignTableSize (1 << kNumAlignBits) 78 | 79 | #define kMatchMinLen 2 80 | #define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols * 2 + kLenNumHighSymbols) 81 | 82 | /* External ASM code needs same CLzmaProb array layout. So don't change it. */ 83 | 84 | /* (probs_1664) is faster and better for code size at some platforms */ 85 | /* 86 | #ifdef MY_CPU_X86_OR_AMD64 87 | */ 88 | #define kStartOffset 1664 89 | #define GET_PROBS p->probs_1664 90 | /* 91 | #define GET_PROBS p->probs + kStartOffset 92 | #else 93 | #define kStartOffset 0 94 | #define GET_PROBS p->probs 95 | #endif 96 | */ 97 | 98 | #define SpecPos (-kStartOffset) 99 | #define IsRep0Long (SpecPos + kNumFullDistances) 100 | #define RepLenCoder (IsRep0Long + (kNumStates2 << kNumPosBitsMax)) 101 | #define LenCoder (RepLenCoder + kNumLenProbs) 102 | #define IsMatch (LenCoder + kNumLenProbs) 103 | #define Align (IsMatch + (kNumStates2 << kNumPosBitsMax)) 104 | #define IsRep (Align + kAlignTableSize) 105 | #define IsRepG0 (IsRep + kNumStates) 106 | #define IsRepG1 (IsRepG0 + kNumStates) 107 | #define IsRepG2 (IsRepG1 + kNumStates) 108 | #define PosSlot (IsRepG2 + kNumStates) 109 | #define Literal (PosSlot + (kNumLenToPosStates << kNumPosSlotBits)) 110 | #define NUM_BASE_PROBS (Literal + kStartOffset) 111 | 112 | #if Align != 0 && kStartOffset != 0 113 | #error Stop_Compiling_Bad_LZMA_kAlign 114 | #endif 115 | 116 | #if NUM_BASE_PROBS != 1984 117 | #error Stop_Compiling_Bad_LZMA_PROBS 118 | #endif 119 | 120 | 121 | #define kLzmaLitSize 0x300 122 | 123 | #define LzmaProps_GetNumProbs(p) (NUM_BASE_PROBS + ((U32)kLzmaLitSize << ((p)->lc + (p)->lp))) 124 | 125 | 126 | #define CALC_POS_STATE(processed_pos, pb_mask) (((processed_pos) & (pb_mask)) << 4) 127 | #define COMBINED_PS_STATE (pos_state + state) 128 | #define GET_LEN_STATE (pos_state) 129 | 130 | #define kLzma2LcLpMax 4U 131 | 132 | 133 | typedef struct 134 | { 135 | LZMA2_props prop; 136 | BYTE *dic; 137 | size_t dic_pos; 138 | size_t dic_buf_size; 139 | const BYTE *buf; 140 | LZMA2_prob *probs_1664; 141 | U32 range; 142 | U32 code; 143 | U32 processed_pos; 144 | U32 check_dic_size; 145 | U32 reps[4]; 146 | unsigned state; 147 | unsigned state2; 148 | unsigned remain_len; 149 | size_t pack_size; 150 | size_t unpack_size; 151 | BYTE control; 152 | BYTE need_init_dic; 153 | BYTE need_init_state; 154 | BYTE need_init_state2; 155 | BYTE need_init_prop; 156 | BYTE need_flush; 157 | BYTE ext_dic; 158 | BYTE pad_; 159 | LZMA2_prob probs[NUM_BASE_PROBS + ((U32)kLzmaLitSize << kLzma2LcLpMax)]; 160 | } LZMA2_DCtx; 161 | 162 | void LZMA_constructDCtx(LZMA2_DCtx *p); 163 | 164 | typedef enum 165 | { 166 | LZMA_FINISH_ANY, /* finish at any point */ 167 | LZMA_FINISH_END /* block must be finished at the end */ 168 | } LZMA2_finishMode; 169 | 170 | typedef enum 171 | { 172 | LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */ 173 | LZMA_STATUS_FINISHED, /* stream was finished */ 174 | LZMA_STATUS_NOT_FINISHED, /* stream was not finished */ 175 | LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */ 176 | LZMA_STATUS_OUTPUT_FULL /* not finished; output buffer is full */ 177 | } LZMA2_status; 178 | 179 | void LZMA_destructDCtx(LZMA2_DCtx *const p); 180 | 181 | size_t LZMA2_getDictSizeFromProp(BYTE const dict_prop); 182 | 183 | #define LZMA2_CONTENTSIZE_ERROR (size_t)-1 184 | 185 | U64 LZMA2_getUnpackSize(const BYTE *const src, size_t const src_len); 186 | 187 | size_t LZMA2_decMemoryUsage(size_t const dict_size); 188 | 189 | size_t LZMA2_initDecoder(LZMA2_DCtx *const p, BYTE const dict_prop, BYTE *const dic, size_t dic_buf_size); 190 | 191 | size_t LZMA2_decodeToDic(LZMA2_DCtx *const p, size_t const dic_limit, 192 | const BYTE *const src, size_t *const src_len, LZMA2_finishMode const finish_mode); 193 | 194 | size_t LZMA2_decodeToBuf(LZMA2_DCtx *const p, BYTE *dest, size_t *const dest_len, 195 | const BYTE *src, size_t *const src_len, LZMA2_finishMode const finish_mode); 196 | 197 | typedef enum 198 | { 199 | CHUNK_MORE_DATA, 200 | CHUNK_CONTINUE, 201 | CHUNK_DICT_RESET, 202 | CHUNK_FINAL, 203 | CHUNK_ERROR 204 | } LZMA2_parseRes; 205 | 206 | typedef struct 207 | { 208 | size_t pack_size; 209 | size_t unpack_size; 210 | } LZMA2_chunk; 211 | 212 | #if defined(FL2_DEBUG) && (FL2_DEBUG>=1) 213 | # define LZMA2_MT_INPUT_SIZE 0x400 214 | #else 215 | # define LZMA2_MT_INPUT_SIZE 0x40000 216 | #endif 217 | 218 | LZMA2_parseRes LZMA2_parseInput(const BYTE* const in_buf, size_t const pos, ptrdiff_t const len, LZMA2_chunk *const inf); 219 | 220 | #if defined (__cplusplus) 221 | } 222 | #endif 223 | 224 | #endif 225 | -------------------------------------------------------------------------------- /lzma2/lzma2_enc.h: -------------------------------------------------------------------------------- 1 | /* lzma2_enc.h -- LZMA2 Encoder 2 | Based on LzmaEnc.h and Lzma2Enc.h : Igor Pavlov 3 | Modified for FL2 by Conor McCarthy 4 | Public domain 5 | */ 6 | 7 | #ifndef RADYX_LZMA2_ENCODER_H 8 | #define RADYX_LZMA2_ENCODER_H 9 | 10 | #include "mem.h" 11 | #include "data_block.h" 12 | #include "radix_mf.h" 13 | #include "atomic.h" 14 | 15 | #if defined (__cplusplus) 16 | extern "C" { 17 | #endif 18 | 19 | #define kFastDistBits 12U 20 | 21 | #define LZMA2_END_MARKER '\0' 22 | #define ENC_MIN_BYTES_PER_THREAD 0x1C000 /* Enough for 8 threads, 1 Mb dict, 2/16 overlap */ 23 | 24 | 25 | typedef struct LZMA2_ECtx_s LZMA2_ECtx; 26 | 27 | typedef struct 28 | { 29 | unsigned lc; 30 | unsigned lp; 31 | unsigned pb; 32 | unsigned fast_length; 33 | unsigned match_cycles; 34 | FL2_strategy strategy; 35 | unsigned second_dict_bits; 36 | unsigned reset_interval; 37 | } FL2_lzma2Parameters; 38 | 39 | 40 | LZMA2_ECtx* LZMA2_createECtx(void); 41 | 42 | void LZMA2_freeECtx(LZMA2_ECtx *const enc); 43 | 44 | int LZMA2_hashAlloc(LZMA2_ECtx *const enc, const FL2_lzma2Parameters* const options); 45 | 46 | size_t LZMA2_encode(LZMA2_ECtx *const enc, 47 | FL2_matchTable* const tbl, 48 | FL2_dataBlock const block, 49 | const FL2_lzma2Parameters* const options, 50 | int stream_prop, 51 | FL2_atomic *const progress_in, 52 | FL2_atomic *const progress_out, 53 | int *const canceled); 54 | 55 | BYTE LZMA2_getDictSizeProp(size_t const dictionary_size); 56 | 57 | size_t LZMA2_compressBound(size_t src_size); 58 | 59 | size_t LZMA2_encMemoryUsage(unsigned const chain_log, FL2_strategy const strategy, unsigned const thread_count); 60 | 61 | #if defined (__cplusplus) 62 | } 63 | #endif 64 | 65 | #endif /* RADYX_LZMA2_ENCODER_H */ -------------------------------------------------------------------------------- /lzma2/mem.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under both the BSD-style license (found in the 6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found 7 | * in the COPYING file in the root directory of this source tree). 8 | * You may select, at your option, one of the above-listed licenses. 9 | */ 10 | 11 | #ifndef MEM_H_MODULE 12 | #define MEM_H_MODULE 13 | 14 | #if defined (__cplusplus) 15 | extern "C" { 16 | #endif 17 | 18 | /*-**************************************** 19 | * Dependencies 20 | ******************************************/ 21 | #include /* size_t, ptrdiff_t */ 22 | #include /* memcpy */ 23 | 24 | 25 | /*-**************************************** 26 | * Compiler specifics 27 | ******************************************/ 28 | #if defined(_MSC_VER) /* Visual Studio */ 29 | # include /* _byteswap_ulong */ 30 | # include /* _byteswap_* */ 31 | #endif 32 | #if defined(__GNUC__) 33 | # define MEM_STATIC static __inline __attribute__((unused)) 34 | #elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) 35 | # define MEM_STATIC static inline 36 | #elif defined(_MSC_VER) 37 | # define MEM_STATIC static __inline 38 | #else 39 | # define MEM_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */ 40 | #endif 41 | 42 | #ifndef __has_builtin 43 | # define __has_builtin(x) 0 /* compat. with non-clang compilers */ 44 | #endif 45 | 46 | /* code only tested on 32 and 64 bits systems */ 47 | #define MEM_STATIC_ASSERT(c) { enum { MEM_static_assert = 1/(int)(!!(c)) }; } 48 | MEM_STATIC void MEM_check(void) { MEM_STATIC_ASSERT((sizeof(size_t)==4) || (sizeof(size_t)==8)); } 49 | 50 | 51 | /*-************************************************************** 52 | * Basic Types 53 | *****************************************************************/ 54 | #if !defined (__VMS) && (defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) ) 55 | # include 56 | typedef uint8_t BYTE; 57 | typedef uint16_t U16; 58 | typedef int16_t S16; 59 | typedef uint32_t U32; 60 | typedef int32_t S32; 61 | typedef uint64_t U64; 62 | typedef int64_t S64; 63 | #else 64 | # include 65 | #if CHAR_BIT != 8 66 | # error "this implementation requires char to be exactly 8-bit type" 67 | #endif 68 | typedef unsigned char BYTE; 69 | #if USHRT_MAX != 65535 70 | # error "this implementation requires short to be exactly 16-bit type" 71 | #endif 72 | typedef unsigned short U16; 73 | typedef signed short S16; 74 | #if UINT_MAX != 4294967295 75 | # error "this implementation requires int to be exactly 32-bit type" 76 | #endif 77 | typedef unsigned int U32; 78 | typedef signed int S32; 79 | /* note : there are no limits defined for long long type in C90. 80 | * limits exist in C99, however, in such case, is preferred */ 81 | typedef unsigned long long U64; 82 | typedef signed long long S64; 83 | #endif 84 | 85 | 86 | /*-************************************************************** 87 | * Memory I/O 88 | *****************************************************************/ 89 | /* MEM_FORCE_MEMORY_ACCESS : 90 | * By default, access to unaligned memory is controlled by `memcpy()`, which is safe and portable. 91 | * Unfortunately, on some target/compiler combinations, the generated assembly is sub-optimal. 92 | * The below switch allow to select different access method for improved performance. 93 | * Method 0 (default) : use `memcpy()`. Safe and portable. 94 | * Method 1 : `__packed` statement. It depends on compiler extension (i.e., not portable). 95 | * This method is safe if your compiler supports it, and *generally* as fast or faster than `memcpy`. 96 | * Method 2 : direct access. This method is portable but violate C standard. 97 | * It can generate buggy code on targets depending on alignment. 98 | * In some circumstances, it's the only known way to get the most performance (i.e. GCC + ARMv6) 99 | * See http://fastcompression.blogspot.fr/2015/08/accessing-unaligned-memory.html for details. 100 | * Prefer these methods in priority order (0 > 1 > 2) 101 | */ 102 | #ifndef MEM_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */ 103 | # if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) ) 104 | # define MEM_FORCE_MEMORY_ACCESS 2 105 | # elif defined(__INTEL_COMPILER) || defined(__GNUC__) 106 | # define MEM_FORCE_MEMORY_ACCESS 1 107 | # endif 108 | #endif 109 | 110 | MEM_STATIC unsigned MEM_32bits(void) { return sizeof(size_t)==4; } 111 | MEM_STATIC unsigned MEM_64bits(void) { return sizeof(size_t)==8; } 112 | 113 | MEM_STATIC unsigned MEM_isLittleEndian(void) 114 | { 115 | const union { U32 u; BYTE c[4]; } one = { 1 }; /* don't use static : performance detrimental */ 116 | return one.c[0]; 117 | } 118 | 119 | #if defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==2) 120 | 121 | /* violates C standard, by lying on structure alignment. 122 | Only use if no other choice to achieve best performance on target platform */ 123 | MEM_STATIC U16 MEM_read16(const void* memPtr) { return *(const U16*) memPtr; } 124 | MEM_STATIC U32 MEM_read32(const void* memPtr) { return *(const U32*) memPtr; } 125 | MEM_STATIC U64 MEM_read64(const void* memPtr) { return *(const U64*) memPtr; } 126 | MEM_STATIC size_t MEM_readST(const void* memPtr) { return *(const size_t*) memPtr; } 127 | 128 | MEM_STATIC void MEM_write16(void* memPtr, U16 value) { *(U16*)memPtr = value; } 129 | MEM_STATIC void MEM_write32(void* memPtr, U32 value) { *(U32*)memPtr = value; } 130 | MEM_STATIC void MEM_write64(void* memPtr, U64 value) { *(U64*)memPtr = value; } 131 | 132 | #elif defined(MEM_FORCE_MEMORY_ACCESS) && (MEM_FORCE_MEMORY_ACCESS==1) 133 | 134 | /* __pack instructions are safer, but compiler specific, hence potentially problematic for some compilers */ 135 | /* currently only defined for gcc and icc */ 136 | #if defined(_MSC_VER) || (defined(__INTEL_COMPILER) && defined(WIN32)) 137 | __pragma( pack(push, 1) ) 138 | typedef struct { U16 v; } unalign16; 139 | typedef struct { U32 v; } unalign32; 140 | typedef struct { U64 v; } unalign64; 141 | typedef struct { size_t v; } unalignArch; 142 | __pragma( pack(pop) ) 143 | #else 144 | typedef struct { U16 v; } __attribute__((packed)) unalign16; 145 | typedef struct { U32 v; } __attribute__((packed)) unalign32; 146 | typedef struct { U64 v; } __attribute__((packed)) unalign64; 147 | typedef struct { size_t v; } __attribute__((packed)) unalignArch; 148 | #endif 149 | 150 | MEM_STATIC U16 MEM_read16(const void* ptr) { return ((const unalign16*)ptr)->v; } 151 | MEM_STATIC U32 MEM_read32(const void* ptr) { return ((const unalign32*)ptr)->v; } 152 | MEM_STATIC U64 MEM_read64(const void* ptr) { return ((const unalign64*)ptr)->v; } 153 | MEM_STATIC size_t MEM_readST(const void* ptr) { return ((const unalignArch*)ptr)->v; } 154 | 155 | MEM_STATIC void MEM_write16(void* memPtr, U16 value) { ((unalign16*)memPtr)->v = value; } 156 | MEM_STATIC void MEM_write32(void* memPtr, U32 value) { ((unalign32*)memPtr)->v = value; } 157 | MEM_STATIC void MEM_write64(void* memPtr, U64 value) { ((unalign64*)memPtr)->v = value; } 158 | 159 | #else 160 | 161 | /* default method, safe and standard. 162 | can sometimes prove slower */ 163 | 164 | MEM_STATIC U16 MEM_read16(const void* memPtr) 165 | { 166 | U16 val; memcpy(&val, memPtr, sizeof(val)); return val; 167 | } 168 | 169 | MEM_STATIC U32 MEM_read32(const void* memPtr) 170 | { 171 | U32 val; memcpy(&val, memPtr, sizeof(val)); return val; 172 | } 173 | 174 | MEM_STATIC U64 MEM_read64(const void* memPtr) 175 | { 176 | U64 val; memcpy(&val, memPtr, sizeof(val)); return val; 177 | } 178 | 179 | MEM_STATIC size_t MEM_readST(const void* memPtr) 180 | { 181 | size_t val; memcpy(&val, memPtr, sizeof(val)); return val; 182 | } 183 | 184 | MEM_STATIC void MEM_write16(void* memPtr, U16 value) 185 | { 186 | memcpy(memPtr, &value, sizeof(value)); 187 | } 188 | 189 | MEM_STATIC void MEM_write32(void* memPtr, U32 value) 190 | { 191 | memcpy(memPtr, &value, sizeof(value)); 192 | } 193 | 194 | MEM_STATIC void MEM_write64(void* memPtr, U64 value) 195 | { 196 | memcpy(memPtr, &value, sizeof(value)); 197 | } 198 | 199 | #endif /* MEM_FORCE_MEMORY_ACCESS */ 200 | 201 | MEM_STATIC U32 MEM_swap32(U32 in) 202 | { 203 | #if defined(_MSC_VER) /* Visual Studio */ 204 | return _byteswap_ulong(in); 205 | #elif (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \ 206 | || (defined(__clang__) && __has_builtin(__builtin_bswap32)) 207 | return __builtin_bswap32(in); 208 | #else 209 | return ((in << 24) & 0xff000000 ) | 210 | ((in << 8) & 0x00ff0000 ) | 211 | ((in >> 8) & 0x0000ff00 ) | 212 | ((in >> 24) & 0x000000ff ); 213 | #endif 214 | } 215 | 216 | MEM_STATIC U64 MEM_swap64(U64 in) 217 | { 218 | #if defined(_MSC_VER) /* Visual Studio */ 219 | return _byteswap_uint64(in); 220 | #elif (defined (__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)) \ 221 | || (defined(__clang__) && __has_builtin(__builtin_bswap64)) 222 | return __builtin_bswap64(in); 223 | #else 224 | return ((in << 56) & 0xff00000000000000ULL) | 225 | ((in << 40) & 0x00ff000000000000ULL) | 226 | ((in << 24) & 0x0000ff0000000000ULL) | 227 | ((in << 8) & 0x000000ff00000000ULL) | 228 | ((in >> 8) & 0x00000000ff000000ULL) | 229 | ((in >> 24) & 0x0000000000ff0000ULL) | 230 | ((in >> 40) & 0x000000000000ff00ULL) | 231 | ((in >> 56) & 0x00000000000000ffULL); 232 | #endif 233 | } 234 | 235 | MEM_STATIC size_t MEM_swapST(size_t in) 236 | { 237 | if (MEM_32bits()) 238 | return (size_t)MEM_swap32((U32)in); 239 | else 240 | return (size_t)MEM_swap64((U64)in); 241 | } 242 | 243 | /*=== Little endian r/w ===*/ 244 | 245 | MEM_STATIC U16 MEM_readLE16(const void* memPtr) 246 | { 247 | if (MEM_isLittleEndian()) 248 | return MEM_read16(memPtr); 249 | else { 250 | const BYTE* p = (const BYTE*)memPtr; 251 | return (U16)(p[0] + (p[1]<<8)); 252 | } 253 | } 254 | 255 | MEM_STATIC void MEM_writeLE16(void* memPtr, U16 val) 256 | { 257 | if (MEM_isLittleEndian()) { 258 | MEM_write16(memPtr, val); 259 | } else { 260 | BYTE* p = (BYTE*)memPtr; 261 | p[0] = (BYTE)val; 262 | p[1] = (BYTE)(val>>8); 263 | } 264 | } 265 | 266 | MEM_STATIC U32 MEM_readLE24(const void* memPtr) 267 | { 268 | return MEM_readLE16(memPtr) + (((const BYTE*)memPtr)[2] << 16); 269 | } 270 | 271 | MEM_STATIC void MEM_writeLE24(void* memPtr, U32 val) 272 | { 273 | MEM_writeLE16(memPtr, (U16)val); 274 | ((BYTE*)memPtr)[2] = (BYTE)(val>>16); 275 | } 276 | 277 | MEM_STATIC U32 MEM_readLE32(const void* memPtr) 278 | { 279 | if (MEM_isLittleEndian()) 280 | return MEM_read32(memPtr); 281 | else 282 | return MEM_swap32(MEM_read32(memPtr)); 283 | } 284 | 285 | MEM_STATIC void MEM_writeLE32(void* memPtr, U32 val32) 286 | { 287 | if (MEM_isLittleEndian()) 288 | MEM_write32(memPtr, val32); 289 | else 290 | MEM_write32(memPtr, MEM_swap32(val32)); 291 | } 292 | 293 | MEM_STATIC U64 MEM_readLE64(const void* memPtr) 294 | { 295 | if (MEM_isLittleEndian()) 296 | return MEM_read64(memPtr); 297 | else 298 | return MEM_swap64(MEM_read64(memPtr)); 299 | } 300 | 301 | MEM_STATIC void MEM_writeLE64(void* memPtr, U64 val64) 302 | { 303 | if (MEM_isLittleEndian()) 304 | MEM_write64(memPtr, val64); 305 | else 306 | MEM_write64(memPtr, MEM_swap64(val64)); 307 | } 308 | 309 | MEM_STATIC size_t MEM_readLEST(const void* memPtr) 310 | { 311 | if (MEM_32bits()) 312 | return (size_t)MEM_readLE32(memPtr); 313 | else 314 | return (size_t)MEM_readLE64(memPtr); 315 | } 316 | 317 | MEM_STATIC void MEM_writeLEST(void* memPtr, size_t val) 318 | { 319 | if (MEM_32bits()) 320 | MEM_writeLE32(memPtr, (U32)val); 321 | else 322 | MEM_writeLE64(memPtr, (U64)val); 323 | } 324 | 325 | /*=== Big endian r/w ===*/ 326 | 327 | MEM_STATIC U32 MEM_readBE32(const void* memPtr) 328 | { 329 | if (MEM_isLittleEndian()) 330 | return MEM_swap32(MEM_read32(memPtr)); 331 | else 332 | return MEM_read32(memPtr); 333 | } 334 | 335 | MEM_STATIC void MEM_writeBE32(void* memPtr, U32 val32) 336 | { 337 | if (MEM_isLittleEndian()) 338 | MEM_write32(memPtr, MEM_swap32(val32)); 339 | else 340 | MEM_write32(memPtr, val32); 341 | } 342 | 343 | MEM_STATIC U64 MEM_readBE64(const void* memPtr) 344 | { 345 | if (MEM_isLittleEndian()) 346 | return MEM_swap64(MEM_read64(memPtr)); 347 | else 348 | return MEM_read64(memPtr); 349 | } 350 | 351 | MEM_STATIC void MEM_writeBE64(void* memPtr, U64 val64) 352 | { 353 | if (MEM_isLittleEndian()) 354 | MEM_write64(memPtr, MEM_swap64(val64)); 355 | else 356 | MEM_write64(memPtr, val64); 357 | } 358 | 359 | MEM_STATIC size_t MEM_readBEST(const void* memPtr) 360 | { 361 | if (MEM_32bits()) 362 | return (size_t)MEM_readBE32(memPtr); 363 | else 364 | return (size_t)MEM_readBE64(memPtr); 365 | } 366 | 367 | MEM_STATIC void MEM_writeBEST(void* memPtr, size_t val) 368 | { 369 | if (MEM_32bits()) 370 | MEM_writeBE32(memPtr, (U32)val); 371 | else 372 | MEM_writeBE64(memPtr, (U64)val); 373 | } 374 | 375 | 376 | #if defined (__cplusplus) 377 | } 378 | #endif 379 | 380 | #endif /* MEM_H_MODULE */ 381 | -------------------------------------------------------------------------------- /lzma2/platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present, Przemyslaw Skibinski, Yann Collet, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under both the BSD-style license (found in the 6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found 7 | * in the COPYING file in the root directory of this source tree). 8 | * You may select, at your option, one of the above-listed licenses. 9 | */ 10 | 11 | #ifndef PLATFORM_H_MODULE 12 | #define PLATFORM_H_MODULE 13 | 14 | #if defined (__cplusplus) 15 | extern "C" { 16 | #endif 17 | 18 | 19 | 20 | /* ************************************** 21 | * Compiler Options 22 | ****************************************/ 23 | #if defined(_MSC_VER) 24 | # define _CRT_SECURE_NO_WARNINGS /* Disable Visual Studio warning messages for fopen, strncpy, strerror */ 25 | # if (_MSC_VER <= 1800) /* 1800 == Visual Studio 2013 */ 26 | # define _CRT_SECURE_NO_DEPRECATE /* VS2005 - must be declared before and */ 27 | # define snprintf sprintf_s /* snprintf unsupported by Visual <= 2013 */ 28 | # endif 29 | #endif 30 | 31 | 32 | /* ************************************** 33 | * Detect 64-bit OS 34 | * http://nadeausoftware.com/articles/2012/02/c_c_tip_how_detect_processor_type_using_compiler_predefined_macros 35 | ****************************************/ 36 | #if defined __ia64 || defined _M_IA64 /* Intel Itanium */ \ 37 | || defined __powerpc64__ || defined __ppc64__ || defined __PPC64__ /* POWER 64-bit */ \ 38 | || (defined __sparc && (defined __sparcv9 || defined __sparc_v9__ || defined __arch64__)) || defined __sparc64__ /* SPARC 64-bit */ \ 39 | || defined __x86_64__s || defined _M_X64 /* x86 64-bit */ \ 40 | || defined __arm64__ || defined __aarch64__ || defined __ARM64_ARCH_8__ /* ARM 64-bit */ \ 41 | || (defined __mips && (__mips == 64 || __mips == 4 || __mips == 3)) /* MIPS 64-bit */ \ 42 | || defined _LP64 || defined __LP64__ /* NetBSD, OpenBSD */ || defined __64BIT__ /* AIX */ || defined _ADDR64 /* Cray */ \ 43 | || (defined __SIZEOF_POINTER__ && __SIZEOF_POINTER__ == 8) /* gcc */ 44 | # if !defined(__64BIT__) 45 | # define __64BIT__ 1 46 | # endif 47 | #endif 48 | 49 | 50 | /* ********************************************************* 51 | * Turn on Large Files support (>4GB) for 32-bit Linux/Unix 52 | ***********************************************************/ 53 | #if !defined(__64BIT__) || defined(__MINGW32__) /* No point defining Large file for 64 bit but MinGW-w64 requires it */ 54 | # if !defined(_FILE_OFFSET_BITS) 55 | # define _FILE_OFFSET_BITS 64 /* turn off_t into a 64-bit type for ftello, fseeko */ 56 | # endif 57 | # if !defined(_LARGEFILE_SOURCE) /* obsolete macro, replaced with _FILE_OFFSET_BITS */ 58 | # define _LARGEFILE_SOURCE 1 /* Large File Support extension (LFS) - fseeko, ftello */ 59 | # endif 60 | # if defined(_AIX) || defined(__hpux) 61 | # define _LARGE_FILES /* Large file support on 32-bits AIX and HP-UX */ 62 | # endif 63 | #endif 64 | 65 | 66 | /* ************************************************************ 67 | * Detect POSIX version 68 | * PLATFORM_POSIX_VERSION = 0 for non-Unix e.g. Windows 69 | * PLATFORM_POSIX_VERSION = 1 for Unix-like but non-POSIX 70 | * PLATFORM_POSIX_VERSION > 1 is equal to found _POSIX_VERSION 71 | * Value of PLATFORM_POSIX_VERSION can be forced on command line 72 | ***************************************************************/ 73 | #ifndef PLATFORM_POSIX_VERSION 74 | 75 | # if (defined(__APPLE__) && defined(__MACH__)) || defined(__SVR4) || defined(_AIX) || defined(__hpux) /* POSIX.1-2001 (SUSv3) conformant */ \ 76 | || defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) /* BSD distros */ 77 | /* exception rule : force posix version to 200112L, 78 | * note: it's better to use unistd.h's _POSIX_VERSION whenever possible */ 79 | # define PLATFORM_POSIX_VERSION 200112L 80 | 81 | /* try to determine posix version through official unistd.h's _POSIX_VERSION (http://pubs.opengroup.org/onlinepubs/7908799/xsh/unistd.h.html). 82 | * note : there is no simple way to know in advance if is present or not on target system, 83 | * Posix specification mandates its presence and its content, but target system must respect this spec. 84 | * It's necessary to _not_ #include whenever target OS is not unix-like 85 | * otherwise it will block preprocessing stage. 86 | * The following list of build macros tries to "guess" if target OS is likely unix-like, and therefore can #include 87 | */ 88 | # elif !defined(_WIN32) \ 89 | && (defined(__unix__) || defined(__unix) \ 90 | || defined(__midipix__) || defined(__VMS) || defined(__HAIKU__)) 91 | 92 | # if defined(__linux__) || defined(__linux) 93 | # ifndef _POSIX_C_SOURCE 94 | # define _POSIX_C_SOURCE 200112L /* feature test macro : https://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html */ 95 | # endif 96 | # endif 97 | # include /* declares _POSIX_VERSION */ 98 | # if defined(_POSIX_VERSION) /* POSIX compliant */ 99 | # define PLATFORM_POSIX_VERSION _POSIX_VERSION 100 | # else 101 | # define PLATFORM_POSIX_VERSION 1 102 | # endif 103 | 104 | # else /* non-unix target platform (like Windows) */ 105 | # define PLATFORM_POSIX_VERSION 0 106 | # endif 107 | 108 | #endif /* PLATFORM_POSIX_VERSION */ 109 | 110 | /*-********************************************* 111 | * Detect if isatty() and fileno() are available 112 | ************************************************/ 113 | #if (defined(__linux__) && (PLATFORM_POSIX_VERSION > 1)) \ 114 | || (PLATFORM_POSIX_VERSION >= 200112L) \ 115 | || defined(__DJGPP__) \ 116 | || defined(__MSYS__) 117 | # include /* isatty */ 118 | # define IS_CONSOLE(stdStream) isatty(fileno(stdStream)) 119 | #elif defined(MSDOS) || defined(OS2) || defined(__CYGWIN__) 120 | # include /* _isatty */ 121 | # define IS_CONSOLE(stdStream) _isatty(_fileno(stdStream)) 122 | #elif defined(WIN32) || defined(_WIN32) 123 | # include /* _isatty */ 124 | # include /* DeviceIoControl, HANDLE, FSCTL_SET_SPARSE */ 125 | # include /* FILE */ 126 | static __inline int IS_CONSOLE(FILE* stdStream) { 127 | DWORD dummy; 128 | return _isatty(_fileno(stdStream)) && GetConsoleMode((HANDLE)_get_osfhandle(_fileno(stdStream)), &dummy); 129 | } 130 | #else 131 | # define IS_CONSOLE(stdStream) 0 132 | #endif 133 | 134 | 135 | /****************************** 136 | * OS-specific IO behaviors 137 | ******************************/ 138 | #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(_WIN32) 139 | # include /* _O_BINARY */ 140 | # include /* _setmode, _fileno, _get_osfhandle */ 141 | # if !defined(__DJGPP__) 142 | # include /* DeviceIoControl, HANDLE, FSCTL_SET_SPARSE */ 143 | # include /* FSCTL_SET_SPARSE */ 144 | # define SET_BINARY_MODE(file) { int const unused=_setmode(_fileno(file), _O_BINARY); (void)unused; } 145 | # define SET_SPARSE_FILE_MODE(file) { DWORD dw; DeviceIoControl((HANDLE) _get_osfhandle(_fileno(file)), FSCTL_SET_SPARSE, 0, 0, 0, 0, &dw, 0); } 146 | # else 147 | # define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) 148 | # define SET_SPARSE_FILE_MODE(file) 149 | # endif 150 | #else 151 | # define SET_BINARY_MODE(file) 152 | # define SET_SPARSE_FILE_MODE(file) 153 | #endif 154 | 155 | 156 | #ifndef ZSTD_SPARSE_DEFAULT 157 | # if (defined(__APPLE__) && defined(__MACH__)) 158 | # define ZSTD_SPARSE_DEFAULT 0 159 | # else 160 | # define ZSTD_SPARSE_DEFAULT 1 161 | # endif 162 | #endif 163 | 164 | 165 | #ifndef ZSTD_START_SYMBOLLIST_FRAME 166 | # ifdef __linux__ 167 | # define ZSTD_START_SYMBOLLIST_FRAME 2 168 | # elif defined __APPLE__ 169 | # define ZSTD_START_SYMBOLLIST_FRAME 4 170 | # else 171 | # define ZSTD_START_SYMBOLLIST_FRAME 0 172 | # endif 173 | #endif 174 | 175 | 176 | #ifndef ZSTD_SETPRIORITY_SUPPORT 177 | /* mandates presence of and support for setpriority() : http://man7.org/linux/man-pages/man2/setpriority.2.html */ 178 | # define ZSTD_SETPRIORITY_SUPPORT (PLATFORM_POSIX_VERSION >= 200112L) 179 | #endif 180 | 181 | 182 | #ifndef ZSTD_NANOSLEEP_SUPPORT 183 | /* mandates support of nanosleep() within : http://man7.org/linux/man-pages/man2/nanosleep.2.html */ 184 | # if (defined(__linux__) && (PLATFORM_POSIX_VERSION >= 199309L)) \ 185 | || (PLATFORM_POSIX_VERSION >= 200112L) 186 | # define ZSTD_NANOSLEEP_SUPPORT 1 187 | # else 188 | # define ZSTD_NANOSLEEP_SUPPORT 0 189 | # endif 190 | #endif 191 | 192 | 193 | #if defined (__cplusplus) 194 | } 195 | #endif 196 | 197 | #endif /* PLATFORM_H_MODULE */ 198 | -------------------------------------------------------------------------------- /lzma2/radix_get.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Conor McCarthy 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under both the BSD-style license (found in the 6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found 7 | * in the COPYING file in the root directory of this source tree). 8 | * You may select, at your option, one of the above-listed licenses. 9 | */ 10 | 11 | #ifndef FL2_RADIX_GET_H_ 12 | #define FL2_RADIX_GET_H_ 13 | 14 | #if defined (__cplusplus) 15 | extern "C" { 16 | #endif 17 | 18 | typedef struct 19 | { 20 | U32 length; 21 | U32 dist; 22 | } RMF_match; 23 | 24 | static size_t RMF_bitpackExtendMatch(const BYTE* const data, 25 | const U32* const table, 26 | ptrdiff_t const start_index, 27 | ptrdiff_t limit, 28 | U32 const link, 29 | size_t const length) 30 | { 31 | ptrdiff_t end_index = start_index + length; 32 | ptrdiff_t const dist = start_index - link; 33 | 34 | if (limit > start_index + (ptrdiff_t)kMatchLenMax) 35 | limit = start_index + kMatchLenMax; 36 | 37 | while (end_index < limit && end_index - (ptrdiff_t)(table[end_index] & RADIX_LINK_MASK) == dist) 38 | end_index += table[end_index] >> RADIX_LINK_BITS; 39 | 40 | if (end_index >= limit) { 41 | DEBUGLOG(7, "RMF_bitpackExtendMatch : pos %u, link %u, init length %u, full length %u", (U32)start_index, link, (U32)length, (U32)(limit - start_index)); 42 | return limit - start_index; 43 | } 44 | 45 | while (end_index < limit && data[end_index - dist] == data[end_index]) 46 | ++end_index; 47 | 48 | DEBUGLOG(7, "RMF_bitpackExtendMatch : pos %u, link %u, init length %u, full length %u", (U32)start_index, link, (U32)length, (U32)(end_index - start_index)); 49 | return end_index - start_index; 50 | } 51 | 52 | #define GetMatchLink(table, pos) ((const RMF_unit*)(table))[(pos) >> UNIT_BITS].links[(pos) & UNIT_MASK] 53 | 54 | #define GetMatchLength(table, pos) ((const RMF_unit*)(table))[(pos) >> UNIT_BITS].lengths[(pos) & UNIT_MASK] 55 | 56 | static size_t RMF_structuredExtendMatch(const BYTE* const data, 57 | const U32* const table, 58 | ptrdiff_t const start_index, 59 | ptrdiff_t limit, 60 | U32 const link, 61 | size_t const length) 62 | { 63 | ptrdiff_t end_index = start_index + length; 64 | ptrdiff_t const dist = start_index - link; 65 | 66 | if (limit > start_index + (ptrdiff_t)kMatchLenMax) 67 | limit = start_index + kMatchLenMax; 68 | 69 | while (end_index < limit && end_index - (ptrdiff_t)GetMatchLink(table, end_index) == dist) 70 | end_index += GetMatchLength(table, end_index); 71 | 72 | if (end_index >= limit) { 73 | DEBUGLOG(7, "RMF_structuredExtendMatch : pos %u, link %u, init length %u, full length %u", (U32)start_index, link, (U32)length, (U32)(limit - start_index)); 74 | return limit - start_index; 75 | } 76 | 77 | while (end_index < limit && data[end_index - dist] == data[end_index]) 78 | ++end_index; 79 | 80 | DEBUGLOG(7, "RMF_structuredExtendMatch : pos %u, link %u, init length %u, full length %u", (U32)start_index, link, (U32)length, (U32)(end_index - start_index)); 81 | return end_index - start_index; 82 | } 83 | 84 | FORCE_INLINE_TEMPLATE 85 | RMF_match RMF_getMatch(FL2_dataBlock block, 86 | FL2_matchTable* tbl, 87 | unsigned max_depth, 88 | int structTbl, 89 | size_t pos) 90 | { 91 | if (structTbl) 92 | { 93 | U32 const link = GetMatchLink(tbl->table, pos); 94 | 95 | RMF_match match; 96 | match.length = 0; 97 | 98 | if (link == RADIX_NULL_LINK) 99 | return match; 100 | 101 | size_t const length = GetMatchLength(tbl->table, pos); 102 | size_t const dist = pos - link - 1; 103 | 104 | if (length == max_depth || length == STRUCTURED_MAX_LENGTH /* from HandleRepeat */) 105 | match.length = (U32)RMF_structuredExtendMatch(block.data, tbl->table, pos, block.end, link, length); 106 | else 107 | match.length = (U32)length; 108 | 109 | match.dist = (U32)dist; 110 | 111 | return match; 112 | } 113 | else { 114 | U32 link = tbl->table[pos]; 115 | 116 | RMF_match match; 117 | match.length = 0; 118 | 119 | if (link == RADIX_NULL_LINK) 120 | return match; 121 | 122 | size_t const length = link >> RADIX_LINK_BITS; 123 | link &= RADIX_LINK_MASK; 124 | size_t const dist = pos - link - 1; 125 | 126 | if (length == max_depth || length == BITPACK_MAX_LENGTH /* from HandleRepeat */) 127 | match.length = (U32)RMF_bitpackExtendMatch(block.data, tbl->table, pos, block.end, link, length); 128 | else 129 | match.length = (U32)length; 130 | 131 | match.dist = (U32)dist; 132 | 133 | return match; 134 | } 135 | } 136 | 137 | FORCE_INLINE_TEMPLATE 138 | RMF_match RMF_getNextMatch(FL2_dataBlock block, 139 | FL2_matchTable* tbl, 140 | unsigned max_depth, 141 | int structTbl, 142 | size_t pos) 143 | { 144 | if (structTbl) 145 | { 146 | U32 const link = GetMatchLink(tbl->table, pos); 147 | 148 | RMF_match match; 149 | match.length = 0; 150 | 151 | if (link == RADIX_NULL_LINK) 152 | return match; 153 | 154 | size_t const length = GetMatchLength(tbl->table, pos); 155 | size_t const dist = pos - link - 1; 156 | 157 | /* same distance, one byte shorter */ 158 | if (link - 1 == GetMatchLink(tbl->table, pos - 1)) 159 | return match; 160 | 161 | if (length == max_depth || length == STRUCTURED_MAX_LENGTH /* from HandleRepeat */) 162 | match.length = (U32)RMF_structuredExtendMatch(block.data, tbl->table, pos, block.end, link, length); 163 | else 164 | match.length = (U32)length; 165 | 166 | match.dist = (U32)dist; 167 | 168 | return match; 169 | } 170 | else { 171 | U32 link = tbl->table[pos]; 172 | 173 | RMF_match match; 174 | match.length = 0; 175 | 176 | if (link == RADIX_NULL_LINK) 177 | return match; 178 | 179 | size_t const length = link >> RADIX_LINK_BITS; 180 | link &= RADIX_LINK_MASK; 181 | size_t const dist = pos - link - 1; 182 | 183 | /* same distance, one byte shorter */ 184 | if (link - 1 == (tbl->table[pos - 1] & RADIX_LINK_MASK)) 185 | return match; 186 | 187 | if (length == max_depth || length == BITPACK_MAX_LENGTH /* from HandleRepeat */) 188 | match.length = (U32)RMF_bitpackExtendMatch(block.data, tbl->table, pos, block.end, link, length); 189 | else 190 | match.length = (U32)length; 191 | 192 | match.dist = (U32)dist; 193 | 194 | return match; 195 | } 196 | } 197 | 198 | #if defined (__cplusplus) 199 | } 200 | #endif 201 | 202 | #endif /* FL2_RADIX_GET_H_ */ -------------------------------------------------------------------------------- /lzma2/radix_internal.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Conor McCarthy 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under both the BSD-style license (found in the 6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found 7 | * in the COPYING file in the root directory of this source tree). 8 | * You may select, at your option, one of the above-listed licenses. 9 | */ 10 | 11 | #ifndef RADIX_INTERNAL_H 12 | #define RADIX_INTERNAL_H 13 | 14 | #include "atomic.h" 15 | #include "radix_mf.h" 16 | 17 | #if defined(FL2_XZ_BUILD) && defined(TUKLIB_FAST_UNALIGNED_ACCESS) 18 | # define MEM_read32(a) (*(const U32*)(a)) 19 | #endif 20 | 21 | #if defined (__cplusplus) 22 | extern "C" { 23 | #endif 24 | 25 | #define DICTIONARY_LOG_MIN 12U 26 | #define DICTIONARY_LOG_MAX_64 30U 27 | #define DICTIONARY_LOG_MAX_32 27U 28 | #define DICTIONARY_SIZE_MIN ((size_t)1 << DICTIONARY_LOG_MIN) 29 | #define DICTIONARY_SIZE_MAX_64 ((size_t)1 << DICTIONARY_LOG_MAX_64) 30 | #define DICTIONARY_SIZE_MAX_32 ((size_t)1 << DICTIONARY_LOG_MAX_32) 31 | #define MAX_REPEAT 24 32 | #define RADIX16_TABLE_SIZE ((size_t)1 << 16) 33 | #define RADIX8_TABLE_SIZE ((size_t)1 << 8) 34 | #define STACK_SIZE (RADIX16_TABLE_SIZE * 3) 35 | #define MAX_BRUTE_FORCE_LIST_SIZE 5 36 | #define BUFFER_LINK_MASK 0xFFFFFFU 37 | #define MATCH_BUFFER_OVERLAP 6 38 | #define BITPACK_MAX_LENGTH 63U 39 | #define STRUCTURED_MAX_LENGTH 255U 40 | 41 | #define RADIX_LINK_BITS 26 42 | #define RADIX_LINK_MASK ((1U << RADIX_LINK_BITS) - 1) 43 | #define RADIX_NULL_LINK 0xFFFFFFFFU 44 | 45 | #define UNIT_BITS 2 46 | #define UNIT_MASK ((1U << UNIT_BITS) - 1) 47 | 48 | #define RADIX_CANCEL_INDEX (long)(RADIX16_TABLE_SIZE + FL2_MAXTHREADS + 2) 49 | 50 | typedef struct 51 | { 52 | U32 head; 53 | U32 count; 54 | } RMF_tableHead; 55 | 56 | union src_data_u { 57 | BYTE chars[4]; 58 | U32 u32; 59 | }; 60 | 61 | typedef struct 62 | { 63 | U32 from; 64 | union src_data_u src; 65 | U32 next; 66 | } RMF_buildMatch; 67 | 68 | typedef struct 69 | { 70 | U32 prev_index; 71 | U32 list_count; 72 | } RMF_listTail; 73 | 74 | typedef struct 75 | { 76 | U32 links[1 << UNIT_BITS]; 77 | BYTE lengths[1 << UNIT_BITS]; 78 | } RMF_unit; 79 | 80 | typedef struct 81 | { 82 | unsigned max_len; 83 | U32* table; 84 | size_t match_buffer_size; 85 | size_t match_buffer_limit; 86 | RMF_listTail tails_8[RADIX8_TABLE_SIZE]; 87 | RMF_tableHead stack[STACK_SIZE]; 88 | RMF_listTail tails_16[RADIX16_TABLE_SIZE]; 89 | RMF_buildMatch match_buffer[1]; 90 | } RMF_builder; 91 | 92 | struct FL2_matchTable_s 93 | { 94 | FL2_atomic st_index; 95 | long end_index; 96 | int is_struct; 97 | int alloc_struct; 98 | unsigned thread_count; 99 | size_t unreduced_dict_size; 100 | size_t progress; 101 | RMF_parameters params; 102 | RMF_builder** builders; 103 | U32 stack[RADIX16_TABLE_SIZE]; 104 | RMF_tableHead list_heads[RADIX16_TABLE_SIZE]; 105 | U32 table[1]; 106 | }; 107 | 108 | void RMF_bitpackInit(struct FL2_matchTable_s* const tbl, const void* data, size_t const end); 109 | void RMF_structuredInit(struct FL2_matchTable_s* const tbl, const void* data, size_t const end); 110 | void RMF_bitpackBuildTable(struct FL2_matchTable_s* const tbl, 111 | size_t const job, 112 | unsigned const multi_thread, 113 | FL2_dataBlock const block); 114 | void RMF_structuredBuildTable(struct FL2_matchTable_s* const tbl, 115 | size_t const job, 116 | unsigned const multi_thread, 117 | FL2_dataBlock const block); 118 | void RMF_recurseListChunk(RMF_builder* const tbl, 119 | const BYTE* const data_block, 120 | size_t const block_start, 121 | U32 const depth, 122 | U32 const max_depth, 123 | U32 const list_count, 124 | size_t const stack_base); 125 | int RMF_bitpackIntegrityCheck(const struct FL2_matchTable_s* const tbl, const BYTE* const data, size_t pos, size_t const end, unsigned max_depth); 126 | int RMF_structuredIntegrityCheck(const struct FL2_matchTable_s* const tbl, const BYTE* const data, size_t pos, size_t const end, unsigned max_depth); 127 | void RMF_bitpackLimitLengths(struct FL2_matchTable_s* const tbl, size_t const pos); 128 | void RMF_structuredLimitLengths(struct FL2_matchTable_s* const tbl, size_t const pos); 129 | BYTE* RMF_bitpackAsOutputBuffer(struct FL2_matchTable_s* const tbl, size_t const pos); 130 | BYTE* RMF_structuredAsOutputBuffer(struct FL2_matchTable_s* const tbl, size_t const pos); 131 | size_t RMF_bitpackGetMatch(const struct FL2_matchTable_s* const tbl, 132 | const BYTE* const data, 133 | size_t const pos, 134 | size_t const limit, 135 | unsigned const max_depth, 136 | size_t* const offset_ptr); 137 | size_t RMF_structuredGetMatch(const struct FL2_matchTable_s* const tbl, 138 | const BYTE* const data, 139 | size_t const pos, 140 | size_t const limit, 141 | unsigned const max_depth, 142 | size_t* const offset_ptr); 143 | 144 | #if defined (__cplusplus) 145 | } 146 | #endif 147 | 148 | #endif /* RADIX_INTERNAL_H */ -------------------------------------------------------------------------------- /lzma2/radix_mf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2018, Conor McCarthy 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under both the BSD-style license (found in the 6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found 7 | * in the COPYING file in the root directory of this source tree). 8 | * You may select, at your option, one of the above-listed licenses. 9 | */ 10 | 11 | #ifndef RADIX_MF_H 12 | #define RADIX_MF_H 13 | 14 | #include "fast-lzma2.h" 15 | #include "data_block.h" 16 | 17 | #if defined (__cplusplus) 18 | extern "C" { 19 | #endif 20 | 21 | typedef struct FL2_matchTable_s FL2_matchTable; 22 | 23 | #define OVERLAP_FROM_DICT_SIZE(d, o) (((d) >> 4) * (o)) 24 | 25 | #define RMF_MIN_BYTES_PER_THREAD 1024 26 | 27 | typedef struct 28 | { 29 | size_t dictionary_size; 30 | unsigned match_buffer_resize; 31 | unsigned overlap_fraction; 32 | unsigned divide_and_conquer; 33 | unsigned depth; 34 | #ifdef RMF_REFERENCE 35 | unsigned use_ref_mf; 36 | #endif 37 | } RMF_parameters; 38 | 39 | FL2_matchTable* RMF_createMatchTable(const RMF_parameters* const params, size_t const dict_reduce, unsigned const thread_count); 40 | void RMF_freeMatchTable(FL2_matchTable* const tbl); 41 | BYTE RMF_compatibleParameters(const FL2_matchTable* const tbl, const RMF_parameters* const params, size_t const dict_reduce); 42 | size_t RMF_applyParameters(FL2_matchTable* const tbl, const RMF_parameters* const params, size_t const dict_reduce); 43 | size_t RMF_threadCount(const FL2_matchTable * const tbl); 44 | void RMF_initProgress(FL2_matchTable * const tbl); 45 | void RMF_initTable(FL2_matchTable* const tbl, const void* const data, size_t const end); 46 | int RMF_buildTable(FL2_matchTable* const tbl, 47 | size_t const job, 48 | unsigned const multi_thread, 49 | FL2_dataBlock const block); 50 | void RMF_cancelBuild(FL2_matchTable* const tbl); 51 | void RMF_resetIncompleteBuild(FL2_matchTable* const tbl); 52 | int RMF_integrityCheck(const FL2_matchTable* const tbl, const BYTE* const data, size_t const pos, size_t const end, unsigned const max_depth); 53 | void RMF_limitLengths(FL2_matchTable* const tbl, size_t const pos); 54 | BYTE* RMF_getTableAsOutputBuffer(FL2_matchTable* const tbl, size_t const pos); 55 | size_t RMF_memoryUsage(size_t const dict_size, unsigned const buffer_resize, unsigned const thread_count); 56 | 57 | #if defined (__cplusplus) 58 | } 59 | #endif 60 | 61 | #endif /* RADIX_MF_H */ -------------------------------------------------------------------------------- /lzma2/range_enc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Bitwise range encoder by Igor Pavlov 3 | * Modified by Conor McCarthy 4 | * 5 | * Public domain 6 | */ 7 | 8 | #ifndef RANGE_ENCODER_H 9 | #define RANGE_ENCODER_H 10 | 11 | #include "mem.h" 12 | #include "compiler.h" 13 | 14 | #if defined (__cplusplus) 15 | extern "C" { 16 | #endif 17 | 18 | #ifdef LZMA_ENC_PROB32 19 | typedef U32 LZMA2_prob; 20 | #else 21 | typedef U16 LZMA2_prob; 22 | #endif 23 | 24 | #define kNumTopBits 24U 25 | #define kTopValue (1UL << kNumTopBits) 26 | #define kNumBitModelTotalBits 11U 27 | #define kBitModelTotal (1 << kNumBitModelTotalBits) 28 | #define kNumMoveBits 5U 29 | #define kProbInitValue (kBitModelTotal >> 1U) 30 | #define kNumMoveReducingBits 4U 31 | #define kNumBitPriceShiftBits 5U 32 | #define kPriceTableSize (kBitModelTotal >> kNumMoveReducingBits) 33 | 34 | extern BYTE price_table[2][kPriceTableSize]; 35 | #if 0 36 | void RC_printPriceTable(); 37 | #endif 38 | 39 | typedef struct 40 | { 41 | BYTE *out_buffer; 42 | size_t out_index; 43 | U64 cache_size; 44 | U64 low; 45 | U32 range; 46 | BYTE cache; 47 | } RC_encoder; 48 | 49 | void RC_reset(RC_encoder* const rc); 50 | 51 | void RC_setOutputBuffer(RC_encoder* const rc, BYTE *const out_buffer); 52 | 53 | void FORCE_NOINLINE RC_shiftLow(RC_encoder* const rc); 54 | 55 | void RC_encodeBitTree(RC_encoder* const rc, LZMA2_prob *const probs, unsigned bit_count, unsigned symbol); 56 | 57 | void RC_encodeBitTreeReverse(RC_encoder* const rc, LZMA2_prob *const probs, unsigned bit_count, unsigned symbol); 58 | 59 | void FORCE_NOINLINE RC_encodeDirect(RC_encoder* const rc, unsigned value, unsigned bit_count); 60 | 61 | HINT_INLINE 62 | void RC_encodeBit0(RC_encoder* const rc, LZMA2_prob *const rprob) 63 | { 64 | unsigned prob = *rprob; 65 | rc->range = (rc->range >> kNumBitModelTotalBits) * prob; 66 | prob += (kBitModelTotal - prob) >> kNumMoveBits; 67 | *rprob = (LZMA2_prob)prob; 68 | if (rc->range < kTopValue) { 69 | rc->range <<= 8; 70 | RC_shiftLow(rc); 71 | } 72 | } 73 | 74 | HINT_INLINE 75 | void RC_encodeBit1(RC_encoder* const rc, LZMA2_prob *const rprob) 76 | { 77 | unsigned prob = *rprob; 78 | U32 new_bound = (rc->range >> kNumBitModelTotalBits) * prob; 79 | rc->low += new_bound; 80 | rc->range -= new_bound; 81 | prob -= prob >> kNumMoveBits; 82 | *rprob = (LZMA2_prob)prob; 83 | if (rc->range < kTopValue) { 84 | rc->range <<= 8; 85 | RC_shiftLow(rc); 86 | } 87 | } 88 | 89 | HINT_INLINE 90 | void RC_encodeBit(RC_encoder* const rc, LZMA2_prob *const rprob, unsigned const bit) 91 | { 92 | unsigned prob = *rprob; 93 | if (bit != 0) { 94 | U32 const new_bound = (rc->range >> kNumBitModelTotalBits) * prob; 95 | rc->low += new_bound; 96 | rc->range -= new_bound; 97 | prob -= prob >> kNumMoveBits; 98 | } 99 | else { 100 | rc->range = (rc->range >> kNumBitModelTotalBits) * prob; 101 | prob += (kBitModelTotal - prob) >> kNumMoveBits; 102 | } 103 | *rprob = (LZMA2_prob)prob; 104 | if (rc->range < kTopValue) { 105 | rc->range <<= 8; 106 | RC_shiftLow(rc); 107 | } 108 | } 109 | 110 | #define GET_PRICE(prob, symbol) \ 111 | price_table[symbol][(prob) >> kNumMoveReducingBits] 112 | 113 | #define GET_PRICE_0(prob) price_table[0][(prob) >> kNumMoveReducingBits] 114 | 115 | #define GET_PRICE_1(prob) price_table[1][(prob) >> kNumMoveReducingBits] 116 | 117 | #define kMinLitPrice 8U 118 | 119 | HINT_INLINE 120 | unsigned RC_getTreePrice(const LZMA2_prob* const prob_table, unsigned bit_count, size_t symbol) 121 | { 122 | unsigned price = 0; 123 | symbol |= ((size_t)1 << bit_count); 124 | do { 125 | size_t const next_symbol = symbol >> 1; 126 | unsigned prob = prob_table[next_symbol]; 127 | size_t bit = symbol & 1; 128 | price += GET_PRICE(prob, bit); 129 | symbol = next_symbol; 130 | } while (symbol != 1); 131 | return price; 132 | } 133 | 134 | HINT_INLINE 135 | unsigned RC_getReverseTreePrice(const LZMA2_prob* const prob_table, unsigned bit_count, size_t symbol) 136 | { 137 | unsigned prob = prob_table[1]; 138 | size_t bit = symbol & 1; 139 | unsigned price = GET_PRICE(prob, bit); 140 | size_t m = 1; 141 | while (--bit_count != 0) { 142 | m = (m << 1) | bit; 143 | symbol >>= 1; 144 | prob = prob_table[m]; 145 | bit = symbol & 1; 146 | price += GET_PRICE(prob, bit); 147 | } 148 | return price; 149 | } 150 | 151 | HINT_INLINE 152 | void RC_flush(RC_encoder* const rc) 153 | { 154 | for (int i = 0; i < 5; ++i) 155 | RC_shiftLow(rc); 156 | } 157 | 158 | #if defined (__cplusplus) 159 | } 160 | #endif 161 | 162 | #endif /* RANGE_ENCODER_H */ -------------------------------------------------------------------------------- /lzma2/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016-present, Przemyslaw Skibinski, Yann Collet, Facebook, Inc. 3 | * All rights reserved. 4 | * 5 | * This source code is licensed under both the BSD-style license (found in the 6 | * LICENSE file in the root directory of this source tree) and the GPLv2 (found 7 | * in the COPYING file in the root directory of this source tree). 8 | * You may select, at your option, one of the above-listed licenses. 9 | */ 10 | 11 | #ifndef UTIL_H_MODULE 12 | #define UTIL_H_MODULE 13 | 14 | #if defined (__cplusplus) 15 | extern "C" { 16 | #endif 17 | 18 | 19 | /*-**************************************** 20 | * Dependencies 21 | ******************************************/ 22 | #include "platform.h" /* PLATFORM_POSIX_VERSION, ZSTD_NANOSLEEP_SUPPORT, ZSTD_SETPRIORITY_SUPPORT */ 23 | #include /* malloc, realloc, free */ 24 | #include /* size_t, ptrdiff_t */ 25 | #include /* fprintf */ 26 | #include /* stat, utime */ 27 | #include /* stat, chmod */ 28 | #if defined(_MSC_VER) 29 | # include /* utime */ 30 | # include /* _chmod */ 31 | #else 32 | # include /* chown, stat */ 33 | # include /* utime */ 34 | #endif 35 | #include /* clock_t, clock, CLOCKS_PER_SEC, nanosleep */ 36 | #include "mem.h" /* U32, U64 */ 37 | 38 | 39 | /*-************************************************************ 40 | * Avoid fseek()'s 2GiB barrier with MSVC, macOS, *BSD, MinGW 41 | ***************************************************************/ 42 | #if defined(_MSC_VER) && (_MSC_VER >= 1400) 43 | # define UTIL_fseek _fseeki64 44 | #elif !defined(__64BIT__) && (PLATFORM_POSIX_VERSION >= 200112L) /* No point defining Large file for 64 bit */ 45 | # define UTIL_fseek fseeko 46 | #elif defined(__MINGW32__) && defined(__MSVCRT__) && !defined(__STRICT_ANSI__) && !defined(__NO_MINGW_LFS) 47 | # define UTIL_fseek fseeko64 48 | #else 49 | # define UTIL_fseek fseek 50 | #endif 51 | 52 | 53 | /*-************************************************* 54 | * Sleep & priority functions: Windows - Posix - others 55 | ***************************************************/ 56 | #if defined(_WIN32) 57 | # include 58 | # define SET_REALTIME_PRIORITY SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS) 59 | # define UTIL_sleep(s) Sleep(1000*s) 60 | # define UTIL_sleepMilli(milli) Sleep(milli) 61 | 62 | #elif PLATFORM_POSIX_VERSION > 0 /* Unix-like operating system */ 63 | # include /* sleep */ 64 | # define UTIL_sleep(s) sleep(s) 65 | # if ZSTD_NANOSLEEP_SUPPORT /* necessarily defined in platform.h */ 66 | # define UTIL_sleepMilli(milli) { struct timespec t; t.tv_sec=0; t.tv_nsec=milli*1000000ULL; nanosleep(&t, NULL); } 67 | # else 68 | # define UTIL_sleepMilli(milli) /* disabled */ 69 | # endif 70 | # if ZSTD_SETPRIORITY_SUPPORT 71 | # include /* setpriority */ 72 | # define SET_REALTIME_PRIORITY setpriority(PRIO_PROCESS, 0, -20) 73 | # else 74 | # define SET_REALTIME_PRIORITY /* disabled */ 75 | # endif 76 | 77 | #else /* unknown non-unix operating systen */ 78 | # define UTIL_sleep(s) /* disabled */ 79 | # define UTIL_sleepMilli(milli) /* disabled */ 80 | # define SET_REALTIME_PRIORITY /* disabled */ 81 | #endif 82 | 83 | 84 | /*-************************************* 85 | * Constants 86 | ***************************************/ 87 | #define LIST_SIZE_INCREASE (8*1024) 88 | 89 | 90 | /*-**************************************** 91 | * Compiler specifics 92 | ******************************************/ 93 | #if defined(__INTEL_COMPILER) 94 | # pragma warning(disable : 177) /* disable: message #177: function was declared but never referenced, useful with UTIL_STATIC */ 95 | #endif 96 | #if defined(__GNUC__) 97 | # define UTIL_STATIC static __attribute__((unused)) 98 | #elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) 99 | # define UTIL_STATIC static inline 100 | #elif defined(_MSC_VER) 101 | # define UTIL_STATIC static __inline 102 | #else 103 | # define UTIL_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */ 104 | #endif 105 | 106 | 107 | /*-**************************************** 108 | * Console log 109 | ******************************************/ 110 | extern int g_utilDisplayLevel; 111 | #define UTIL_DISPLAY(...) fprintf(stderr, __VA_ARGS__) 112 | #define UTIL_DISPLAYLEVEL(l, ...) { if (g_utilDisplayLevel>=l) { UTIL_DISPLAY(__VA_ARGS__); } } 113 | 114 | 115 | /*-**************************************** 116 | * Time functions 117 | ******************************************/ 118 | #if defined(_WIN32) /* Windows */ 119 | 120 | #define UTIL_TIME_INITIALIZER { { 0, 0 } } 121 | typedef LARGE_INTEGER UTIL_time_t; 122 | 123 | #elif defined(__APPLE__) && defined(__MACH__) 124 | 125 | #include 126 | #define UTIL_TIME_INITIALIZER 0 127 | typedef U64 UTIL_time_t; 128 | 129 | #elif (PLATFORM_POSIX_VERSION >= 200112L) \ 130 | && (defined(__UCLIBC__) \ 131 | || (defined(__GLIBC__) \ 132 | && ((__GLIBC__ == 2 && __GLIBC_MINOR__ >= 17) \ 133 | || (__GLIBC__ > 2)))) 134 | 135 | #define UTIL_TIME_INITIALIZER { 0, 0 } 136 | typedef struct timespec UTIL_freq_t; 137 | typedef struct timespec UTIL_time_t; 138 | 139 | UTIL_time_t UTIL_getSpanTime(UTIL_time_t begin, UTIL_time_t end); 140 | 141 | #else /* relies on standard C (note : clock_t measurements can be wrong when using multi-threading) */ 142 | 143 | typedef clock_t UTIL_time_t; 144 | #define UTIL_TIME_INITIALIZER 0 145 | 146 | #endif 147 | 148 | UTIL_time_t UTIL_getTime(void); 149 | U64 UTIL_getSpanTimeMicro(UTIL_time_t clockStart, UTIL_time_t clockEnd); 150 | U64 UTIL_getSpanTimeNano(UTIL_time_t clockStart, UTIL_time_t clockEnd); 151 | 152 | #define SEC_TO_MICRO 1000000 153 | 154 | /* returns time span in microseconds */ 155 | U64 UTIL_clockSpanMicro(UTIL_time_t clockStart); 156 | 157 | /* returns time span in microseconds */ 158 | U64 UTIL_clockSpanNano(UTIL_time_t clockStart); 159 | void UTIL_waitForNextTick(void); 160 | 161 | /*-**************************************** 162 | * File functions 163 | ******************************************/ 164 | #if defined(_MSC_VER) 165 | #define chmod _chmod 166 | typedef struct __stat64 stat_t; 167 | #else 168 | typedef struct stat stat_t; 169 | #endif 170 | 171 | 172 | int UTIL_fileExist(const char* filename); 173 | int UTIL_isRegularFile(const char* infilename); 174 | int UTIL_setFileStat(const char* filename, stat_t* statbuf); 175 | U32 UTIL_isDirectory(const char* infilename); 176 | int UTIL_getFileStat(const char* infilename, stat_t* statbuf); 177 | 178 | U32 UTIL_isLink(const char* infilename); 179 | #define UTIL_FILESIZE_UNKNOWN ((U64)(-1)) 180 | U64 UTIL_getFileSize(const char* infilename); 181 | 182 | U64 UTIL_getTotalFileSize(const char* const * const fileNamesTable, unsigned nbFiles); 183 | 184 | /* 185 | * A modified version of realloc(). 186 | * If UTIL_realloc() fails the original block is freed. 187 | */ 188 | UTIL_STATIC void* UTIL_realloc(void *ptr, size_t size) 189 | { 190 | void *newptr = realloc(ptr, size); 191 | if (newptr) return newptr; 192 | free(ptr); 193 | return NULL; 194 | } 195 | 196 | int UTIL_prepareFileList(const char* dirName, char** bufStart, size_t* pos, char** bufEnd, int followLinks); 197 | #ifdef _WIN32 198 | # define UTIL_HAS_CREATEFILELIST 199 | #elif defined(__linux__) || (PLATFORM_POSIX_VERSION >= 200112L) /* opendir, readdir require POSIX.1-2001 */ 200 | # define UTIL_HAS_CREATEFILELIST 201 | # include /* opendir, readdir */ 202 | # include /* strerror, memcpy */ 203 | #else 204 | #endif /* #ifdef _WIN32 */ 205 | 206 | /* 207 | * UTIL_createFileList - takes a list of files and directories (params: inputNames, inputNamesNb), scans directories, 208 | * and returns a new list of files (params: return value, allocatedBuffer, allocatedNamesNb). 209 | * After finishing usage of the list the structures should be freed with UTIL_freeFileList(params: return value, allocatedBuffer) 210 | * In case of error UTIL_createFileList returns NULL and UTIL_freeFileList should not be called. 211 | */ 212 | const char** 213 | UTIL_createFileList(const char **inputNames, unsigned inputNamesNb, 214 | char** allocatedBuffer, unsigned* allocatedNamesNb, 215 | int followLinks); 216 | 217 | UTIL_STATIC void UTIL_freeFileList(const char** filenameTable, char* allocatedBuffer) 218 | { 219 | if (allocatedBuffer) free(allocatedBuffer); 220 | if (filenameTable) free((void*)filenameTable); 221 | } 222 | 223 | int UTIL_countPhysicalCores(void); 224 | 225 | #if defined (__cplusplus) 226 | } 227 | #endif 228 | 229 | #endif /* UTIL_H_MODULE */ 230 | -------------------------------------------------------------------------------- /lzma2/xxhash.h: -------------------------------------------------------------------------------- 1 | /* 2 | xxHash - Extremely Fast Hash algorithm 3 | Header File 4 | Copyright (C) 2012-2016, Yann Collet. 5 | 6 | BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php) 7 | 8 | Redistribution and use in source and binary forms, with or without 9 | modification, are permitted provided that the following conditions are 10 | met: 11 | 12 | * Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | * Redistributions in binary form must reproduce the above 15 | copyright notice, this list of conditions and the following disclaimer 16 | in the documentation and/or other materials provided with the 17 | distribution. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | 31 | You can contact the author at : 32 | - xxHash source repository : https://github.com/Cyan4973/xxHash 33 | */ 34 | 35 | /* Notice extracted from xxHash homepage : 36 | 37 | xxHash is an extremely fast Hash algorithm, running at RAM speed limits. 38 | It also successfully passes all tests from the SMHasher suite. 39 | 40 | Comparison (single thread, Windows Seven 32 bits, using SMHasher on a Core 2 Duo @3GHz) 41 | 42 | Name Speed Q.Score Author 43 | xxHash 5.4 GB/s 10 44 | CrapWow 3.2 GB/s 2 Andrew 45 | MumurHash 3a 2.7 GB/s 10 Austin Appleby 46 | SpookyHash 2.0 GB/s 10 Bob Jenkins 47 | SBox 1.4 GB/s 9 Bret Mulvey 48 | Lookup3 1.2 GB/s 9 Bob Jenkins 49 | SuperFastHash 1.2 GB/s 1 Paul Hsieh 50 | CityHash64 1.05 GB/s 10 Pike & Alakuijala 51 | FNV 0.55 GB/s 5 Fowler, Noll, Vo 52 | CRC32 0.43 GB/s 9 53 | MD5-32 0.33 GB/s 10 Ronald L. Rivest 54 | SHA1-32 0.28 GB/s 10 55 | 56 | Q.Score is a measure of quality of the hash function. 57 | It depends on successfully passing SMHasher test set. 58 | 10 is a perfect score. 59 | 60 | A 64-bits version, named XXH64, is available since r35. 61 | It offers much better speed, but for 64-bits applications only. 62 | Name Speed on 64 bits Speed on 32 bits 63 | XXH64 13.8 GB/s 1.9 GB/s 64 | XXH32 6.8 GB/s 6.0 GB/s 65 | */ 66 | 67 | #if defined (__cplusplus) 68 | extern "C" { 69 | #endif 70 | 71 | #ifndef XXHASH_H_5627135585666179 72 | #define XXHASH_H_5627135585666179 1 73 | 74 | 75 | /* **************************** 76 | * Definitions 77 | ******************************/ 78 | #include /* size_t */ 79 | typedef enum { XXH_OK=0, XXH_ERROR } XXH_errorcode; 80 | 81 | 82 | /* **************************** 83 | * API modifier 84 | ******************************/ 85 | /** XXH_PRIVATE_API 86 | * This is useful if you want to include xxhash functions in `static` mode 87 | * in order to inline them, and remove their symbol from the public list. 88 | * Methodology : 89 | * #define XXH_PRIVATE_API 90 | * #include "xxhash.h" 91 | * `xxhash.c` is automatically included. 92 | * It's not useful to compile and link it as a separate module anymore. 93 | */ 94 | #ifdef XXH_PRIVATE_API 95 | # ifndef XXH_STATIC_LINKING_ONLY 96 | # define XXH_STATIC_LINKING_ONLY 97 | # endif 98 | # if defined(__GNUC__) 99 | # define XXH_PUBLIC_API static __inline __attribute__((unused)) 100 | # elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */) 101 | # define XXH_PUBLIC_API static inline 102 | # elif defined(_MSC_VER) 103 | # define XXH_PUBLIC_API static __inline 104 | # else 105 | # define XXH_PUBLIC_API static /* this version may generate warnings for unused static functions; disable the relevant warning */ 106 | # endif 107 | #else 108 | # define XXH_PUBLIC_API /* do nothing */ 109 | #endif /* XXH_PRIVATE_API */ 110 | 111 | /*!XXH_NAMESPACE, aka Namespace Emulation : 112 | 113 | If you want to include _and expose_ xxHash functions from within your own library, 114 | but also want to avoid symbol collisions with another library which also includes xxHash, 115 | 116 | you can use XXH_NAMESPACE, to automatically prefix any public symbol from xxhash library 117 | with the value of XXH_NAMESPACE (so avoid to keep it NULL and avoid numeric values). 118 | 119 | Note that no change is required within the calling program as long as it includes `xxhash.h` : 120 | regular symbol name will be automatically translated by this header. 121 | */ 122 | #ifdef XXH_NAMESPACE 123 | # define XXH_CAT(A,B) A##B 124 | # define XXH_NAME2(A,B) XXH_CAT(A,B) 125 | # define XXH32 XXH_NAME2(XXH_NAMESPACE, XXH32) 126 | # define XXH64 XXH_NAME2(XXH_NAMESPACE, XXH64) 127 | # define XXH_versionNumber XXH_NAME2(XXH_NAMESPACE, XXH_versionNumber) 128 | # define XXH32_createState XXH_NAME2(XXH_NAMESPACE, XXH32_createState) 129 | # define XXH64_createState XXH_NAME2(XXH_NAMESPACE, XXH64_createState) 130 | # define XXH32_freeState XXH_NAME2(XXH_NAMESPACE, XXH32_freeState) 131 | # define XXH64_freeState XXH_NAME2(XXH_NAMESPACE, XXH64_freeState) 132 | # define XXH32_reset XXH_NAME2(XXH_NAMESPACE, XXH32_reset) 133 | # define XXH64_reset XXH_NAME2(XXH_NAMESPACE, XXH64_reset) 134 | # define XXH32_update XXH_NAME2(XXH_NAMESPACE, XXH32_update) 135 | # define XXH64_update XXH_NAME2(XXH_NAMESPACE, XXH64_update) 136 | # define XXH32_digest XXH_NAME2(XXH_NAMESPACE, XXH32_digest) 137 | # define XXH64_digest XXH_NAME2(XXH_NAMESPACE, XXH64_digest) 138 | # define XXH32_copyState XXH_NAME2(XXH_NAMESPACE, XXH32_copyState) 139 | # define XXH64_copyState XXH_NAME2(XXH_NAMESPACE, XXH64_copyState) 140 | # define XXH32_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH32_canonicalFromHash) 141 | # define XXH64_canonicalFromHash XXH_NAME2(XXH_NAMESPACE, XXH64_canonicalFromHash) 142 | # define XXH32_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH32_hashFromCanonical) 143 | # define XXH64_hashFromCanonical XXH_NAME2(XXH_NAMESPACE, XXH64_hashFromCanonical) 144 | #endif 145 | 146 | 147 | /* ************************************* 148 | * Version 149 | ***************************************/ 150 | #define XXH_VERSION_MAJOR 0 151 | #define XXH_VERSION_MINOR 6 152 | #define XXH_VERSION_RELEASE 2 153 | #define XXH_VERSION_NUMBER (XXH_VERSION_MAJOR *100*100 + XXH_VERSION_MINOR *100 + XXH_VERSION_RELEASE) 154 | XXH_PUBLIC_API unsigned XXH_versionNumber (void); 155 | 156 | 157 | /* **************************** 158 | * Simple Hash Functions 159 | ******************************/ 160 | typedef unsigned int XXH32_hash_t; 161 | typedef unsigned long long XXH64_hash_t; 162 | 163 | XXH_PUBLIC_API XXH32_hash_t XXH32 (const void* input, size_t length, unsigned int seed); 164 | XXH_PUBLIC_API XXH64_hash_t XXH64 (const void* input, size_t length, unsigned long long seed); 165 | 166 | /*! 167 | XXH32() : 168 | Calculate the 32-bits hash of sequence "length" bytes stored at memory address "input". 169 | The memory between input & input+length must be valid (allocated and read-accessible). 170 | "seed" can be used to alter the result predictably. 171 | Speed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s 172 | XXH64() : 173 | Calculate the 64-bits hash of sequence of length "len" stored at memory address "input". 174 | "seed" can be used to alter the result predictably. 175 | This function runs 2x faster on 64-bits systems, but slower on 32-bits systems (see benchmark). 176 | */ 177 | 178 | 179 | /* **************************** 180 | * Streaming Hash Functions 181 | ******************************/ 182 | typedef struct XXH32_state_s XXH32_state_t; /* incomplete type */ 183 | typedef struct XXH64_state_s XXH64_state_t; /* incomplete type */ 184 | 185 | /*! State allocation, compatible with dynamic libraries */ 186 | 187 | XXH_PUBLIC_API XXH32_state_t* XXH32_createState(void); 188 | XXH_PUBLIC_API XXH_errorcode XXH32_freeState(XXH32_state_t* statePtr); 189 | 190 | XXH_PUBLIC_API XXH64_state_t* XXH64_createState(void); 191 | XXH_PUBLIC_API XXH_errorcode XXH64_freeState(XXH64_state_t* statePtr); 192 | 193 | 194 | /* hash streaming */ 195 | 196 | XXH_PUBLIC_API XXH_errorcode XXH32_reset (XXH32_state_t* statePtr, unsigned int seed); 197 | XXH_PUBLIC_API XXH_errorcode XXH32_update (XXH32_state_t* statePtr, const void* input, size_t length); 198 | XXH_PUBLIC_API XXH32_hash_t XXH32_digest (const XXH32_state_t* statePtr); 199 | 200 | XXH_PUBLIC_API XXH_errorcode XXH64_reset (XXH64_state_t* statePtr, unsigned long long seed); 201 | XXH_PUBLIC_API XXH_errorcode XXH64_update (XXH64_state_t* statePtr, const void* input, size_t length); 202 | XXH_PUBLIC_API XXH64_hash_t XXH64_digest (const XXH64_state_t* statePtr); 203 | 204 | /* 205 | These functions generate the xxHash of an input provided in multiple segments. 206 | Note that, for small input, they are slower than single-call functions, due to state management. 207 | For small input, prefer `XXH32()` and `XXH64()` . 208 | 209 | XXH state must first be allocated, using XXH*_createState() . 210 | 211 | Start a new hash by initializing state with a seed, using XXH*_reset(). 212 | 213 | Then, feed the hash state by calling XXH*_update() as many times as necessary. 214 | Obviously, input must be allocated and read accessible. 215 | The function returns an error code, with 0 meaning OK, and any other value meaning there is an error. 216 | 217 | Finally, a hash value can be produced anytime, by using XXH*_digest(). 218 | This function returns the nn-bits hash as an int or long long. 219 | 220 | It's still possible to continue inserting input into the hash state after a digest, 221 | and generate some new hashes later on, by calling again XXH*_digest(). 222 | 223 | When done, free XXH state space if it was allocated dynamically. 224 | */ 225 | 226 | 227 | /* ************************** 228 | * Utils 229 | ****************************/ 230 | #if !(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) /* ! C99 */ 231 | # define restrict /* disable restrict */ 232 | #endif 233 | 234 | XXH_PUBLIC_API void XXH32_copyState(XXH32_state_t* restrict dst_state, const XXH32_state_t* restrict src_state); 235 | XXH_PUBLIC_API void XXH64_copyState(XXH64_state_t* restrict dst_state, const XXH64_state_t* restrict src_state); 236 | 237 | 238 | /* ************************** 239 | * Canonical representation 240 | ****************************/ 241 | /* Default result type for XXH functions are primitive unsigned 32 and 64 bits. 242 | * The canonical representation uses human-readable write convention, aka big-endian (large digits first). 243 | * These functions allow transformation of hash result into and from its canonical format. 244 | * This way, hash values can be written into a file / memory, and remain comparable on different systems and programs. 245 | */ 246 | typedef struct { unsigned char digest[4]; } XXH32_canonical_t; 247 | typedef struct { unsigned char digest[8]; } XXH64_canonical_t; 248 | 249 | XXH_PUBLIC_API void XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t hash); 250 | XXH_PUBLIC_API void XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t hash); 251 | 252 | XXH_PUBLIC_API XXH32_hash_t XXH32_hashFromCanonical(const XXH32_canonical_t* src); 253 | XXH_PUBLIC_API XXH64_hash_t XXH64_hashFromCanonical(const XXH64_canonical_t* src); 254 | 255 | #endif /* XXHASH_H_5627135585666179 */ 256 | 257 | 258 | 259 | /* ================================================================================================ 260 | This section contains definitions which are not guaranteed to remain stable. 261 | They may change in future versions, becoming incompatible with a different version of the library. 262 | They shall only be used with static linking. 263 | Never use these definitions in association with dynamic linking ! 264 | =================================================================================================== */ 265 | #if defined(XXH_STATIC_LINKING_ONLY) && !defined(XXH_STATIC_H_3543687687345) 266 | #define XXH_STATIC_H_3543687687345 267 | 268 | /* These definitions are only meant to allow allocation of XXH state 269 | statically, on stack, or in a struct for example. 270 | Do not use members directly. */ 271 | 272 | struct XXH32_state_s { 273 | unsigned total_len_32; 274 | unsigned large_len; 275 | unsigned v1; 276 | unsigned v2; 277 | unsigned v3; 278 | unsigned v4; 279 | unsigned mem32[4]; /* buffer defined as U32 for alignment */ 280 | unsigned memsize; 281 | unsigned reserved; /* never read nor write, will be removed in a future version */ 282 | }; /* typedef'd to XXH32_state_t */ 283 | 284 | struct XXH64_state_s { 285 | unsigned long long total_len; 286 | unsigned long long v1; 287 | unsigned long long v2; 288 | unsigned long long v3; 289 | unsigned long long v4; 290 | unsigned long long mem64[4]; /* buffer defined as U64 for alignment */ 291 | unsigned memsize; 292 | unsigned reserved[2]; /* never read nor write, will be removed in a future version */ 293 | }; /* typedef'd to XXH64_state_t */ 294 | 295 | 296 | # ifdef XXH_PRIVATE_API 297 | # include "xxhash.c" /* include xxhash functions as `static`, for inlining */ 298 | # endif 299 | 300 | #endif /* XXH_STATIC_LINKING_ONLY && XXH_STATIC_H_3543687687345 */ 301 | 302 | 303 | #if defined (__cplusplus) 304 | } 305 | #endif 306 | -------------------------------------------------------------------------------- /mmLoader.h: -------------------------------------------------------------------------------- 1 | #ifndef __MMLOADER_H_INCLUDED_ 2 | #define __MMLOADER_H_INCLUDED_ 3 | #pragma once 4 | #include 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | #define MMEC_OK 0 11 | #define MMEC_BAD_PE_FORMAT 1 12 | #define MMEC_ALLOCATED_MEMORY_FAILED 2 13 | #define MMEC_INVALID_RELOCATION_BASE 3 14 | #define MMEC_IMPORT_MODULE_FAILED 4 15 | #define MMEC_PROTECT_SECTION_FAILED 5 16 | #define MMEC_INVALID_ENTRY_POINT 6 17 | #define MMEC_INVALID_WIN32_ENV 0xff 18 | 19 | typedef enum _MMHELPER_METHOD { 20 | MHM_BOOL_LOAD, 21 | MHM_VOID_FREE, 22 | MHM_FARPROC_GETPROC, 23 | } MMHELPER_METHOD; 24 | 25 | typedef void **HMEMMODULE; 26 | typedef LPVOID(__stdcall *Type_MemModuleHelper)(MMHELPER_METHOD, LPVOID, LPVOID, LPVOID); 27 | LPVOID MemModuleHelper(_In_ MMHELPER_METHOD method, _In_ LPVOID lpArg1, _In_ LPVOID lpArg2, _In_ LPVOID lpArg3); 28 | HMEMMODULE LoadMemModule(_In_ LPVOID lpPeModuleBuffer, _In_ BOOL bCallEntry, _Inout_ DWORD *pdwError); 29 | FARPROC GetMemModuleProc(_In_ HMEMMODULE MemModuleHandle, _In_ LPCSTR lpName); 30 | VOID FreeMemModule(_In_ HMEMMODULE MemModuleHandle); 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /packer.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheAenema/hm-pe-packer/f16942ca4c1397150b7a76941bbd59ae252b7293/packer.cpp -------------------------------------------------------------------------------- /packer.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Release 6 | x64 7 | 8 | 9 | 10 | 16.0 11 | {EBCBD031-6C18-4CB1-AB09-C1E011FD6C04} 12 | PE.Packer 13 | 10.0 14 | pe_packer 15 | 16 | 17 | 18 | Application 19 | false 20 | v142 21 | true 22 | MultiByte 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | .\win64\ 35 | .\win64\temp\packer 36 | 37 | 38 | 39 | TurnOffAllWarnings 40 | MaxSpeed 41 | true 42 | true 43 | true 44 | MultiThreaded 45 | None 46 | 47 | 48 | Console 49 | true 50 | true 51 | 52 | 53 | false 54 | /EMITPOGOPHASEINFO %(AdditionalOptions) 55 | utilities\hmrclib64_vc16.lib;%(AdditionalDependencies) 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /packer.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /pe_packer_tutorial.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29503.13 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pe_packer", "packer.vcxproj", "{EBCBD031-6C18-4CB1-AB09-C1E011FD6C04}" 7 | EndProject 8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "unpacker_stub", "unpacker_stub.vcxproj", "{28BF484E-64B9-4F96-9621-79248E5EB595}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Default|Win64 = Default|Win64 13 | EndGlobalSection 14 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 15 | {EBCBD031-6C18-4CB1-AB09-C1E011FD6C04}.Default|Win64.ActiveCfg = Release|x64 16 | {EBCBD031-6C18-4CB1-AB09-C1E011FD6C04}.Default|Win64.Build.0 = Release|x64 17 | {28BF484E-64B9-4F96-9621-79248E5EB595}.Default|Win64.ActiveCfg = Release|x64 18 | {28BF484E-64B9-4F96-9621-79248E5EB595}.Default|Win64.Build.0 = Release|x64 19 | EndGlobalSection 20 | GlobalSection(SolutionProperties) = preSolution 21 | HideSolutionNode = FALSE 22 | EndGlobalSection 23 | GlobalSection(ExtensibilityGlobals) = postSolution 24 | SolutionGuid = {BBE25931-87DD-45A3-B9EA-F37A09723CA0} 25 | EndGlobalSection 26 | EndGlobal 27 | -------------------------------------------------------------------------------- /resolvers/kernel32.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheAenema/hm-pe-packer/f16942ca4c1397150b7a76941bbd59ae252b7293/resolvers/kernel32.lib -------------------------------------------------------------------------------- /resolvers/msvcrt.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheAenema/hm-pe-packer/f16942ca4c1397150b7a76941bbd59ae252b7293/resolvers/msvcrt.lib -------------------------------------------------------------------------------- /unpacker.cpp: -------------------------------------------------------------------------------- 1 | // Dev : Hamid.Memar 2 | 3 | // WinAPI Functions 4 | #include 5 | #include 6 | EXTERN_C IMAGE_DOS_HEADER __ImageBase; 7 | 8 | // Resolvers Functions 9 | EXTERN_C void crt_init(); 10 | EXTERN_C void k32_init(); 11 | 12 | // Encryption Library 13 | extern "C" 14 | { 15 | #include "aes.h" 16 | } 17 | 18 | // Compression Library 19 | #include "lzma2\fast-lzma2.h" 20 | 21 | // PE Loader Library 22 | #include "mmLoader.h" 23 | 24 | // Merge Data With Code 25 | #pragma comment(linker, "/merge:.rdata=.text") 26 | #pragma comment(linker, "/merge:.data=.text") 27 | 28 | // Cross Section Value 29 | EXTERN_C static volatile uintptr_t moduleImageBase = 0xBCEAEFBA; 30 | EXTERN_C static volatile FARPROC functionForwardingPtr = (FARPROC)0xCAFEBABE; 31 | 32 | // External Functions 33 | EXTERN_C BOOL CallModuleEntry(void* pMemModule_d, DWORD dwReason); 34 | 35 | // Multi-Accessing Values 36 | HMEMMODULE pe_module = 0; 37 | 38 | // Entrypoint (EXE/DLL) 39 | BOOL func_unpack(void*, int reason, void*) 40 | { 41 | // Releasing DLL PE Module 42 | if (reason == DLL_PROCESS_DETACH) 43 | { 44 | CallModuleEntry(pe_module, DLL_PROCESS_DETACH); FreeMemModule(pe_module); return TRUE; 45 | }; 46 | 47 | // Handling DLL Thread Events 48 | if (reason == DLL_THREAD_ATTACH) return CallModuleEntry(pe_module, DLL_THREAD_ATTACH); 49 | if (reason == DLL_THREAD_DETACH) return CallModuleEntry(pe_module, DLL_THREAD_DETACH); 50 | 51 | // Internal Data [ Signatures ] 52 | volatile PVOID data_ptr = (void*)0xAABBCCDD; 53 | volatile DWORD data_size = 0xEEFFAADD; 54 | volatile DWORD actual_data_size = 0xA0B0C0D0; 55 | volatile DWORD header_size = 0xF0E0D0A0; 56 | 57 | // Initializing Resolvers 58 | k32_init(); crt_init(); 59 | 60 | // Getting BaseAddress of Module 61 | intptr_t imageBase = (intptr_t)&__ImageBase; 62 | data_ptr = (void*)((intptr_t)data_ptr + imageBase); 63 | 64 | // Initializing Cryptor 65 | struct AES_ctx ctx; 66 | const unsigned char key[32] = { 67 | 0xD6, 0x23, 0xB8, 0xEF, 0x62, 0x26, 0xCE, 0xC3, 0xE2, 0x4C, 0x55, 0x12, 68 | 0x7D, 0xE8, 0x73, 0xE7, 0x83, 0x9C, 0x77, 0x6B, 0xB1, 0xA9, 0x3B, 0x57, 69 | 0xB2, 0x5F, 0xDB, 0xEA, 0x0D, 0xB6, 0x8E, 0xA2 70 | }; 71 | const unsigned char iv[16] = { 72 | 0x18, 0x42, 0x31, 0x2D, 0xFC, 0xEF, 0xDA, 0xB6, 0xB9, 0x49, 0xF1, 0x0D, 73 | 0x03, 0x7E, 0x7E, 0xBD 74 | }; 75 | AES_init_ctx_iv(&ctx, key, iv); 76 | 77 | // Casting PVOID to BYTE 78 | uint8_t* data_ptr_byte = (uint8_t*)data_ptr; 79 | 80 | // Decrypting Buffer 81 | AES_CBC_decrypt_buffer(&ctx, data_ptr_byte, data_size); 82 | 83 | // Allocating Code Buffer 84 | uint8_t* code_buffer = (uint8_t*)malloc(actual_data_size); 85 | 86 | // Decompressing Buffer 87 | FL2_decompress(code_buffer, actual_data_size, &data_ptr_byte[16], data_size - 32); 88 | memset(data_ptr, 0, data_size); 89 | 90 | // Loading PE Module 91 | DWORD pe_loader_result = 0; 92 | pe_module = LoadMemModule(code_buffer, false, &pe_loader_result); 93 | 94 | // Set Image Base 95 | moduleImageBase = (uintptr_t)*pe_module; 96 | functionForwardingPtr = 0; 97 | 98 | // Call Entrypoint 99 | return CallModuleEntry(pe_module, DLL_PROCESS_ATTACH); 100 | } -------------------------------------------------------------------------------- /unpacker_stub.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Release 6 | x64 7 | 8 | 9 | 10 | 16.0 11 | {28BF484E-64B9-4F96-9621-79248E5EB595} 12 | unpacker_stub 13 | 10.0 14 | unpacker_stub 15 | 16 | 17 | 18 | Application 19 | false 20 | v142 21 | false 22 | NotSet 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | .\win64\ 35 | .\win64\temp\unpacker\ 36 | false 37 | 38 | 39 | true 40 | 41 | 42 | 43 | TurnOffAllWarnings 44 | true 45 | false 46 | MultiThreaded 47 | stdcpp17 48 | None 49 | false 50 | false 51 | false 52 | AnySuitable 53 | true 54 | Speed 55 | true 56 | true 57 | true 58 | 6011;6387 59 | .\resolvers\headers 60 | 61 | 62 | Console 63 | true 64 | false 65 | msvcrt.lib;kernel32.lib;.\lzma2\fast-lzma2.lib 66 | true 67 | false 68 | true 69 | func_unpack 70 | /EMITPOGOPHASEINFO /SECTION:.text,EWR %(AdditionalOptions) 71 | false 72 | 73 | 74 | .\resolvers 75 | true 76 | false 77 | Default 78 | false 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /utilities/hmrclib64_vc16.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheAenema/hm-pe-packer/f16942ca4c1397150b7a76941bbd59ae252b7293/utilities/hmrclib64_vc16.lib -------------------------------------------------------------------------------- /win64/app.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheAenema/hm-pe-packer/f16942ca4c1397150b7a76941bbd59ae252b7293/win64/app.ico -------------------------------------------------------------------------------- /win64/dll/input_pe.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheAenema/hm-pe-packer/f16942ca4c1397150b7a76941bbd59ae252b7293/win64/dll/input_pe.dll -------------------------------------------------------------------------------- /win64/dll/pe_dll_tester.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheAenema/hm-pe-packer/f16942ca4c1397150b7a76941bbd59ae252b7293/win64/dll/pe_dll_tester.exe -------------------------------------------------------------------------------- /win64/exe/input_pe.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheAenema/hm-pe-packer/f16942ca4c1397150b7a76941bbd59ae252b7293/win64/exe/input_pe.exe -------------------------------------------------------------------------------- /win64/pe_packer_test_dll.bat: -------------------------------------------------------------------------------- 1 | "%cd%\pe_packer.exe" "%cd%\dll\input_pe.dll" "%cd%\dll\output_pe.dll" 2 | pause -------------------------------------------------------------------------------- /win64/pe_packer_test_exe.bat: -------------------------------------------------------------------------------- 1 | "%cd%\pe_packer.exe" "%cd%\exe\input_pe.exe" "%cd%\exe\output_pe.exe" 2 | pause -------------------------------------------------------------------------------- /win64/pe_packer_test_self.bat: -------------------------------------------------------------------------------- 1 | "%cd%\pe_packer.exe" "%cd%\pe_packer.exe" "%cd%\hm_pe_packer.exe" 2 | pause --------------------------------------------------------------------------------