Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define N 4096
- #define F 18
- #define THRESHOLD 2
- #define GETBYTE() ((dwInputCurrent < dwInputLength) ? buffer[dwInputCurrent++] & 0x00FF : 0xffff)
- /* Special thanks to Anchorite from TeamX.ru */
- void LZSSDecode(char* buffer, int dwInputLength, char* arOut) {
- uint16_t i;
- uint16_t j;
- uint16_t k;
- int16_t c;
- int dictionaryIndex = N - F;
- unsigned int flags = 0;
- int dwInputCurrent = 0;
- int dwOutputIndex = 0;
- char * text_buf = malloc(N+F-1);
- memset(text_buf,' ',dictionaryIndex);
- for ( ; ; ) {
- if (((flags >>= 1) & 256) == 0) {
- if ((c = GETBYTE()) == 0xffff) break;
- flags = c | 0xff00; /* uses higher byte to count 8 */
- }
- if (flags & 1) {
- if ((c = GETBYTE()) == 0xffff) break;
- // arOut[dwOutputIndex++] = c;
- dwOutputIndex++;
- text_buf[dictionaryIndex++] = c;
- dictionaryIndex &= (N - 1);
- }
- else {
- if ((i = GETBYTE()) == 0xffff) break;
- if ((j = GETBYTE()) == 0xffff) break;
- i |= ((j & 0xf0) << 4);
- j = (j & 0x0f) + THRESHOLD;
- for (k = 0; k <= j; k++) {
- c = text_buf[(i + k) & (N - 1)];
- // arOut[dwOutputIndex++] = c;
- dwOutputIndex++;
- text_buf[dictionaryIndex++] = c;
- dictionaryIndex &= (N - 1);
- }
- }
- }
- printf("Output would be %i\n",dwOutputIndex);
- free(text_buf);
- }
Advertisement
Add Comment
Please, Sign In to add comment