免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 6988 | 回复: 1
打印 上一主题 下一主题

[Android] Apk伪加密实现与破解JAVA源码 [复制链接]

论坛徽章:
39
白银圣斗士
日期:2015-11-24 10:40:40酉鸡
日期:2015-03-20 14:15:44寅虎
日期:2015-03-20 14:13:59午马
日期:2015-03-20 14:13:16白羊座
日期:2015-03-20 14:12:54金牛座
日期:2015-03-20 14:12:09双子座
日期:2015-03-20 14:11:57巨蟹座
日期:2015-03-20 14:11:44狮子座
日期:2015-03-20 14:11:29亥猪
日期:2015-03-20 14:16:24戌狗
日期:2015-03-20 14:16:40申猴
日期:2015-03-20 14:17:05
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-07-19 17:26 |只看该作者 |倒序浏览
       有些APK用解压工具打开会发现是加密格式的,但Android实际是不可能支持加密的APK的,这里就利用了ANDROID读取APK不检测ZIP文件头里的加密信息的空子。知道原理处理就很简单了。破解的PYTHON代码很早就有了。这个给出我写一个一份JAVA代码,支持给APK添加伪加密头信息,和去除伪加密头信息。
  1. package com.rover12421.apkutil;

  2. import java.io.File;
  3. import java.io.FileInputStream;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.nio.ByteBuffer;
  7. import java.nio.channels.FileChannel;
  8. import java.util.Arrays;
  9. import java.util.zip.ZipError;

  10. import static com.rover12421.apkutil.ZipConstants.*;

  11. public class ApkUtilTool {
  12.   
  13.     private FileChannel ch; // channel to the zipfile
  14.     private FileChannel fc;

  15.     /**
  16.      * 修复zip伪加密状态的Entry
  17.      * @param inZip
  18.      * @param storeZip
  19.      * @throws IOException
  20.      */
  21.     public void FixEncryptedEntry(File inZip, File fixZip) throws IOException {
  22.       changEntry(inZip, fixZip, true);
  23.   }
  24.    
  25.     /**
  26.      * 修复zip伪加密状态的Entry
  27.      * @param inZip
  28.      * @param storeZip
  29.      * @throws IOException
  30.      */
  31.     public void FixEncryptedEntry(String inZip, String fixZip) throws IOException {
  32.       FixEncryptedEntry(new File(inZip), new File(fixZip));
  33.     }
  34.    
  35.     /**
  36.      * 修改zip的Entry为伪加密状态
  37.      * @param inZip
  38.      * @param storeZip
  39.      * @throws IOException
  40.      */
  41.     public void ChangToEncryptedEntry(File inZip, File storeZip) throws IOException {
  42.       changEntry(inZip, storeZip, false);
  43.     }
  44.    
  45.     /**
  46.      * 修改zip的Entry为伪加密状态
  47.      * @param inZip
  48.      * @param storeZip
  49.      * @throws IOException
  50.      */
  51.     public void ChangToEncryptedEntry(String inZip, String storeZip) throws IOException {
  52.       ChangToEncryptedEntry(new File(inZip), new File(storeZip));
  53.     }
  54.    
  55.     /**
  56.      * 更改zip的Entry为伪加密状态
  57.      * @param inZip
  58.      * @param storeZip
  59.      * @param fix  ture:修复伪加密 false:更改到伪加密
  60.      * @throws IOException
  61.      */
  62.     private void changEntry(File inZip, File storeZip, boolean fix) throws IOException {
  63.       FileInputStream fis = new FileInputStream(inZip);
  64.     FileOutputStream fos = new FileOutputStream(storeZip);
  65.    
  66.     byte[] buf = new byte[10240];
  67.       int len;
  68.       while ((len = fis.read(buf)) != -1) {
  69.       fos.write(buf, 0, len);
  70.     }
  71.       
  72.       ch = fis.getChannel();
  73.       fc = fos.getChannel();
  74.       
  75.       changEntry(fix);
  76.       
  77.       ch.close();
  78.       fc.close();
  79.    
  80.     fis.close();
  81.     fos.close();
  82.     }
  83.    
  84.   // Reads zip file central directory. Returns the file position of first
  85.     // CEN header, otherwise returns -1 if an error occured. If zip->msg != NULL
  86.     // then the error was a zip format error and zip->msg has the error text.
  87.     // Always pass in -1 for knownTotal; it's used for a recursive call.
  88.     private void changEntry(boolean fix) throws IOException {
  89.       END end = findEND();
  90.       
  91.         if (end.cenlen > end.endpos)
  92.             zerror("invalid END header (bad central directory size)");
  93.         long cenpos = end.endpos - end.cenlen;     // position of CEN table

  94.         // Get position of first local file (LOC) header, taking into
  95.         // account that there may be a stub prefixed to the zip file.
  96.         long locpos = cenpos - end.cenoff;
  97.         if (locpos < 0)
  98.             zerror("invalid END header (bad central directory offset)");

  99.         // read in the CEN and END
  100.         byte[] cen = new byte[(int)(end.cenlen + ENDHDR)];
  101.         if (readFullyAt(cen, 0, cen.length, cenpos) != end.cenlen + ENDHDR) {
  102.             zerror("read CEN tables failed");
  103.         }

  104.         int pos = 0;
  105.         int limit = cen.length - ENDHDR;
  106.         while (pos < limit) {
  107.             if (CENSIG(cen, pos) != CENSIG)
  108.                 zerror("invalid CEN header (bad signature)");
  109.             int method = CENHOW(cen, pos);
  110.             int nlen   = CENNAM(cen, pos);
  111.             int elen   = CENEXT(cen, pos);
  112.             int clen   = CENCOM(cen, pos);
  113.             
  114.             if (fix) {
  115.               if ((CEN***(cen, pos) & 1) != 0) {
  116.                   byte[] name = Arrays.copyOfRange(cen, pos + CENHDR, pos + CENHDR + nlen);
  117.                   System.out.println("Found the encrypted entry : " + new String(name) + ", fix...");
  118.                   //b[n] & 0xff) | ((b[n + 1] & 0xff) << 8
  119.                   cen[pos+8] &= 0xFE;
  120. //                  cen[pos+8] ^= CEN***(cen, pos) % 2;
  121. //                  cen[pos+8] ^= cen[pos+8] % 2;
  122. //                    zerror("invalid CEN header (encrypted entry)");
  123.                 }
  124.       } else {
  125.         if ((CEN***(cen, pos) & 1) == 0) {
  126.                   byte[] name = Arrays.copyOfRange(cen, pos + CENHDR, pos + CENHDR + nlen);
  127.                   System.out.println("Chang the entry : " + new String(name) + ", Encrypted...");
  128.                   //b[n] & 0xff) | ((b[n + 1] & 0xff) << 8
  129.                   cen[pos+8] |= 0x1;
  130. //                    zerror("invalid CEN header (encrypted entry)");
  131.                 }
  132.       }
  133.             
  134.             
  135.             if (method != METHOD_STORED && method != METHOD_DEFLATED)
  136.                 zerror("invalid CEN header (unsupported compression method: " + method + ")");
  137.             if (pos + CENHDR + nlen > limit)
  138.                 zerror("invalid CEN header (bad header size)");
  139.             
  140.             // skip ext and comment
  141.             pos += (CENHDR + nlen + elen + clen);
  142.         }
  143.         
  144.         writeFullyAt(cen, 0, cen.length, cenpos);
  145.         
  146.         if (pos + ENDHDR != cen.length) {
  147.             zerror("invalid CEN header (bad header size)");
  148.         }
  149.     }
  150.    
  151.     // Reads len bytes of data from the specified offset into buf.
  152.     // Returns the total number of bytes read.
  153.     // Each/every byte read from here (except the cen, which is mapped).
  154.     final long readFullyAt(byte[] buf, int off, long len, long pos)
  155.         throws IOException
  156.     {
  157.         ByteBuffer bb = ByteBuffer.wrap(buf);
  158.         bb.position(off);
  159.         bb.limit((int)(off + len));
  160.         return readFullyAt(bb, pos);
  161.     }

  162.     private final long readFullyAt(ByteBuffer bb, long pos)
  163.         throws IOException
  164.     {
  165.         synchronized(ch) {
  166.             return ch.position(pos).read(bb);
  167.         }
  168.     }
  169.    
  170.     final long writeFullyAt(byte[] buf, int off, long len, long pos)
  171.             throws IOException
  172.         {
  173.             ByteBuffer bb = ByteBuffer.wrap(buf);
  174.             bb.position(off);
  175.             bb.limit((int)(off + len));
  176.             return writeFullyAt(bb, pos);
  177.         }
  178.    
  179.     private final long writeFullyAt(ByteBuffer bb, long pos)
  180.             throws IOException
  181.     {
  182.         synchronized(fc) {
  183.             return fc.position(pos).write(bb);
  184.         }
  185.     }
  186.    
  187.     // Searches for end of central directory (END) header. The contents of
  188.     // the END header will be read and placed in endbuf. Returns the file
  189.     // position of the END header, otherwise returns -1 if the END header
  190.     // was not found or an error occurred.
  191.     private END findEND() throws IOException
  192.     {
  193.         byte[] buf = new byte[READBLOCKSZ];
  194.         long ziplen = ch.size();
  195.         long minHDR = (ziplen - END_MAXLEN) > 0 ? ziplen - END_MAXLEN : 0;
  196.         long minPos = minHDR - (buf.length - ENDHDR);

  197.         for (long pos = ziplen - buf.length; pos >= minPos; pos -= (buf.length - ENDHDR))
  198.         {
  199.             int off = 0;
  200.             if (pos < 0) {
  201.                 // Pretend there are some NUL bytes before start of file
  202.                 off = (int)-pos;
  203.                 Arrays.fill(buf, 0, off, (byte)0);
  204.             }
  205.             int len = buf.length - off;
  206.             if (readFullyAt(buf, off, len, pos + off) != len)
  207.                 zerror("zip END header not found");

  208.             // Now scan the block backwards for END header signature
  209.             for (int i = buf.length - ENDHDR; i >= 0; i--) {
  210.                 if (buf[i+0] == (byte)'P'    &&
  211.                     buf[i+1] == (byte)'K'    &&
  212.                     buf[i+2] == (byte)'\005' &&
  213.                     buf[i+3] == (byte)'\006' &&
  214.                     (pos + i + ENDHDR + ENDCOM(buf, i) == ziplen)) {
  215.                     // Found END header
  216.                     buf = Arrays.copyOfRange(buf, i, i + ENDHDR);
  217.                     END end = new END();
  218.                     end.endsub = ENDSUB(buf);
  219.                     end.centot = ENDTOT(buf);
  220.                     end.cenlen = ENDSIZ(buf);
  221.                     end.cenoff = ENDOFF(buf);
  222.                     end.comlen = ENDCOM(buf);
  223.                     end.endpos = pos + i;
  224.                     if (end.cenlen == ZIP64_MINVAL ||
  225.                         end.cenoff == ZIP64_MINVAL ||
  226.                         end.centot == ZIP64_MINVAL32)
  227.                     {
  228.                         // need to find the zip64 end;
  229.                         byte[] loc64 = new byte[ZIP64_LOCHDR];
  230.                         if (readFullyAt(loc64, 0, loc64.length, end.endpos - ZIP64_LOCHDR)
  231.                             != loc64.length) {
  232.                             return end;
  233.                         }
  234.                         long end64pos = ZIP64_LOCOFF(loc64);
  235.                         byte[] end64buf = new byte[ZIP64_ENDHDR];
  236.                         if (readFullyAt(end64buf, 0, end64buf.length, end64pos)
  237.                             != end64buf.length) {
  238.                             return end;
  239.                         }
  240.                         // end64 found, re-calcualte everything.
  241.                         end.cenlen = ZIP64_ENDSIZ(end64buf);
  242.                         end.cenoff = ZIP64_ENDOFF(end64buf);
  243.                         end.centot = (int)ZIP64_ENDTOT(end64buf); // assume total < 2g
  244.                         end.endpos = end64pos;
  245.                     }
  246.                     return end;
  247.                 }
  248.             }
  249.         }
  250.         zerror("zip END header not found");
  251.         return null; //make compiler happy
  252.     }
  253.    
  254.     static void zerror(String msg) {
  255.         throw new ZipError(msg);
  256.     }
  257.    
  258. // End of central directory record
  259.     static class END {
  260.         int  disknum;
  261.         int  sdisknum;
  262.         int  endsub;     // endsub
  263.         int  centot;     // 4 bytes
  264.         long cenlen;     // 4 bytes
  265.         long cenoff;     // 4 bytes
  266.         int  comlen;     // comment length
  267.         byte[] comment;

  268.         /* members of Zip64 end of central directory locator */
  269.         int diskNum;
  270.         long endpos;
  271.         int disktot;
  272.         
  273.         @Override
  274.         public String toString() {
  275.           return "disknum : " + disknum + "\n" +
  276.               "sdisknum : " + sdisknum + "\n" +
  277.               "endsub : " + endsub + "\n" +
  278.               "centot : " + centot + "\n" +
  279.               "cenlen : " + cenlen + "\n" +
  280.               "cenoff : " + cenoff + "\n" +
  281.               "comlen : " + comlen + "\n" +
  282.               "diskNum : " + diskNum + "\n" +
  283.               "endpos : " + endpos + "\n" +
  284.               "disktot : " + disktot;
  285.         }
  286.     }
  287. }
复制代码
代码修改自JDK7源码

论坛徽章:
39
白银圣斗士
日期:2015-11-24 10:40:40酉鸡
日期:2015-03-20 14:15:44寅虎
日期:2015-03-20 14:13:59午马
日期:2015-03-20 14:13:16白羊座
日期:2015-03-20 14:12:54金牛座
日期:2015-03-20 14:12:09双子座
日期:2015-03-20 14:11:57巨蟹座
日期:2015-03-20 14:11:44狮子座
日期:2015-03-20 14:11:29亥猪
日期:2015-03-20 14:16:24戌狗
日期:2015-03-20 14:16:40申猴
日期:2015-03-20 14:17:05
2 [报告]
发表于 2013-07-19 17:27 |只看该作者
  1. /*
  2. * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. *   - Redistributions of source code must retain the above copyright
  9. *     notice, this list of conditions and the following disclaimer.
  10. *
  11. *   - Redistributions in binary form must reproduce the above copyright
  12. *     notice, this list of conditions and the following disclaimer in the
  13. *     documentation and/or other materials provided with the distribution.
  14. *
  15. *   - Neither the name of Oracle nor the names of its
  16. *     contributors may be used to endorse or promote products derived
  17. *     from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
  20. * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  21. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  22. * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  23. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  24. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  25. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  27. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  28. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  29. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. */

  31. package com.rover12421.apkutil;


  32. /**
  33. *
  34. * @author Xueming Shen
  35. */

  36. class ZipConstants {
  37.     /*
  38.      * Compression methods
  39.      */
  40.     static final int METHOD_STORED     = 0;
  41.     static final int METHOD_DEFLATED   = 8;
  42.     static final int METHOD_DEFLATED64 = 9;
  43.     static final int METHOD_BZIP2      = 12;
  44.     static final int METHOD_LZMA       = 14;
  45.     static final int METHOD_LZ77       = 19;
  46.     static final int METHOD_AES        = 99;

  47.     /*
  48.      * General purpose big flag
  49.      */
  50.     static final int FLAG_ENCRYPTED  = 0x01;
  51.     static final int FLAG_DATADESCR  = 0x08;    // crc, size and csize in dd
  52.     static final int FLAG_EFS        = 0x800;   // If this bit is set the filename and
  53.                                                 // comment fields for this file must be
  54.                                                 // encoded using UTF-8.
  55.     /*
  56.      * Header signatures
  57.      */
  58.     static long LOCSIG = 0x04034b50L;   // "PK\003\004"
  59.     static long EXTSIG = 0x08074b50L;   // "PK\007\008"
  60.     static long CENSIG = 0x02014b50L;   // "PK\001\002"
  61.     static long ENDSIG = 0x06054b50L;   // "PK\005\006"

  62.     /*
  63.      * Header sizes in bytes (including signatures)
  64.      */
  65.     static final int LOCHDR = 30;       // LOC header size
  66.     static final int EXTHDR = 16;       // EXT header size
  67.     static final int CENHDR = 46;       // CEN header size
  68.     static final int ENDHDR = 22;       // END header size

  69.     /*
  70.      * Local file (LOC) header field offsets
  71.      */
  72.     static final int LOCVER = 4;        // version needed to extract
  73.     static final int LOC*** = 6;        // general purpose bit flag
  74.     static final int LOCHOW = 8;        // compression method
  75.     static final int LOCTIM = 10;       // modification time
  76.     static final int LOCCRC = 14;       // uncompressed file crc-32 value
  77.     static final int LOCSIZ = 18;       // compressed size
  78.     static final int LOCLEN = 22;       // uncompressed size
  79.     static final int LOCNAM = 26;       // filename length
  80.     static final int LOCEXT = 28;       // extra field length

  81.     /*
  82.      * Extra local (EXT) header field offsets
  83.      */
  84.     static final int EXTCRC = 4;        // uncompressed file crc-32 value
  85.     static final int EXTSIZ = 8;        // compressed size
  86.     static final int EXTLEN = 12;       // uncompressed size

  87.     /*
  88.      * Central directory (CEN) header field offsets
  89.      */
  90.     static final int CENVEM = 4;        // version made by
  91.     static final int CENVER = 6;        // version needed to extract
  92.     static final int CEN*** = 8;        // encrypt, decrypt flags
  93.     static final int CENHOW = 10;       // compression method
  94.     static final int CENTIM = 12;       // modification time
  95.     static final int CENCRC = 16;       // uncompressed file crc-32 value
  96.     static final int CENSIZ = 20;       // compressed size
  97.     static final int CENLEN = 24;       // uncompressed size
  98.     static final int CENNAM = 28;       // filename length
  99.     static final int CENEXT = 30;       // extra field length
  100.     static final int CENCOM = 32;       // comment length
  101.     static final int CENDSK = 34;       // disk number start
  102.     static final int CENATT = 36;       // internal file attributes
  103.     static final int CENATX = 38;       // external file attributes
  104.     static final int CENOFF = 42;       // LOC header offset

  105.     /*
  106.      * End of central directory (END) header field offsets
  107.      */
  108.     static final int ENDSUB = 8;        // number of entries on this disk
  109.     static final int ENDTOT = 10;       // total number of entries
  110.     static final int ENDSIZ = 12;       // central directory size in bytes
  111.     static final int ENDOFF = 16;       // offset of first CEN header
  112.     static final int ENDCOM = 20;       // zip file comment length

  113.     /*
  114.      * ZIP64 constants
  115.      */
  116.     static final long ZIP64_ENDSIG = 0x06064b50L;  // "PK\006\006"
  117.     static final long ZIP64_LOCSIG = 0x07064b50L;  // "PK\006\007"
  118.     static final int  ZIP64_ENDHDR = 56;           // ZIP64 end header size
  119.     static final int  ZIP64_LOCHDR = 20;           // ZIP64 end loc header size
  120.     static final int  ZIP64_EXTHDR = 24;           // EXT header size
  121.     static final int  ZIP64_EXTID  = 0x0001;       // Extra field Zip64 header ID

  122.     static final int  ZIP64_MINVAL32 = 0xFFFF;
  123.     static final long ZIP64_MINVAL = 0xFFFFFFFFL;

  124.     /*
  125.      * Zip64 End of central directory (END) header field offsets
  126.      */
  127.     static final int  ZIP64_ENDLEN = 4;       // size of zip64 end of central dir
  128.     static final int  ZIP64_ENDVEM = 12;      // version made by
  129.     static final int  ZIP64_ENDVER = 14;      // version needed to extract
  130.     static final int  ZIP64_ENDNMD = 16;      // number of this disk
  131.     static final int  ZIP64_ENDDSK = 20;      // disk number of start
  132.     static final int  ZIP64_ENDTOD = 24;      // total number of entries on this disk
  133.     static final int  ZIP64_ENDTOT = 32;      // total number of entries
  134.     static final int  ZIP64_ENDSIZ = 40;      // central directory size in bytes
  135.     static final int  ZIP64_ENDOFF = 48;      // offset of first CEN header
  136.     static final int  ZIP64_ENDEXT = 56;      // zip64 extensible data sector

  137.     /*
  138.      * Zip64 End of central directory locator field offsets
  139.      */
  140.     static final int  ZIP64_LOCDSK = 4;       // disk number start
  141.     static final int  ZIP64_LOCOFF = 8;       // offset of zip64 end
  142.     static final int  ZIP64_LOCTOT = 16;      // total number of disks

  143.     /*
  144.      * Zip64 Extra local (EXT) header field offsets
  145.      */
  146.     static final int  ZIP64_EXTCRC = 4;       // uncompressed file crc-32 value
  147.     static final int  ZIP64_EXTSIZ = 8;       // compressed size, 8-byte
  148.     static final int  ZIP64_EXTLEN = 16;      // uncompressed size, 8-byte

  149.     /*
  150.      * Extra field header ID
  151.      */
  152.     static final int  EXTID_ZIP64 = 0x0001;      // ZIP64
  153.     static final int  EXTID_NTFS  = 0x000a;      // NTFS
  154.     static final int  EXTID_UNIX  = 0x000d;      // UNIX
  155.     static final int  EXTID_EFS   = 0x0017;      // Strong Encryption
  156.     static final int  EXTID_EXTT  = 0x5455;      // Info-ZIP Extended Timestamp

  157.     /*
  158.      * fields access methods
  159.      */
  160.     ///////////////////////////////////////////////////////
  161.     static final int CH(byte[] b, int n) {
  162.        return b[n] & 0xff;
  163.     }

  164.     static final int SH(byte[] b, int n) {
  165.         return (b[n] & 0xff) | ((b[n + 1] & 0xff) << 8);
  166.     }

  167.     static final long LG(byte[] b, int n) {
  168.         return ((SH(b, n)) | (SH(b, n + 2) << 16)) & 0xffffffffL;
  169.     }

  170.     static final long LL(byte[] b, int n) {
  171.         return (LG(b, n)) | (LG(b, n + 4) << 32);
  172.     }

  173.     static final long GETSIG(byte[] b) {
  174.         return LG(b, 0);
  175.     }

  176.     // local file (LOC) header fields
  177.     static final long LOCSIG(byte[] b) { return LG(b, 0); } // signature
  178.     static final int  LOCVER(byte[] b) { return SH(b, 4); } // version needed to extract
  179.     static final int  LOC***(byte[] b) { return SH(b, 6); } // general purpose bit flags
  180.     static final int  LOCHOW(byte[] b) { return SH(b, 8); } // compression method
  181.     static final long LOCTIM(byte[] b) { return LG(b, 10);} // modification time
  182.     static final long LOCCRC(byte[] b) { return LG(b, 14);} // crc of uncompressed data
  183.     static final long LOCSIZ(byte[] b) { return LG(b, 18);} // compressed data size
  184.     static final long LOCLEN(byte[] b) { return LG(b, 22);} // uncompressed data size
  185.     static final int  LOCNAM(byte[] b) { return SH(b, 26);} // filename length
  186.     static final int  LOCEXT(byte[] b) { return SH(b, 28);} // extra field length

  187.     // extra local (EXT) header fields
  188.     static final long EXTCRC(byte[] b) { return LG(b, 4);}  // crc of uncompressed data
  189.     static final long EXTSIZ(byte[] b) { return LG(b, 8);}  // compressed size
  190.     static final long EXTLEN(byte[] b) { return LG(b, 12);} // uncompressed size

  191.     // end of central directory header (END) fields
  192.     static final int  ENDSUB(byte[] b) { return SH(b, 8); }  // number of entries on this disk
  193.     static final int  ENDTOT(byte[] b) { return SH(b, 10);}  // total number of entries
  194.     static final long ENDSIZ(byte[] b) { return LG(b, 12);}  // central directory size
  195.     static final long ENDOFF(byte[] b) { return LG(b, 16);}  // central directory offset
  196.     static final int  ENDCOM(byte[] b) { return SH(b, 20);}  // size of zip file comment
  197.     static final int  ENDCOM(byte[] b, int off) { return SH(b, off + 20);}

  198.     // zip64 end of central directory recoder fields
  199.     static final long ZIP64_ENDTOD(byte[] b) { return LL(b, 24);}  // total number of entries on disk
  200.     static final long ZIP64_ENDTOT(byte[] b) { return LL(b, 32);}  // total number of entries
  201.     static final long ZIP64_ENDSIZ(byte[] b) { return LL(b, 40);}  // central directory size
  202.     static final long ZIP64_ENDOFF(byte[] b) { return LL(b, 48);}  // central directory offset
  203.     static final long ZIP64_LOCOFF(byte[] b) { return LL(b, 8);}   // zip64 end offset

  204.     // central directory header (CEN) fields
  205.     static final long CENSIG(byte[] b, int pos) { return LG(b, pos + 0); }
  206.     static final int  CENVEM(byte[] b, int pos) { return SH(b, pos + 4); }
  207.     static final int  CENVER(byte[] b, int pos) { return SH(b, pos + 6); }
  208.     static final int  CEN***(byte[] b, int pos) { return SH(b, pos + 8); }
  209.     static final int  CENHOW(byte[] b, int pos) { return SH(b, pos + 10);}
  210.     static final long CENTIM(byte[] b, int pos) { return LG(b, pos + 12);}
  211.     static final long CENCRC(byte[] b, int pos) { return LG(b, pos + 16);}
  212.     static final long CENSIZ(byte[] b, int pos) { return LG(b, pos + 20);}
  213.     static final long CENLEN(byte[] b, int pos) { return LG(b, pos + 24);}
  214.     static final int  CENNAM(byte[] b, int pos) { return SH(b, pos + 28);}
  215.     static final int  CENEXT(byte[] b, int pos) { return SH(b, pos + 30);}
  216.     static final int  CENCOM(byte[] b, int pos) { return SH(b, pos + 32);}
  217.     static final int  CENDSK(byte[] b, int pos) { return SH(b, pos + 34);}
  218.     static final int  CENATT(byte[] b, int pos) { return SH(b, pos + 36);}
  219.     static final long CENATX(byte[] b, int pos) { return LG(b, pos + 38);}
  220.     static final long CENOFF(byte[] b, int pos) { return LG(b, pos + 42);}

  221.     /* The END header is followed by a variable length comment of size < 64k. */
  222.     static final long END_MAXLEN = 0xFFFF + ENDHDR;
  223.     static final int READBLOCKSZ = 128;
  224. }
复制代码
zip信息类,直接提取自JDK7
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP