dsh-ipa-build 1.3.6 → 1.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/NOTICE CHANGED
@@ -5,13 +5,13 @@ dsh-ipa-build
5
5
 
6
6
  vendor/ 下的第三方组件各自按自己的许可证分发,和上面的 MIT 无关:
7
7
 
8
- - vendor/ldid-master/ —— ldid v2.1.5-procursus8(ProcursusTeam/ldid,commit 18255c5),AGPL-3.0(见该目录下的 COPYING)。
8
+ - vendor/ldid-master/ —— ldid v2.1.5-procursus8(ProcursusTeam/ldid,commit 18255c5),GNU Affero General Public License v3.0(AGPL-3.0,见该目录下的 COPYING)。
9
9
  只在 Linux / macOS 上编译成 ~/.ipa-toolchain/bin/ldid 用于本地签名。
10
10
  你的分发行为若触发 AGPL 义务(例如对外提供修改后的 ldid 或其衍生作品),
11
11
  需自行履行 AGPL 的源码提供义务。
12
- - vendor/libplist-2.6.0.tar.bz2 —— libplist,LGPL-2.1(https://github.com/libimobiledevice/libplist)。ldid 编译时静态/动态链接它,动态链接时保留替换库的权利即可。
12
+ - vendor/libplist-2.6.0.tar.bz2 —— libplist,GNU Lesser General Public License v2.1(LGPL-2.1,https://github.com/libimobiledevice/libplist)。ldid 编译时静态/动态链接它,动态链接时保留替换库的权利即可。
13
13
  - vendor/zsign/zsign.exe —— zsign v1.1.3 Windows 版,来自 https://github.com/zhlynn/zsign 。
14
- 该仓库声明的许可证是 GPL-3.0(见上游 LICENSE),二进制未做改动;分发前请按该仓库最新声明核对。
14
+ 该仓库声明的许可证是 GNU General Public License v3.0(GPL-3.0,见上游 LICENSE),二进制未做改动;分发前请按该仓库最新声明核对。
15
15
  - vendor/iPhoneOS16.5.sdk.tar.xz —— Apple 的 iPhoneOS SDK,版权归 Apple,仅随本插件用于本地交叉编译,不单独再分发 SDK。
16
16
  - iPhoneOS SDK 中的系统库头文件与 .tbd stub 版权归 Apple Inc.
17
17
 
package/README.md CHANGED
@@ -59,7 +59,9 @@ IPA_CERT_PASSWORD=证书密码 scripts/ipa resign old.ipa -o new.ipa --p12 dev.p
59
59
 
60
60
  ## 平台差异
61
61
 
62
- `pack` / `resign` / `info` 不依赖编译器,三平台行为一样。`build` 要 clang + ld64.lld:Linux/macOS 跑完 bootstrap 就有;Windows 上 bootstrap 会装 LLVM,实在装不上而机器里有 WSL 时,`build` 会把活转给 WSL 里的 bash 版本,命令不用改。
62
+ `pack` / `resign` / `info` 不依赖编译器,三平台行为一样。`build` 要 clang + ld64.lld:Linux/macOS 跑完 bootstrap 就有;Windows 上 bootstrap 会装 LLVM,实在装不上而机器里有 WSL 时,`build` 会把活转给 WSL 里的 bash 版本,命令不用改;密码按推荐方式放在 `IPA_CERT_PASSWORD` 里也会显式带进 WSL(wsl.exe 本身不传 Windows 环境变量)。
63
+
64
+ 已知差异:打 `.app` 成 `.ipa` 时,Linux/macOS 用 `zip -y` 保留符号链接,Windows 用 .NET 的 zip 实现会把 `.framework` 里的链接展开成文件副本(打包时会给出提示)。两种包都能装,但同一个 `.app` 两端打出来的体积和文件列表不一样;要完全一致就在 WSL 里跑 `pack`。
63
65
 
64
66
  ## 自检
65
67
 
@@ -68,7 +70,7 @@ scripts/ipa build scripts/examples/HelloApp --name HelloApp --bundle-id com.exam
68
70
  scripts/ipa info dist/HelloApp.ipa
69
71
  ```
70
72
 
71
- `info` 的签名行有内容就说明编译、打包、签名这条链路通了。没有编译器的机器用 `pack` 打这个例子也能验证打包和签名。
73
+ `info` 的签名行有内容就说明编译、打包、签名这条链路通了。签名判定按真实布局读:Mach-O 头和 load command 跟 slice 字节序走,签名 SuperBlob 固定大端。没有编译器的机器用 `pack` 打这个例子也能验证打包和签名。
72
74
 
73
75
  ## 包里的东西
74
76
 
package/SKILL.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  name: dsh-ipa-build
3
- version: 1.3.6
3
+ version: 1.3.7
4
4
  description: 把 iOS 程序做成 .ipa。源码能直接交叉编译成 arm64 包,现成的 .app 能打包,已有 ipa 能重签、改 bundle id 做多开,dylib 也跟着签。SDK、ldid、zsign 随插件带,环境由 AI 自己铺好,用户不用装东西。
5
5
  ---
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-ipa-build",
3
- "version": "1.3.6",
3
+ "version": "1.3.7",
4
4
  "description": "把 iOS 源码打成 .ipa 的 DSH 插件。包内自带 iPhoneOS 16.5 SDK 和 zsign,Windows / Linux / macOS 都能编能签,用户装完不用再配环境。",
5
5
  "license": "MIT",
6
6
  "repository": {
package/plugin.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "产出 IPA",
3
3
  "id": "dsh-ipa-build",
4
- "version": "1.3.6",
4
+ "version": "1.3.7",
5
5
  "type": "skill",
6
6
  "skill": "SKILL.md",
7
7
  "setup": {
@@ -8,6 +8,9 @@ param(
8
8
  'https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.8/clang+llvm-18.1.8-x86_64-pc-windows-msvc.tar.xz'
9
9
  ),
10
10
  # 上面那份 18.1.8 的 sha256,实测校验过(936MB,下完 tar -tJf 能完整列出)
11
+ # 注意:这个值写死就等于“只认这一个包”,如果上游换了 18.1.8 的构建产物,安装会被一直拒绝。
12
+ # 换机或换网络重下时若报对不上,先核对 size 981666720 与 tar 列表,再确认是不是上游换了包,别直接改这个数。
13
+ # 待办:在一台干净 Windows 机上完整跑一次 bootstrap.ps1 复核这个锚点。
11
14
  # 换 URL 的话这个哈希也要跟着换,不然会被判成"文件不对"
12
15
  [string]$LlvmSha = '22c5907db053026cc2a8ff96d21c0f642a90d24d66c23c6d28ee7b1d572b82e8'
13
16
  )
package/scripts/ipa CHANGED
@@ -79,14 +79,23 @@ CPU = {16777228: 'arm64', 16777223: 'x86_64', 12: 'armv7', 7: 'i386', 16777222:
79
79
 
80
80
  path = sys.argv[1]
81
81
  try:
82
- data = open(path, 'rb').read()
82
+ fh = open(path, 'rb')
83
83
  except Exception as e:
84
84
  print('读不了|%s' % e)
85
85
  sys.exit()
86
+ # 几百 MB 的二进制整读会把内存翻倍,这里只按偏移 seek 读
87
+ fh.seek(0, 2)
88
+ size = fh.tell()
86
89
 
87
90
  def rd(off, n, endian):
91
+ if off is None or off < 0 or off + n > size:
92
+ return None
93
+ fh.seek(off)
94
+ raw = fh.read(n)
95
+ if len(raw) != n:
96
+ return None
88
97
  fmt = ('>' if endian == 'be' else '<') + ('I' if n == 4 else 'Q')
89
- return struct.unpack(fmt, data[off:off + n])[0]
98
+ return struct.unpack(fmt, raw)[0]
90
99
 
91
100
  def sig_state(base, _fat_endian=None):
92
101
  # slice 自己的字节序看它自己的 magic,不能沿用 fat 头的字节序
@@ -110,15 +119,15 @@ def sig_state(base, _fat_endian=None):
110
119
  return None
111
120
  pos, end = base + hsz, base + hsz + sizeofcmds
112
121
  sigoff = None
113
- while pos + 8 <= end and pos + 8 <= len(data):
114
- cmd, size = rd(pos, 4, endian), rd(pos + 4, 4, endian)
115
- if size < 8:
122
+ while pos + 8 <= end and pos + 8 <= size:
123
+ cmd, cmdsz = rd(pos, 4, endian), rd(pos + 4, 4, endian)
124
+ if cmdsz is None or cmdsz < 8:
116
125
  break
117
- if cmd == 0x1d and pos + 16 <= len(data):
126
+ if cmd == 0x1d and pos + 16 <= size:
118
127
  # dataoff 相对 slice 起点,fat 里要加上 base
119
128
  sigoff = base + rd(pos + 8, 4, endian)
120
- pos += size
121
- if sigoff is None or sigoff + 12 > len(data):
129
+ pos += cmdsz
130
+ if sigoff is None or sigoff + 12 > size:
122
131
  return None
123
132
  # CodeSignature 的 SuperBlob 在文件里固定大端(FA DE 0C C0),
124
133
  # 跟 slice 自己是小端还是大端无关,这里不能跟着 slice 走
@@ -152,15 +161,15 @@ elif magic in (0xcefaedfe, 0xcffaedfe):
152
161
  sig = sig_state(0, 'be')
153
162
  elif magic in FAT:
154
163
  endian, entSize = FAT[magic]
155
- nfat = rd(4, 4, endian)
164
+ nfat = rd(4, 4, endian) or 0
156
165
  if nfat <= 20:
157
166
  for i in range(nfat):
158
167
  e = 8 + i * entSize
159
- if e + entSize > len(data):
168
+ if e + entSize > size:
160
169
  break
161
170
  archs.append(CPU.get(rd(e, 4, endian), '?'))
162
171
  off = rd(e + 8, 8 if entSize == 32 else 4, endian)
163
- if off < len(data):
172
+ if off is not None and off < size:
164
173
  st = sig_state(off)
165
174
  # 多个切片取最强的那个:任一有 CMS 就是真证书签名
166
175
  if st == 'cms' or (st and sig is None):
@@ -172,6 +181,7 @@ else:
172
181
 
173
182
  label = {'cms': '真证书签名(有 CMS)', 'adhoc': 'ad-hoc 伪签名(只有 CodeDirectory)', None: '没签'}[sig]
174
183
  print('|'.join(['+'.join(archs) or '?', label]))
184
+ fh.close()
175
185
  PY
176
186
  }
177
187
 
@@ -186,7 +196,12 @@ import os, struct, sys
186
196
  app = sys.argv[1]
187
197
  # 32/64 位 Mach-O、标准 fat(小端读出 0xBEBAFECA)和字节交换变体
188
198
  MAG = (0xfeedface, 0xfeedfacf, 0xcefaedfe, 0xcffaedfe, 0xbebafeca, 0xbfbafeca, 0xcafebabe, 0xcafebabf)
189
- for name in sorted(os.listdir(app)):
199
+ base = os.path.basename(app.rstrip('/'))
200
+ prefer = [base[:-4]] if base.endswith('.app') else []
201
+ names = sorted(os.listdir(app))
202
+ # 顶层常有 helper 之类的其他 Mach-O,app 同名的那份才是主程序,先试它
203
+ cand = [n for n in prefer if n in names] + [n for n in names if n not in prefer]
204
+ for name in cand:
190
205
  p = os.path.join(app, name)
191
206
  if not os.path.isfile(p):
192
207
  continue
@@ -347,7 +362,8 @@ PY
347
362
  zip_payload "$tmpipa" "$work"
348
363
  if [ -n "$p12" ]; then sign_with_cert "$tmpipa" "$out"; rm -f "$tmpipa"
349
364
  else mv -f "$tmpipa" "$out"; fi
350
- rm -rf "$PWD/.build"
365
+ # 只删这次构建的目录,同 cwd 下别的 app 的中间产物不能连坐
366
+ rm -rf "$work"; rmdir "$PWD/.build" 2>/dev/null || true
351
367
  echo "产物 $out"
352
368
  }
353
369
 
@@ -435,10 +451,16 @@ sign_nested() {
435
451
  while IFS= read -r x; do
436
452
  local xe; xe="$(plist_get "$x" CFBundleExecutable)"
437
453
  [ -n "$xe" ] || xe="$(basename "$x" .appex)"
438
- if [ -n "$ent" ] && [ -f "$ent" ]; then "$ldid" -S"$ent" "$x/$xe" || die "签 $x 失败"
454
+ # 扩展用自己的 entitlements(app groups 之类跟主 app 不一样),
455
+ # 没有就裸签,别把主 app 的高权限项摊到扩展上
456
+ local xent=""
457
+ for cand in "$x/Entitlements.plist" "$(dirname "$x")/$(basename "$x" .appex).entitlements"; do
458
+ [ -f "$cand" ] && { xent="$cand"; break; }
459
+ done
460
+ if [ -n "$xent" ]; then "$ldid" -S"$xent" "$x/$xe" || die "签 $x 失败"
439
461
  else "$ldid" -S "$x/$xe" || die "签 $x 失败"; fi
440
462
  find "$x" -name '*.dylib' -type f | while read -r d; do "$ldid" -S "$d" || true; done
441
- done < <(find "$app/PlugIns" -maxdepth 2 -name '*.appex' -type d 2>/dev/null)
463
+ done < <(find "$app" -name '*.appex' -type d -not -path '*/Frameworks/*' 2>/dev/null)
442
464
  fi
443
465
  if [ -d "$app/Frameworks" ]; then
444
466
  while IFS= read -r fwdir; do
@@ -452,13 +474,24 @@ sign_nested() {
452
474
 
453
475
  # 换主 id 时扩展的 id 要跟着换,真签要求 appex id 以主 app id 开头
454
476
  retag_appex() {
455
- local app="$1" bid="$2" x eid base
477
+ local app="$1" bid="$2" x eid pre
478
+ # 用扩展自己的 bundle 名,不取旧 id 的最后一段:两个扩展末段同名会撞 id。
479
+ # Watch 里的扩展要挂在 watchkitapp 下面。
480
+ while IFS= read -r x; do
481
+ eid="$(plist_get "$x" CFBundleIdentifier)"
482
+ [ -n "$eid" ] || continue
483
+ case "$x" in
484
+ */Watch/*) pre="$bid.watchkitapp" ;;
485
+ *) pre="$bid" ;;
486
+ esac
487
+ plist_set "$x" "CFBundleIdentifier=$pre.$(basename "$x" .appex)"
488
+ done < <(find "$app" -name '*.appex' -type d 2>/dev/null)
489
+ # Watch/<x>.app 自己也是一个要真签的包,id 得跟着主 app 走
456
490
  while IFS= read -r x; do
457
491
  eid="$(plist_get "$x" CFBundleIdentifier)"
458
492
  [ -n "$eid" ] || continue
459
- base="${eid##*.}"
460
- plist_set "$x" "CFBundleIdentifier=$bid.$base"
461
- done < <(find "$app/PlugIns" -maxdepth 2 -name '*.appex' -type d 2>/dev/null)
493
+ plist_set "$x" "CFBundleIdentifier=$bid.watchkitapp"
494
+ done < <(find "$app" -path '*/Watch/*.app' -type d 2>/dev/null)
462
495
  }
463
496
 
464
497
  cmd_resign() {
package/scripts/ipa.ps1 CHANGED
@@ -60,8 +60,14 @@ function U32-At($b, $o, $be) {
60
60
  return [uint32](((($v -band 0xFF) -shl 24) -bor (($v -band 0xFF00) -shl 8) -bor (($v -band 0xFF0000) -shr 8) -bor (($v -band 0xFF000000) -shr 24)))
61
61
  }
62
62
  function U64-At($b, $o, $be) {
63
- $lo = U32-At $b $o (-not $be)
64
- $hi = U32-At $b ($o + 4) (-not $be)
63
+ # 大端时前 4 字节是高 32 位;小端时前 4 字节才是低 32 位
64
+ if ($be) {
65
+ $hi = U32-At $b $o $true
66
+ $lo = U32-At $b ($o + 4) $true
67
+ } else {
68
+ $lo = U32-At $b $o $false
69
+ $hi = U32-At $b ($o + 4) $false
70
+ }
65
71
  return ([uint64]$hi -shl 32) -bor [uint64]$lo
66
72
  }
67
73
 
@@ -535,6 +541,10 @@ function Cmd-Build($argv) {
535
541
  $expectPath = ($pathOpts -contains $a)
536
542
  }
537
543
  $cmd = $parts -join ' '
544
+ # wsl.exe 默认不把 Windows 的环境变量带进 bash,密码按推荐方式放 env 的话
545
+ # 转发时会变成空串,所以这里显式前置进去
546
+ $wpass = Get-Pass $opt
547
+ if ($wpass) { $cmd = 'IPA_CERT_PASSWORD=' + (Q $wpass) + ' ' + $cmd }
538
548
  & wsl.exe bash -lc $cmd
539
549
  exit $LASTEXITCODE
540
550
  }