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

📄 tinfgzip.c

📁 Boot code for ADM5120 with serial console for Edimax router.
💻 C
字号:
/* * tinfgzip  -  tiny gzip decompressor * * Copyright (c) 2003 by Joergen Ibsen / Jibz * All Rights Reserved * * http://www.ibsensoftware.com/ * * This software is provided 'as-is', without any express * or implied warranty.  In no event will the authors be * held liable for any damages arising from the use of * this software. * * Permission is granted to anyone to use this software * for any purpose, including commercial applications, * and to alter it and redistribute it freely, subject to * the following restrictions: * * 1. The origin of this software must not be *    misrepresented; you must not claim that you *    wrote the original software. If you use this *    software in a product, an acknowledgment in *    the product documentation would be appreciated *    but is not required. * * 2. Altered source versions must be plainly marked *    as such, and must not be misrepresented as *    being the original software. * * 3. This notice may not be removed or altered from *    any source distribution. * *----------------------------------------------------------- * Modification:  Changed to handle 2 possible uncompressed * length values for Edimax-style CSYS blocks. *----------------------------------------------------------- */#include "tinf.h"#define FTEXT    1#define FHCRC    2#define FEXTRA   4#define FNAME    8#define FCOMMENT 16int tinf_gzip_uncompress(void *dest, unsigned int *destLen,                         const void *source, unsigned int sourceLen){    unsigned char *src = (unsigned char *)source;    unsigned char *dst = (unsigned char *)dest;    unsigned char *start;    unsigned int dlen_1, dlen_2, crc32_1, crc32_2;    int res;    unsigned char flg;    /* -- check format -- */    /* check id bytes */    if (src[0] != 0x1f || src[1] != 0x8b) return TINF_DATA_ERROR;    /* check method is deflate */    if (src[2] != 8) return TINF_DATA_ERROR;    /* get flag byte */    flg = src[3];    /* check that reserved bits are zero */    if (flg & 0xe0) return TINF_DATA_ERROR;    /* -- find start of compressed data -- */    /* skip base header of 10 bytes */    start = src + 10;    /* skip extra data if present */    if (flg & FEXTRA)    {       unsigned int xlen = start[1];       xlen = 256*xlen + start[0];       start += xlen + 2;    }    /* skip file name if present */    if (flg & FNAME) { while (*start) ++start; ++start; }    /* skip file comment if present */    if (flg & FCOMMENT) { while (*start) ++start; ++start; }    /* check header crc if present */    if (flg & FHCRC)    {       unsigned int hcrc = start[1];       hcrc = 256*hcrc + start[0];       if (hcrc != (tinf_crc32(src, start - src) & 0x0000ffff))          return TINF_DATA_ERROR;       start += 2;    }    /* -- get decompressed length -- */    dlen_1 =              src[sourceLen - 1];    dlen_1 = 256*dlen_1 + src[sourceLen - 2];    dlen_1 = 256*dlen_1 + src[sourceLen - 3];    dlen_1 = 256*dlen_1 + src[sourceLen - 4];    /* -- if CSYS block was padded there will be an extra byte -- */    dlen_2 =              src[sourceLen - 2];    dlen_2 = 256*dlen_2 + src[sourceLen - 3];    dlen_2 = 256*dlen_2 + src[sourceLen - 4];    dlen_2 = 256*dlen_2 + src[sourceLen - 5];    /* -- get crc32 of decompressed data -- */    crc32_1 =               src[sourceLen - 5];    crc32_1 = 256*crc32_1 + src[sourceLen - 6];    crc32_1 = 256*crc32_1 + src[sourceLen - 7];    crc32_1 = 256*crc32_1 + src[sourceLen - 8];    /* -- if CSYS block was padded there will be an extra byte -- */    crc32_2 =               src[sourceLen - 6];    crc32_2 = 256*crc32_2 + src[sourceLen - 7];    crc32_2 = 256*crc32_2 + src[sourceLen - 8];    crc32_2 = 256*crc32_2 + src[sourceLen - 9];    /* -- decompress data -- */    res = tinf_uncompress(dst, destLen, start, src + sourceLen - start - 8);    if (res != TINF_OK) return TINF_DATA_ERROR;    if ((*destLen != dlen_1) && (*destLen != dlen_2))		return TINF_DATA_ERROR;    /* -- check CRC32 checksum -- */    if ((*destLen == dlen_1 ? crc32_1 : crc32_2) != tinf_crc32(dst, *destLen))		return TINF_DATA_ERROR;    return TINF_OK;}

⌨️ 快捷键说明

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