首页
社区
课程
招聘
[求助]安卓中Zlib解压不会运用,求帮助
发表于: 2013-2-28 12:03 10824

[求助]安卓中Zlib解压不会运用,求帮助

2013-2-28 12:03
10824
各位朋友大家好,我玩的一款手机网游,想做做外挂解放一下双手,(游戏中不能交易任何物品,所以作此外挂纯属爱好)。

情况如下:

在下面这一贴中,licthday同学已经告知,该数据块中标志位 01 78 9C 表示运用zlib解压
http://bbs.pediy.com/showthread.php?t=163133&highlight=

经常找资料,发现相关资料不多,找到一个自认为应该能用,

标题:java.util.zip.Deflater 压缩 inflater解压
链接:http://navylee.iteye.com/blog/1661733

我寻求其中解压部分放入我的程序,但运行时被告知:
System.err
java.util.zip.DataFormatException: data error

代码详情如下:

package com.example.q1;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
import android.widget.Toast;

import java.io.ByteArrayOutputStream;
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;

public class MainActivity extends Activity {
static TextView mTextView1 = null;
static TextView mTextView2 = null;
byte bytes[]={0x00,(byte) 0xA4,0x01,0x78,(byte) 0x9C,(byte) 0x95,(byte) 0xCF,0x4D,0x0A,(byte) 0x83,0x30,0x10,0x05,(byte) 0xE0,(byte) 0xBB,(byte) 0xBC,0x75,(byte) 0x90,(byte) 0xFC,0x17,0x73,(byte) 0x83,(byte) 0xEE,(byte) 0xA5,(byte) 0x9B,(byte) 0xE2,(byte) 0xCA,0x0E,0x54,(byte) 0xB0,0x2A,0x31,0x0A,0x45,(byte) 0xBC,0x7B,0x63,(byte) 0xBB,(byte) 0x89,(byte) 0xAB,(byte) 0xC6,(byte) 0xEC,0x5E,0x26,0x5F,0x66,0x66,0x45,0x18,(byte) 0xE0,(byte) 0xEE,0x35,(byte) 0xC3,0x30,(byte) 0xC2,0x09,(byte) 0xA1,0x24,(byte) 0x83,(byte) 0xA7,0x00,(byte) 0xC7,0x19,0x26,(byte) 0xF2,0x0B,(byte) 0xF9,(byte) 0xAA,0x7D,0x51,(byte) 0xAC,0x28,(byte) 0xCB,0x4B,0x65,(byte) 0x8C,(byte) 0xB6,0x0C,0x4D,(byte) 0xD7,0x52,0x1F,0x6E,(byte) 0xE4,(byte) 0xA7,0x76,(byte) 0xE8,(byte) 0xE1,0x20,0x0A,0x55,0x70,0x30,(byte) 0xCC,0x11,0x54,(byte) 0xD4,0x3C,(byte) 0xA7,(byte) 0xF8,(byte) 0xE1,(byte) 0xFA,0x4D,(byte) 0xD7,(byte) 0xC7,0x5E,(byte) 0x96,0x36,0x1E,0x7D,0x29,(byte) 0xE3,(byte) 0x93,(byte) 0xF0,0x1E,(byte) 0xE9,0x77,(byte) 0xC9,0x45,(byte) 0x8C,0x1D,0x2D,(byte) 0xD4,(byte) 0xED,0x09,0x1B,(byte) 0xFB,0x2F,0x64,0x22,0x64,(byte) 0x96,0x50,(byte) 0x89,(byte) 0xE0,0x59,0x42,(byte) 0x9F,(byte) 0xEC,0x21,0x0F,0x7B, (byte) 0x94,0x59,0x22,(byte) 0x9D,0x4A,(byte) 0x98,0x2C,(byte) 0xA2,0x4F,0x37,0x31,0x27,0x57,(byte) 0x97,(byte) 0xDC,0x1E,0x45,(byte) 0xBD,0x7D,0x00,0x4B,(byte) 0x99,(byte) 0x92,(byte) 0xFC};
        @Override
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
               
                mTextView1 = (TextView)this.findViewById(R.id.textView2);
                mTextView2 = (TextView)this.findViewById(R.id.textView1);

            mTextView1.setText(bytes.toString());
            byte[] result=null;
       
                try {
                        decompress(bytes);
                } catch (DataFormatException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
               
        }

        public static byte[] decompress(byte[] value) throws DataFormatException {  
            ByteArrayOutputStream bos = new ByteArrayOutputStream(value.length);
            Inflater decompressor = new Inflater();
            try {  
              decompressor.setInput(value);
              final byte[] buf = new byte[1024];  
              while (!decompressor.finished()) {  
                int count = decompressor.inflate(buf);  
                bos.write(buf, 0, count);  
              }  
            } finally {   
              decompressor.end();  
            }  
            mTextView2.setText(bos.toString());
           return bos.toByteArray();  
          }         
       

        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
                // Inflate the menu; this adds items to the action bar if it is present.
                getMenuInflater().inflate(R.menu.main, menu);
                return true;
        }

}
下图为拦截的服务器返回的数据封包,不知我程序中的 bytes[] 赋值对不对,附件中包含程序及封包,请帮我看看

[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

上传的附件:
收藏
免费 0
支持
分享
最新回复 (5)
雪    币: 28972
活跃值: (7458)
能力值: ( LV15,RANK:3306 )
在线值:
发帖
回帖
粉丝
2
目测把开头的00 A4 01去掉就行了



// zlib_src→deflate.c→deflate
s->strstart = 0;
s->w_bits = 15; //window size
s->level = 6; //default compression level
Z_DEFLATED = 8;
// header = 0x789C
上传的附件:
2013-2-28 15:17
0
雪    币: 157
活跃值: (10)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
3
不会java。zlib用的是deflate算法,被定义在rfc1951中。看rfc1951就ok了~
需要一点算法基础,deflate分2部,第一步是lz77,第二步是huffman。给个分析地址给你。
http://www.jb51.net/article/7040.htm
2013-2-28 15:22
0
雪    币: 35
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
谢谢,算法基础有点难度。既然别人能用,应该是我某个地方没注意到。

希望有人能指出来
2013-2-28 16:12
0
雪    币: 35
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
高,实在是高,真的OK了,谢谢

能告诉我您的这知识,我查阅什么资料可以查到么
2013-2-28 16:21
0
雪    币: 66
活跃值: (188)
能力值: ( LV3,RANK:30 )
在线值:
发帖
回帖
粉丝
6
是的, 0x78 0x9C 是一个 zlib header,后面的是 deflate 数据

zlib 能使用一个gzip header,zlib header 或者不使用数据头压缩数据
带有 header 的数据可以实现错误检测
zlib header 是一个可变的头部
关于 zlib header 可以查看 RFC 1950,有详细介绍
deflate   (RFC1951)    一种压缩算法,使用LZ77和哈弗曼进行编码
zlib      (RFC1950)    一种格式,是对deflate进行了简单的封装
gzip      (RFC1952)    一种格式,也是对deflate进行的封装
2013-2-28 17:56
0
游客
登录 | 注册 方可回帖
返回
//