gpt4 book ai didi

macos - SMJobBless.py 脚本在 M1 Mac 上不起作用

转载 作者:行者123 更新时间:2023-12-05 04:42:54 24 4
gpt4 key购买 nike

SMJobBlessUtil.py脚本(Apple 提供用于设置/检查特权帮助工具与其主应用程序之间的配对)在 M1 Mac 上不起作用。

$ ./SMJobBlessUtil.py check MyApp.app

/Users/Alex/MyApp.app/Contents/Library/LaunchServices/ca.momchilov.MyApp.helper: tool __TEXT / __info_plist section dump malformed (2)

我已经在 rdar://FB9726189 下提交了错误报告,您可以在 Open Radar 上看到:https://openradar.appspot.com/radar?id=5006748255518720

最佳答案

我通过在整个脚本中调用 traceback.print_exc() 来调试它,因为它的默认行为不打印堆栈跟踪。

它应该如何运作

问题源于 readPlistFromToolSection 函数,它使用了 otool从辅助工具的可执行文件(它是 Mach-O 文件,分为许多部分。其中一些部分是嵌入式 plist 文件)中读取一些部分。

它调用:

$ otool -s __TEXT __info_plist <YOUR_APP>/Contents/Library/LaunchServices/<YOUR_HELPER_TOOL>

(它还为 __launchd_plist 调用了一个类似的变体)

在为 x86( native 或通过 Rosetta)编译的工具上运行此工具会得到如下结果:

./your_helper_tool:
Contents of (__TEXT,__info_plist) section
0000000100003b8a 3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31
0000000100003b9a 2e 30 22 20 65 6e 63 6f 64 69 6e 67 3d 22 55 54
0000000100003baa 46 2d 38 22 3f 3e 0a 3c 21 44 4f 43 54 59 50 45
0000000100003bba 20 70 6c 69 73 74 20 50 55 42 4c 49 43 20 22 2d
0000000100003bca 2f 2f 41 70 70 6c 65 2f 2f 44 54 44 20 50 4c 49
0000000100003bda 53 54 20 31 2e 30 2f 2f 45 4e 22 20 22 68 74 74
0000000100003bea 70 3a 2f 2f 77 77 77 2e 61 70 70 6c 65 2e 63 6f
0000000100003bfa 6d 2f 44 54 44 73 2f 50 72 6f 70 65 72 74 79 4c
0000000100003c0a 69 73 74 2d 31 2e 30 2e 64 74 64 22 3e 0a 3c 70
0000000100003c1a 6c 69 73 74 20 76 65 72 73 69 6f 6e 3d 22 31 2e
0000000100003c2a 30 22 3e 0a 3c 64 69 63 74 3e 0a 09 3c 6b 65 79
0000000100003c3a 3e 43 46 42 75 6e 64 6c 65 49 64 65 6e 74 69 66
0000000100003c4a 69 65 72 3c 2f 6b 65 79 3e 0a 09 3c 73 74 72 69
0000000100003c5a 6e 67 3e 63 61 2e 6d 6f 6d 63 68 69 6c 6f 76 2e
0000000100003c6a 44 65 6d 6f 2d 50 72 69 76 69 6c 65 67 65 64 2d
0000000100003c7a 48 65 6c 70 65 72 2d 41 70 70 2e 68 65 6c 70 65
0000000100003c8a 72 3c 2f 73 74 72 69 6e 67 3e 0a 09 3c 6b 65 79
0000000100003c9a 3e 43 46 42 75 6e 64 6c 65 49 6e 66 6f 44 69 63
0000000100003caa 74 69 6f 6e 61 72 79 56 65 72 73 69 6f 6e 3c 2f
0000000100003cba 6b 65 79 3e 0a 09 3c 73 74 72 69 6e 67 3e 36 2e
0000000100003cca 30 3c 2f 73 74 72 69 6e 67 3e 0a 09 3c 6b 65 79
0000000100003cda 3e 43 46 42 75 6e 64 6c 65 4e 61 6d 65 3c 2f 6b
0000000100003cea 65 79 3e 0a 09 3c 73 74 72 69 6e 67 3e 44 65 6d
0000000100003cfa 6f 50 72 69 76 69 6c 65 67 65 64 48 65 6c 70 65
0000000100003d0a 72 3c 2f 73 74 72 69 6e 67 3e 0a 09 3c 6b 65 79
0000000100003d1a 3e 43 46 42 75 6e 64 6c 65 56 65 72 73 69 6f 6e
0000000100003d2a 3c 2f 6b 65 79 3e 0a 09 3c 73 74 72 69 6e 67 3e
0000000100003d3a 31 2e 30 3c 2f 73 74 72 69 6e 67 3e 0a 09 3c 6b
0000000100003d4a 65 79 3e 53 4d 41 75 74 68 6f 72 69 7a 65 64 43
0000000100003d5a 6c 69 65 6e 74 73 3c 2f 6b 65 79 3e 0a 09 3c 61
0000000100003d6a 72 72 61 79 3e 0a 09 09 3c 73 74 72 69 6e 67 3e
0000000100003d7a 69 64 65 6e 74 69 66 69 65 72 20 22 63 61 2e 6d
0000000100003d8a 6f 6d 63 68 69 6c 6f 76 2e 44 65 6d 6f 2d 50 72
0000000100003d9a 69 76 69 6c 65 67 65 64 2d 48 65 6c 70 65 72 2d
0000000100003daa 41 70 70 22 20 61 6e 64 20 61 6e 63 68 6f 72 20
0000000100003dba 61 70 70 6c 65 20 67 65 6e 65 72 69 63 20 61 6e
0000000100003dca 64 20 63 65 72 74 69 66 69 63 61 74 65 20 6c 65
0000000100003dda 61 66 5b 73 75 62 6a 65 63 74 2e 43 4e 5d 20 3d
0000000100003dea 20 22 41 70 70 6c 65 20 44 65 76 65 6c 6f 70 6d
0000000100003dfa 65 6e 74 3a 20 61 6c 65 78 61 6e 64 65 72 6d 6f
0000000100003e0a 6d 63 68 69 6c 6f 76 40 67 6d 61 69 6c 2e 63 6f
0000000100003e1a 6d 20 28 4c 43 52 33 32 34 54 51 38 35 29 22 20
0000000100003e2a 61 6e 64 20 63 65 72 74 69 66 69 63 61 74 65 20
0000000100003e3a 31 5b 66 69 65 6c 64 2e 31 2e 32 2e 38 34 30 2e
0000000100003e4a 31 31 33 36 33 35 2e 31 30 30 2e 36 2e 32 2e 31
0000000100003e5a 5d 20 2f 2a 20 65 78 69 73 74 73 20 2a 2f 3c 2f
0000000100003e6a 73 74 72 69 6e 67 3e 0a 09 3c 2f 61 72 72 61 79
0000000100003e7a 3e 0a 3c 2f 64 69 63 74 3e 0a 3c 2f 70 6c 69 73
0000000100003e8a 74 3e 0a

