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

📄 csdn技术中心 lz77压缩算法(c语言版).htm

📁 是一个压缩文件的算法 用c语言写的
💻 HTM
📖 第 1 页 / 共 4 页
字号:
            ulBitOffset;<BR><BR>}<BR><BR><BR>void lz77decompress(<BR>&nbsp; 
            &nbsp;PUCHAR &nbsp;pDataBuffer,<BR>&nbsp; &nbsp;ULONG &nbsp; 
            ulNumberOfBits,<BR>&nbsp; &nbsp;PUCHAR 
            &nbsp;pOutputBuffer,<BR>&nbsp; &nbsp;PULONG 
            &nbsp;pulNumberOfBytes<BR>&nbsp; &nbsp;)<BR>{<BR>&nbsp; &nbsp;LONG 
            &nbsp; &nbsp; &nbsp; &nbsp;iSlideWindowPtr;<BR>&nbsp; &nbsp;PUCHAR 
            &nbsp; &nbsp; &nbsp;pSlideWindowPtr;<BR><BR>&nbsp; &nbsp;ULONG 
            &nbsp; length, offset;<BR>&nbsp; &nbsp;ULONG &nbsp; bit;<BR>&nbsp; 
            &nbsp;UCHAR &nbsp; cc;<BR>&nbsp; &nbsp;int &nbsp; &nbsp; 
            i;<BR><BR>&nbsp; &nbsp;ULONG &nbsp; ulBytesDecoded;<BR>&nbsp; 
            &nbsp;ULONG &nbsp; ulBitOffset;<BR><BR>&nbsp; &nbsp;ULONG &nbsp; 
            ulCodingLength;<BR>&nbsp; &nbsp;PUCHAR &nbsp;pWrite;<BR><BR>&nbsp; 
            &nbsp;iSlideWindowPtr = -MAX_WND_SIZE;<BR>&nbsp; &nbsp;pWrite = 
            (PUCHAR)pOutputBuffer;<BR>&nbsp; &nbsp;ulBitOffset = 0;<BR>&nbsp; 
            &nbsp;ulBytesDecoded = 0;<BR><BR><BR>&nbsp; &nbsp;while( 
            ulBitOffset&lt;ulNumberOfBits )<BR>&nbsp; &nbsp;{<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp;bit = ReadBitFromBitStream(pDataBuffer, 
            ulBitOffset);<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp;ulBitOffset++;<BR><BR>&nbsp; &nbsp; &nbsp; &nbsp;if( bit 
            )<BR>&nbsp; &nbsp; &nbsp; &nbsp;{<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp;if( iSlideWindowPtr&gt;=0 )<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp;{<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp;pSlideWindowPtr = pOutputBuffer + 
            iSlideWindowPtr;<BR><BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;}<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else if( 
            iSlideWindowPtr&gt;=-MAX_WND_SIZE )<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp;{<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;pSlideWindowPtr = pOutputBuffer;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp;}<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;else<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;pSlideWindowPtr = 
            NULL;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;}<BR><BR><BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for(i=0, 
            offset=0; i&lt;OFFSET_CODING_LENGTH; i++, ulBitOffset++)<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;bit = ReadBitFromBitStream(pDataBuffer, 
            ulBitOffset);<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;offset |= (bit&lt;&lt;i);<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp;}<BR><BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;length= ReadGolombCode(&amp;ulCodingLength, pDataBuffer, 
            ulBitOffset);<BR><BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;assert(offset&lt;MAX_WND_SIZE);<BR><BR>&nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp;if( length&gt;MAX_WND_SIZE )<BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;{<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp;assert(length&lt;=MAX_WND_SIZE);<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp;ulBitOffset += ulCodingLength;<BR><BR>&nbsp; &nbsp; 
            &nbsp; &nbsp; &nbsp; &nbsp;RtlMoveMemory(pWrite, 
            pSlideWindowPtr+offset, length);<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp;pWrite+=length;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;iSlideWindowPtr+=length;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;ulBytesDecoded+=length;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp;}<BR>&nbsp; &nbsp; &nbsp; &nbsp;else<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp;{<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for(i=0, cc=0; 
            i&lt;8 ; i++, ulBitOffset++)<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;{<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;bit = ReadBitFromBitStream(pDataBuffer, 
            ulBitOffset);<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;cc |= ((UCHAR)bit&lt;&lt;i);<BR>&nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp; &nbsp;}<BR><BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;*pWrite++ = cc;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;iSlideWindowPtr++;<BR>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 
            &nbsp;ulBytesDecoded++;<BR>&nbsp; &nbsp; &nbsp; 
            &nbsp;}<BR><BR>&nbsp; &nbsp;}<BR><BR>&nbsp; &nbsp;*pulNumberOfBytes 
            = ulBytesDecoded;<BR>}<BR><BR>extern "C"<BR>void 
            WINAPI<BR>LZ77Compress(<BR>&nbsp; &nbsp;PUCHAR 
            &nbsp;__pDataBuffer,<BR>&nbsp; &nbsp;ULONG &nbsp; 
            __ulDataLength,<BR>&nbsp; &nbsp;PUCHAR 
            &nbsp;__pOutputBuffer,<BR>&nbsp; &nbsp;PULONG 
            &nbsp;__pulNumberOfBits<BR>&nbsp; &nbsp;);<BR><BR>extern "C"<BR>void 
            WINAPI<BR>LZ77Decompress(<BR>&nbsp; &nbsp;PUCHAR 
            &nbsp;__pDataBuffer,<BR>&nbsp; &nbsp;ULONG &nbsp; 
            __ulNumberOfBits,<BR>&nbsp; &nbsp;PUCHAR 
            &nbsp;__pOutputBuffer,<BR>&nbsp; &nbsp;PULONG 
            &nbsp;__pulNumberOfBytes<BR>&nbsp; 
            &nbsp;);<BR><BR>int<BR>main(<BR>&nbsp; &nbsp;int &nbsp; &nbsp; 
            argc,<BR>&nbsp; &nbsp;char &nbsp; &nbsp;*argv[]<BR>&nbsp; 
            &nbsp;)<BR>{<BR>&nbsp; &nbsp;FILE &nbsp; &nbsp;*fp=NULL;<BR>&nbsp; 
            &nbsp;FILE &nbsp; &nbsp;*fp1;<BR>&nbsp; &nbsp;ULONG &nbsp; 
            fsize;<BR>&nbsp; &nbsp;ULONG &nbsp; ulNumberOfBits;<BR>&nbsp; 
            &nbsp;ULONG &nbsp; ulFileCompressedSize;<BR>&nbsp; &nbsp;ULONG 
            &nbsp; ulFileDecompressedSize;<BR>&nbsp; &nbsp;SYSTEMTIME &nbsp; 
            &nbsp; &nbsp;t1, t2;<BR><BR>&nbsp; &nbsp;if( 3!=argc )<BR>&nbsp; 
            &nbsp;{<BR>&nbsp; &nbsp; &nbsp; &nbsp;printf("Usage: lz77 [/c | /d] 
            filename\n");<BR>&nbsp; &nbsp; &nbsp; &nbsp;return -1;<BR>&nbsp; 
            &nbsp;}<BR><BR><BR><BR>// &nbsp;char &nbsp; 
            &nbsp;s1[]="abcdabcdefgabcdefaffasda";<BR>// &nbsp;ULONG &nbsp; a, 
            b;<BR>// &nbsp;FindLongestSubstring((PUCHAR)s1, (PUCHAR)s1+11, 
            11,&amp;a, &amp;b );<BR>// &nbsp;return 0;<BR><BR>&nbsp; &nbsp;fp = 
            fopen(argv[2], "rb");<BR>&nbsp; &nbsp;if( !fp )<BR>&nbsp; 
            &nbsp;{<BR>&nbsp; &nbsp; &nbsp; &nbsp;return -1;<BR>&nbsp; 
            &nbsp;}<BR><BR>&nbsp; &nbsp;fseek(fp, 0, SEEK_END);<BR>&nbsp; 
            &nbsp;fsize = ftell(fp);<BR>&nbsp; &nbsp;fseek(fp, 0, 
            SEEK_SET);<BR><BR>&nbsp; &nbsp;fread(__buffer1__, 1, fsize, 
            fp);<BR><BR><BR>&nbsp; &nbsp;GetSystemTime(&amp;t1);<BR>&nbsp; 
            &nbsp;lz77compress(__buffer1__, fsize, __buffer2__, 
            &amp;ulNumberOfBits);<BR>&nbsp; &nbsp;//LZ77Compress(__buffer1__, 
            fsize, __buffer2__, &amp;ulNumberOfBits);<BR>&nbsp; 
            &nbsp;GetSystemTime(&amp;t2);<BR>&nbsp; &nbsp;ulFileCompressedSize = 
            ((ulNumberOfBits+7)&gt;&gt;3);<BR><BR>&nbsp; 
            &nbsp;fp1=fopen("peinfo.c_", "wb+");<BR>&nbsp; &nbsp;if( !fp1 
            )<BR>&nbsp; &nbsp;{<BR>&nbsp; &nbsp; &nbsp; &nbsp;goto l1;<BR>&nbsp; 
            &nbsp;}<BR>&nbsp; &nbsp;fwrite(__buffer2__, 1, ulFileCompressedSize, 
            fp1);<BR>&nbsp; &nbsp;fclose(fp1);<BR><BR>&nbsp; 
            &nbsp;RtlZeroMemory(__buffer1__, sizeof(__buffer1__));<BR><BR>&nbsp; 
            &nbsp;lz77decompress(__buffer2__, ulNumberOfBits, __buffer1__, 
            &amp;ulFileDecompressedSize);<BR>&nbsp; 
            &nbsp;//LZ77Decompress(__buffer2__, ulNumberOfBits, __buffer1__, 
            &amp;ulFileDecompressedSize);<BR>&nbsp; &nbsp;fp1=fopen("peinfo.d_", 
            "wb+");<BR>&nbsp; &nbsp;if( !fp1 )<BR>&nbsp; &nbsp;{<BR>&nbsp; 
            &nbsp; &nbsp; &nbsp;goto l1;<BR>&nbsp; &nbsp;}<BR>&nbsp; 
            &nbsp;fwrite(__buffer1__, 1, ulFileDecompressedSize, fp1);<BR>&nbsp; 
            &nbsp;fclose(fp1);<BR><BR>l1:<BR>&nbsp; &nbsp;if( fp )<BR>&nbsp; 
            &nbsp;{<BR>&nbsp; &nbsp; &nbsp; &nbsp;fclose(fp);<BR>&nbsp; 
            &nbsp;}<BR><BR>&nbsp; &nbsp;ULONG &nbsp; milliS;<BR><BR>&nbsp; 
            &nbsp;milliS = ((t2.wHour - t1.wHour)*3600 + 
            (t2.wMinute-t1.wMinute)*60 + (t2.wSecond-t1.wSecond)) * 1000 + 
            (t2.wMilliseconds-t1.wMilliseconds);<BR>&nbsp; &nbsp;printf("Totally 
            %ld milliseconds elapsed!\n\n", milliS);<BR><BR>&nbsp; 
            &nbsp;printf("Press any key to exit!\n");<BR>&nbsp; 
            &nbsp;getch();<BR><BR>&nbsp; &nbsp;return 
            0;<BR>}<BR></SPAN></SPAN><BR>
            <DIV 
            style="FONT-SIZE: 14px; LINE-HEIGHT: 25px"><STRONG>作者Blog:</STRONG><A 
            id=ArticleContent1_ArticleContent1_AuthorBlogLink 
            href="http://blog.csdn.net/www_307/" 
            target=_blank>http://blog.csdn.net/www_307/</A></DIV>
            <DIV 
            style="FONT-SIZE: 14px; COLOR: #900; LINE-HEIGHT: 25px"><STRONG>相关文章</STRONG></DIV>
            <TABLE id=ArticleContent1_ArticleContent1_RelatedArticles 
            style="BORDER-COLLAPSE: collapse" cellSpacing=0 border=0>
              <TBODY>
              <TR>
                <TD><A 
                  href="http://dev.csdn.net/article/40/article/53/53134.shtm">elf-write工具写interpreter后门</A> 
                </TD></TR>
              <TR>
                <TD><A 
                  href="http://dev.csdn.net/article/40/article/48/48431.shtm">「病毒源代码专区」</A> 
                </TD></TR>
              <TR>
                <TD><A 
                  href="http://dev.csdn.net/article/40/article/47/47529.shtm">WVTFTPD 
                  0.9 heap overflow remote root exploit.c</A> </TD></TR>
              <TR>
                <TD><A 
                  href="http://dev.csdn.net/article/40/article/47/47525.shtm">iptables_exp.c</A> 
                </TD></TR>
              <TR>
                <TD><A 
                  href="http://dev.csdn.net/article/40/article/45/45349.shtm">Apache 
                  mod_include_exp</A> </TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><A 
      name=#Comment></A>
      <TABLE cellPadding=0 width="100%" border=0>
        <TBODY>
        <TR>
          <TD>
            <TABLE cellSpacing=0 cellPadding=0 width="100%" align=center 
            bgColor=#006699 border=0>
              <TBODY>
              <TR bgColor=#006699>
                <TD id=white align=middle width=556 bgColor=#006699><FONT 
                  color=#ffffff>对该文的评论</FONT> </TD></TR></TBODY></TABLE>
            <DIV align=right><A id=CommnetList1_CommnetList1_Morelink 
            href="http://comment.csdn.net/Comment.aspx?c=2&amp;s=40199">【评论】</A> 
            <A id=CommnetList1_CommnetList1_Hyperlink1 
            href="javascript:window.close();">【关闭】</A> 
      </DIV><BR></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></FORM><!-- 版权 -->
<HR align=center width=770 noShade SIZE=1>

<TABLE cellSpacing=0 cellPadding=0 width=500 align=center border=0>
  <TBODY>
  <TR>
    <TD vAlign=bottom align=middle height=10><A 
      href="http://www.csdn.net/intro/intro.asp?id=2">网站简介</A> - <A 
      href="http://www.csdn.net/intro/intro.asp?id=5">广告服务</A> - <A 
      href="http://www.csdn.net/map/map.shtm">网站地图</A> - <A 
      href="http://www.csdn.net/help/help.asp">帮助信息</A> - <A 
      href="http://www.csdn.net/intro/intro.asp?id=2">联系方式</A> - <A 
      href="http://www.csdn.net/english">English</A> </TD>
    <TD align=middle rowSpan=3><A 
      href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010"><IMG 
      height=48 src="CSDN技术中心 LZ77压缩算法(C语言版).files/biaoshi.gif" width=40 
      border=0></A></TD></TR>
  <TR>
    <TD vAlign=top align=middle>北京百联美达美数码科技有限公司 版权所有 京ICP证020026号</TD></TR>
  <TR align=middle>
    <TD vAlign=top><FONT face=Verdana>Copyright &copy; CSDN.NET, Inc. All Rights 
      Reserved</FONT></TD></TR>
  <TR>
    <TD height=15></TD></TR></TBODY></TABLE><!-- /版权 -->
<SCRIPT>
      document.write("<img src=http://count.csdn.net/count/pageview1.asp?columnid=4&itemid=11 border=0 width=0 height=0>");
    </SCRIPT>
</BODY></HTML>

⌨️ 快捷键说明

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