參考:http://blog.csdn.net/a200710716/article/details/51644421
zip文件格式:
[文件頭+文件數據+數據描述符]{此處可重復n次}+核心目錄+目錄結束標識
當壓縮包中有多個文件時,就會有多個[文件頭+文件數據+數據描述符]
壓縮源文件數據區
[local file header + file data + data descriptor]
記錄着壓縮的所有文件的內容信息,每個壓縮文件都由local file header 、file data、data descriptor三部分組成,在這個數據區中每一個壓縮的源文件/目錄都是一條記錄。
local file header 文件頭
用於標識該文件的開始,記錄了該壓縮文件的信息。文件頭標識,值固定(0x04034b50)
Central directory 核心目錄
記錄了壓縮文件的目錄信息,在這個數據區中每一條紀錄對應在壓縮源文件數據區中的一條數據。文件標示,值固定(0x02014b50)
目錄結束標識
目錄結束標識存在於整個歸檔包的結尾,用於標記壓縮的目錄數據的結束。每個壓縮文件必須有且只有一個EOCD記錄。標記頭(0x06054b50)
主要看這個結構的注釋。
Offset | Bytes | Description | 譯 |
---|---|---|---|
0 | 4 | End of central directory signature = 0x06054b50 | 核心目錄結束標記(0x06054b50) |
4 | 2 | Number of this disk | 當前磁盤編號 |
6 | 2 | number of the disk with the start of the central directory | 核心目錄開始位置的磁盤編號 |
8 | 2 | total number of entries in the central directory on this disk | 該磁盤上所記錄的核心目錄數量 |
10 | 2 | total number of entries in the central directory | 核心目錄結構總數 |
12 | 2 | Size of central directory (bytes) | 核心目錄的大小 |
16 | 4 | offset of start of central directory with respect to the starting disk number | 核心目錄開始位置相對於archive開始的位移 |
20 | 2 | .ZIP file comment length(n) | 注釋長度 |
22 | n | .ZIP Comment | 注釋內容 |
即:
1.zip注釋可隨意修改(最大長度2個字節即256長度)
2.如何尋找注釋內容?找標記頭位移20位
如:看某個apk注釋
此apk的注釋內容為:
是個json數據:{"pn":"MFW","sf":0} 其中 末尾的13 是\r回車 00 是空字符
apk多渠道探討:
1.由此可見此注釋內容可以寫,apk渠道信息。
2.在安裝到手機號找到對應apk獲取此注釋內容存本地。
美團模式:
參考:https://tech.meituan.com/mt-apk-packaging.html
每打一個渠道包只需復制一個apk,在META-INF
中添加一個使用渠道號命名的空文件即可。