SMJobBlessUtil.py 脚本然后通过以下方式将其处理成 XML plist 文件:

  1. 去掉前两行
  2. 去掉最左边一列的地址(每行 \t 之前的所有内容)
  3. 将每一行按空格分割,得到16对十六进制(每个编码1字节)
  4. 将其转换为 bytearray,然后由 pliSTLib.readPlistFromString 解析

问题

当您在原生 ARM64 编译二进制文件上运行相同的 otool 命令时,问题变得很明显:

./your_helper_tool:
Contents of (__TEXT,__info_plist) section
0000000100003b5a 6d783f3c 6576206c 6f697372 31223d6e
0000000100003b6a 2022302e 6f636e65 676e6964 5455223d
0000000100003b7a 22382d46 3c0a3e3f 434f4421 45505954
0000000100003b8a 696c7020 50207473 494c4255 2d222043
0000000100003b9a 70412f2f 2f656c70 4454442f 494c5020
0000000100003baa 31205453 2f2f302e 20224e45 74746822
0000000100003bba 2f2f3a70 2e777777 6c707061 6f632e65
0000000100003bca 54442f6d 502f7344 65706f72 4c797472
0000000100003bda 2d747369 2e302e31 22647464 703c0a3e
0000000100003bea 7473696c 72657620 6e6f6973 2e31223d
0000000100003bfa 0a3e2230 6369643c 090a3e74 79656b3c
0000000100003c0a 4246433e 6c646e75 65644965 6669746e
0000000100003c1a 3c726569 79656b2f 3c090a3e 69727473
0000000100003c2a 633e676e 6f6d2e61 6968636d 2e766f6c
0000000100003c3a 6f6d6544 6972502d 656c6976 2d646567
0000000100003c4a 706c6548 412d7265 682e7070 65706c65
0000000100003c5a 732f3c72 6e697274 090a3e67 79656b3c
0000000100003c6a 4246433e 6c646e75 666e4965 6369446f
0000000100003c7a 6e6f6974 56797261 69737265 2f3c6e6f
0000000100003c8a 3e79656b 733c090a 6e697274 2e363e67
0000000100003c9a 732f3c30 6e697274 090a3e67 79656b3c
0000000100003caa 4246433e 6c646e75 6d614e65 6b2f3c65
0000000100003cba 0a3e7965 74733c09 676e6972 6d65443e
0000000100003cca 6972506f 656c6976 48646567 65706c65
0000000100003cda 732f3c72 6e697274 090a3e67 79656b3c
0000000100003cea 4246433e 6c646e75 72655665 6e6f6973
0000000100003cfa 656b2f3c 090a3e79 7274733c 3e676e69
0000000100003d0a 3c302e31 7274732f 3e676e69 6b3c090a
0000000100003d1a 533e7965 7475414d 69726f68 4364657a
0000000100003d2a 6e65696c 2f3c7374 3e79656b 613c090a
0000000100003d3a 79617272 09090a3e 7274733c 3e676e69
0000000100003d4a 6e656469 69666974 22207265 6d2e6163
0000000100003d5a 68636d6f 766f6c69 6d65442e 72502d6f
0000000100003d6a 6c697669 64656765 6c65482d 2d726570
0000000100003d7a 22707041 646e6120 636e6120 20726f68
0000000100003d8a 6c707061 65672065 6972656e 6e612063
0000000100003d9a 65632064 66697472 74616369 656c2065
0000000100003daa 735b6661 656a6275 432e7463 3d205d4e
0000000100003dba 70412220 20656c70 65766544 6d706f6c
0000000100003dca 3a746e65 656c6120 646e6178 6f6d7265
0000000100003dda 6968636d 40766f6c 69616d67 6f632e6c
0000000100003dea 4c28206d 32335243 38515434 20222935
0000000100003dfa 20646e61 74726563 63696669 20657461
0000000100003e0a 69665b31 2e646c65 2e322e31 2e303438
0000000100003e1a 36333131 312e3533 362e3030 312e322e
0000000100003e2a 2a2f205d 69786520 20737473 2f3c2f2a
0000000100003e3a 69727473 0a3e676e 612f3c09 79617272
0000000100003e4a 2f3c0a3e 74636964 2f3c0a3e 73696c70
0000000100003e5a 74 3e 0a

