Quantcast
Channel: Essence Sharing | 干货分享 - iOSRE
Viewing all articles
Browse latest Browse all 301

记踩上codesign的一个仍未修复的远古bug

$
0
0

@Aimer wrote:

tl;dr

codesign --remove-signature 在删除代码签名之后没有修复MachO Header的偏移,导致生成的MachO文件畸形。我很确定应该有无数人踩过这个坑,自己研究一遍权当练习

正文

以Dash为例,操作之后的app打开直接crash,以lldb file后报warning:


warning: (x86_64) /Applications/Dash.app/Contents/MacOS/Dash load command 3 LC_SEGMENT_64 has a fileoff + filesize (0x335ed0) that extends beyond the end of the file (0x335ec4), the segment will be truncated to match
Current executable set to '/Applications/Dash.app/Contents/MacOS/Dash' (x86_64).

用MachOView打开可执行文件,定位到最后一个LC_SEGMENT:


简单的做下数学验证: 0x31D000+0x18ED0=0x335ED0,比文件实际大小0x335ec4大出0x335ED0-0x335ec4=0xC

将原来的File Size 减少0xC,改为0x18ec4,保存

这里正确的做法是根据原版的LC_CODE_SIGNATURE计算正确的新大小而不是无脑修改到文件末尾, 只不过对于我们的使用需求而言这么做足够了

结论

Posts: 6

Participants: 5

Read full topic


Viewing all articles
Browse latest Browse all 301

Trending Articles