APK伪加密 一、伪加密技术原理 二、zip文件格式 三举例:

我们知道android apk本质上是zip格式的压缩包,我们将android应用程序的后缀.apk改为.zip就可以用解压软件轻松的将android应用程序解压缩。在日常生活或者工作中,我们通常为了保护我们自己的文件在进行压缩式都会进行加密处理。这样的方法对于android apk同样适用。原理很简单,在zip的文件格式中有一个位用来标示该zip压缩文件中的文件是否被加密,我们只要找到该标志位将其置1就可以实现我们的目的。而android的包安装服务(PackageManagerService)在进行apk安装时并不关心这个加密位(暂时我们就这么叫它吧)可以进行正常的安装并且也不会影响apk的运行。

二、zip文件格式

zip的文件格式通常有三个部分组成:压缩文件源数据、压缩目录源数据、目录结束标识。这三个部分中和我们说的加密位有关的是压缩目录源数据部分,我们接下来详细介绍这一部分。

压缩目录源数据部分记录着所有的压缩目录源数据。其结构如下:

Central directory file essay-header

 

Offset

Bytes

Description[18]

0

4

Central directory file essay-header signature =0x02014b50

核心目录文件essay-header标识=(0x02014b50)

4

2

Version made by

压缩所用的pkware版本

6

2

Version needed to extract (minimum)

解压所需pkware的最低版本

8

2

General purpose bit flag

通用位标记

10

2

Compression method

压缩方法

12

2

File last modification time

文件最后修改时间

14

2

File last modification date

文件最后修改日期

16

4

CRC-32

CRC-32算法

20

4

Compressed size

压缩后大小

24

4

Uncompressed size

未压缩的大小

28

2

File name length (n)

文件名长度

30

2

Extra field length (m)

扩展域长度

32

2

File comment length (k)

文件注释长度

34

2

Disk number where file starts

文件开始位置的磁盘编号

36

2

Internal file attributes

内部文件属性

38

4

External file attributes

外部文件属性

42

4

Relative offset of local file essay-header. This is the number of bytes between the start of the first disk on which the file occurs, and the start of the local file essay-header. This allows software reading the central directory to locate the position of the file inside the ZIP file.

本地文件essay-header的相对位移。

46

n

File name

目录文件名

46+n

m

Extra field

扩展域

46+n+m

k

File comment

文件注释内容

该结构中的General purpose bit flag部分的第0位如果置1,标识该压缩包被加密;置为0标识该压缩包没有被加密。

三举例:

  •  先给一个APK文件加密。

APK伪加密
一、伪加密技术原理
二、zip文件格式
三举例:

  • 用16进制编辑器打开它,搜索50 4B 01 02 注意大小端格式。

APK伪加密
一、伪加密技术原理
二、zip文件格式
三举例:

  • 修改这个红框之后偏移为5的字段01-->00。
  •  你会发现对应的AndroidManifest.xml就没有加密啦。

APK伪加密
一、伪加密技术原理
二、zip文件格式
三举例: