⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lzf.c

📁 twocrypt(2c)是一个 PoC工具
💻 C
字号:
/*   lzf.c - fast compression and decompression support   --------------------------------------------------   Extremely fast and surprisingly robust block compression by Marc   Alexander Lehmann, adopted and simplified for 2c. I've fixed some    things in the code, including one bug.   Original copyright follows:   -- snip! --   Copyright (c) 2000-2002 Marc Alexander Lehmann <pcg@goof.com>     Redistribution and use in source and binary forms, with or without    modification, are permitted provided that the following conditions are    met:   1.  Redistributions of source code must retain the above copyright notice,       this list of conditions and the following disclaimer.    2.  Redistributions in binary form must reproduce the above copyright       notice, this list of conditions and the following disclaimer in the       documentation and/or other materials provided with the distribution.   3.  The name of the author may not be used to endorse or promote products       derived from this software without specific prior written permission.   THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR    IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES    OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;   OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,   WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR    OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF    ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include "macros.h"#include "lzf.h"_u32 lzf (const _u8* in, _u32 ilen, _u8* out, _u32 olen) {  _u8 *htab[1<<HLOG], **hslot, *ip = (_u8*)in, *op = out,                *iend  = ip + ilen, *oend = op + olen, *ref;  _u32 hval = (ip[0] << 8) + ip[1], off;  _s32 lit = 0;  do {    hval   = ( hval << 8 ) + (ip + 2 < iend) ? ip[2] : 0;    hslot  = htab + IDX (hval);    ref    = *hslot;     *hslot = ip;    if ((off = ip - ref - 1) < MAX_OFF && ip + 4 < iend &&          ref > in && *(_u16*)ref == *(_u16*)ip &&          ref[2] == ip[2] ) {      _u32 len = 2;      _u32 maxlen = iend - ip - len;       maxlen = maxlen > MAX_REF ? MAX_REF : maxlen;      do len++; while (len < maxlen && ref[len] == ip[len]);      if (op + lit + 1 + 3 >= oend) return 0;      if (lit) {        *op++ = lit - 1;        lit = -lit;         do *op++ = ip[lit]; while (++lit);      }      len -= 2;      ip++;      if (len < 7) {        *op++ = (off >> 8) + (len << 5);      } else {        *op++ = (off >> 8) + (  7 << 5);        *op++ = len - 7;      }      *op++ = off;      ip += len;      hval = ( ip[0] << 8 ) + ip[1];      hval = ( hval << 8 ) + ip[2];      htab[IDX (hval)] = ip;      ip++;    } else {      lit++;      ip++;      if (lit == MAX_LIT) {        if (op + 1 + MAX_LIT >= oend) return 0;        *op++ = MAX_LIT - 1;        lit = -lit;        do *op++ = ip[lit]; while (++lit);      }    }  } while (ip < iend);  if (lit) {    if (op + lit + 1 >= oend) return 0;    *op++ = lit - 1;    lit = -lit;    do *op++ = ip[lit]; while (++lit);  }  return op - out;}_u32 unlzf (const _u8* in, _u32 ilen, _u8* out,_u32 olen) {  _u8 *op = out, *iend = (_u8*)in + ilen, *oend = out + olen;  do {    _u32 ctrl = *in++;    if (ctrl < (1 << 5)) {      ctrl++;      if (op + ctrl > oend)        fatal("[-] Decompression: file corrupted 1 (bad password?)..\n");      do *op++ = *in++; while (--ctrl);    } else {      _u32 len   = ctrl >> 5;      _u8 *ref = op - ((ctrl & 0x1f) << 8) - 1;      if (len == 7) len += *in++;                ref -= *in++;      if (op + len + 2 > oend)        fatal("[-] Decompression: file corrupted 2 (bad password?).\n");      if (ref < out)        fatal("[-] Decompression: file corrupted 3 (bad password?).\n");      *op++ = *ref++;      *op++ = *ref++;      do *op++ = *ref++; while (--len);    }  }  while (op < oend && in < iend);  return op - out;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -