> 文章列表 > 7、应用重签名

7、应用重签名

7、应用重签名

应用重签名概述

  • codesing
  • 重签名步骤
  • SHELL脚本
  • 用户组&文件权限

一、Codesign

Xcode提供了签名工具,codesign,我们通过几个命令就可以完成重签名

1.1 终端命令

  • 列出钥匙串里可签名的证书

security find-identity -v -p codesigning

  • 强制替换签名

codesign -fs "证书串"文件名

  • 给文件添加权限

chmod +x 可执行文件

  • 查看描述文件

security cms -D -i ../embedded.mobileprovision

  • 重签名签名App包

codesign -fs "证书串" --no-strict --entitlements=权限文件.plst APP包

  • 将输入文件压缩为输出文件

zip -ry 输出文件 输入文件

二、重签名步骤

  1. 删除插件和带有插件的 .app包(比如Watch)
  2. 对Frameworks里面的库进行重签名
  3. 给可执行文件 +x(可执行)权限
  4. 添加描述文件(新建工程,真机编译得到,而且要运行,将描述文件安装到手机)
  5. 替换BundleID(info.plist文件. BundleID要和描述文件中的ID保持一致)
  6. 通过授权文件 (Entitlements)重签 .app包
    1. 查看描述文件 security cms -D -i embedded.mobileprovision
    2. 将描述文件中 Entitlements拷贝出来,生成 plist 文件(文件名称entitlements.plist)
    3. 用权限文件签名App包 codesign -fs "Apple Development: XX(XX)" --no--strict --entitlements=entitlements.plist WeChat.app
  7. 最后通过Xcode安装

三、Shell脚本

Shell是一种特殊的交互式工具,它为用户提供了启动程序、管理文件系统中文件以及运行在系统上的进程的途径. Shell一般是指命令行工具.它允许你输入文本命令,然后解释命令,并在内核中执行.Shell脚本,也就是用各种命令预先放入到一个文件中,方便一次性执行的一个脚本文件.

  • $source FileName
    • 意思: 在当前shell环境中读取并执行FileName中的命令
    • 特点:
      • 命令可以强行让一个脚本去立即影响当前的环境(一般用于加载配置文件)
      • 命令会强制执行脚本中的全部命令,而忽略文件的权限
  • $bash FileName、$zsh FileName
    • 重新建立一个子Shell、在子shell中执行脚本里面的句子
  • $ ./FileName
    • 读取并执行文件中的命令.但有一个前提,脚本文件需要有可执行权限

四、用户、组、权限

  • Unix和Linux都是多用户、多任务的系统,所以这样的系统里面就拥有了用户、组的概念.那么同样文件的权限也就有相应的所属用户和所属组了

4.1 Mac文件属性

$ ls -l
total 170240
drwx------@   4 holothurian  staff       128 10 20  2018 Applications
drwx------+  49 holothurian  staff      1568  4 19 01:55 Desktop
drwx------+  21 holothurian  staff       672  4  7 00:53 Documents
drwx------+  79 holothurian  staff      2528  4 18 12:17 Downloads
drwxr-xr-x    5 holothurian  staff       160  4 13 23:47 HSShell
drwx------@ 103 holothurian  admin      3296  4  5 18:26 Library
drwxr-xr-x   15 holothurian  staff       480  4 17 22:50 MonkeyDev
drwx------+   4 holothurian  staff       128  2  1  2020 Movies
drwx------+   7 holothurian  staff       224  4  7 01:18 Music
drwx------+   7 holothurian  staff       224 10 13  2019 Pictures
drwxr-xr-x    3 holothurian  staff        96  6  9  2021 Postman
drwxr-xr-x+   5 holothurian  staff       160  1 23  2017 Public
drwxr-xr-x    3 holothurian  staff        96 10 13  2018 PycharmProjects
drwxr-xr-x    4 holothurian  staff       128  8  7  2021 __handlers__
drwxr-xr-x    7 holothurian  staff       224  4  6 16:28 bin
drwxr-xr-x    3 holothurian  staff        96  8 31  2021 buglybin
drwxr-xr-x    3 holothurian  staff        96 12 16  2021 build
-rw-r--r--    1 holothurian  staff  86532348  6 23  2020 commandlinetools-linux-6609375_latest.zip
-rw-r--r--    1 holothurian  staff     68278  8 31  2021 cp_buglyQqUploadSymbolLib.jar
-rw-r--r--    1 holothurian  staff    546598  8 31  2021 cp_buglySymboliOS.jar
drwxr-xr-x   41 holothurian  staff      1312 11  3  2021 fonts
drwxr-xr-x    6 holothurian  staff       192  6  6  2021 help-note
drwxr-xr-x    8 holothurian  staff       256  9 13  2018 iCloud 云盘(归档)
-rw-r--r--    1 holothurian  staff       239  4 11 14:14 import
-rw-r--r--    1 holothurian  staff       768  3 29 22:26 player.list
  • [权限] [链接] [所有者] [所属组] [文件大小] [最后修改日期] [文件名称]

4.2 文件类型与权限(permission)

  • d rwx r-x r-x
  • [directory][user][group][other]
  • 文件类型:
    • 常见: [d] directory
    • [-] 文件
  • 文件权限
    • [r]: read 读, [w]: write 写 , [x]: execute 执行
    • 这三个权限的位置不会变,依次是rwx. 出现减号[-] 在对应位置,代表没有此权限
  • 一个文件的完整权限,总共分为三组:
    • 第一组: 文件所有者的权限
    • 第二组: 这一组其他用户的权限
    • 第三组: 非本组用户的权限

4.3 改变权限: chmod

文件权限的改变使用chmod命令. 设置方法有两种 : 数字类型改变和符号类型改变

由于文件权限分为三种身份: [user][group][other]

  • 数字类型
    • 各个权限数字对照: r: 4 w:2 x:1
    • 如果一个文件权限为 [-rwxr-xr-x]
    • User: 4+2+1 = 7
    • Group: 4+0+1 = 5
    • Other: 4+0+1 = 5
    • 命令: chmod 755 文件名
  • 符号类型
    • chmod [u、g、o、a] [+ 加入 、-(除去)、=(设置)] [r、w、x] 文件名
    • 例如: chmod + x liblldb.dylib