字节被分成 4 组,每组颠倒。 IE。而不是预期的格式:

a b c d e f g h i j k l m n o p

你得到:

dcba hgfe lkji ponm

解决方案

我能想到的主要解决方案有两个:

  1. 为 Rosetta 构建您的项目(即使您不打算这样发布它)并对结果使用 SMJobBless.py。如果 check 命令通过检查,我认为可以合理地假设它也将通过原生 ARM 二进制文件。
  2. 修补脚本以修复其解析逻辑。这是我对它的修改,对我有用:
diff --git a/SMJobBlessUtil.py b/SMJobBlessUtil.py
index 1a5dd74ea2900ac2fae10b7448272fe4a7d37c7e..487e022a8ff96b4fb86ffe837dbd758853d680a8 100755
--- a/SMJobBlessUtil.py
+++ b/SMJobBlessUtil.py
@@ -152,16 +152,37 @@ def readPlistFromToolSection(toolPath, segmentName, sectionName):
raise CheckException("tool %s / %s section dump malformed (1)" % (segmentName, sectionName), toolPath)
del plistLines[0:2]

+ # Reshapes an input like "6d783f3c" into an output like "3c 3f 78 6d"
+ def reshape(input):
+ hexit_pairs = [input[i:i+2] for i in range(0, len(input), 2)]
+ hexit_pairs.reverse()
+ return " ".join(hexit_pairs)
+
try:
bytes = []
for line in plistLines:
- # line looks like this:
+ # line should look like this:
#
# '0000000100000b80\t3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 '
+ #
+ # But it actually looks like:
+ # '0000000100003b5a\t6d783f3c 6576206c 6f697372 31223d6e
columns = line.split("\t")
assert len(columns) == 2
- for hexStr in columns[1].split():
+
+ hex_data = columns[1]
+ four_byte_chunks = hex_data.split()
+ # print("four_byte_chunks" + str(four_byte_chunks))
+
+ reshaped = [reshape(four_byte_chunk) for four_byte_chunk in four_byte_chunks]
+ # print("reshaped" + str(reshaped))
+
+ fixed_line = " ".join(reshaped)
+ # print("fixed_line: '" + str(fixed_line) + "'")
+
+ for hexStr in fixed_line.split():
bytes.append(int(hexStr, 16))
+
plist = plistlib.readPlistFromString(bytearray(bytes))
except:
raise CheckException("tool %s / %s section dump malformed (2)" % (segmentName, sectionName), toolPath)

关于macos - SMJobBless.py 脚本在 M1 Mac 上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69746635/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com