首页
社区
课程
招聘
[已解决] [求助]关于ld linker weak类型dylibs和file-type类型为bundle的处理? 200.00雪花
发表于: 2023-2-24 11:47 7554

[已解决] [求助]关于ld linker weak类型dylibs和file-type类型为bundle的处理? 200.00雪花

2023-2-24 11:47
7554

各位好:
我求助的问题是这样的,现在有个IPA进来,macho是带bitcode,我需要把bitcode中的明文加密后重新编译成可执行文件打包成IPA。明文加密的问题我已经处理了,已经编译成了.o文件,现在是卡在把各个.o link起来,在调ld处理的时候,因为有Swift的库没成功。我弄了个demo来测试,我的操作步骤是这样的:

 

1 通过以下几步,汇出xml,提取bitcode

1
2
3
4
5
6
7
segedit -extract __LLVM __bundle bundle SwiftPr
 
xar -d toc.xml -f bundle
 
mkdir bundle.extract
 
xar -x -C bundle.extract -f bundle

2 通过xml中的编译参数将各个bitcode编译成.o,这里因为toc.xml <toc><file>里有bundle类型的文件,这几个bundle类型的文件能通过步骤1解出来几千个bc文件,我没搞明白这些bundle文件要怎么处理,只处理了file-type为bitcode的文件:

OC的操作:

1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang  -cc1 -triple arm64-apple-ios12.0.0 -emit-obj --mrelax-relocations -target-sdk-version=15.5 -fvisibility-inlines-hidden-static-local-var -fno-rounding-math -target-abi darwinpcs -Os   bundle.extract/01 -o bundle.extract/01.o -x ir


Swift的操作,将bitcode文件先改成.bc格式:

1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend  -emit-object -target arm64-apple-ios12.0.0 -Xllvm -aarch64-use-tbi -O -disable-llvm-optzns -module-name Kingfisher bundle.extract/03.bc -o bundle.extract/03.o

3 链接.o文件,xml中列出了libswiftsimd.tbd等库但在本地没有,我就拼了系统的路径,这一步走不下去了:

1
/usr/bin/ld  -arch arm64 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/libc++.1.dylib /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/libresolv.9.dylib /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/libz.1.dylib /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Accelerate.framework/Accelerate /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/CFNetwork.framework/CFNetwork /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/CoreData.framework/CoreData /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/CoreGraphics.framework/CoreGraphics /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/CoreImage.framework/CoreImage /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/CoreLocation.framework/CoreLocation /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/CoreText.framework/CoreText /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Foundation.framework/Foundation /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/GLKit.framework/GLKit /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/ImageIO.framework/ImageIO /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Metal.framework/Metal /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/OpenGLES.framework/OpenGLES /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/QuartzCore.framework/QuartzCore /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/UIKit.framework/UIKit /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Accounts.framework/Accounts /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/AudioToolbox.framework/AudioToolbox /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Security.framework/Security /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/Social.framework/Social /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/libobjc.A.dylib /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/libSystem.B.dylib /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftDataDetection.dylib /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/lib/swift/libswiftFileProvider.dylib -execute -platform_version ios 12.0 15.5 -e _main -rpath /usr/lib/swift -rpath /usr/lib/swift -rpath @executable_path/Frameworks -rpath @loader_path/Frameworks -rpath @executable_path/Frameworks -executable_path /Users/nesun/Library/Developer/Xcode/DerivedData/SwiftPr-btxovoqazalvfpcuzpdfsgvbadpm/Build/Intermediates.noindex/ArchiveIntermediates/SwiftPr/InstallationBuildProductsLocation/Applications/SwiftPr.app/SwiftPr -dead_strip /Payload/SwiftPr.app/Frameworks/Alamofire.framework /Payload/SwiftPr.app/Frameworks/AliyunOSSiOS.framework /Payload/SwiftPr.app/Frameworks/CryptoSwift.framework /Payload/SwiftPr.app/Frameworks/FBSDKCoreKit.framework /Payload/SwiftPr.app/Frameworks/FBSDKShareKit.framework /Payload/SwiftPr.app/Frameworks/FDFullscreenPopGesture.framework /Payload/SwiftPr.app/Frameworks/MJRefresh.framework /Payload/SwiftPr.app/Frameworks/Moya.framework /Payload/SwiftPr.app/Frameworks/Moya_ObjectMapper.framework /Payload/SwiftPr.app/Frameworks/ObjectMapper.framework /Payload/SwiftPr.app/Frameworks/ReactiveSwift.framework /Payload/SwiftPr.app/Frameworks/RxSwift.framework /Payload/SwiftPr.app/Frameworks/libswiftCore.dylib /Payload/SwiftPr.app/Frameworks/libswiftCoreFoundation.dylib /Payload/SwiftPr.app/Frameworks/libswiftCoreGraphics.dylib /Payload/SwiftPr.app/Frameworks/libswiftCoreImage.dylib /Payload/SwiftPr.app/Frameworks/libswiftDarwin.dylib /Payload/SwiftPr.app/Frameworks/libswiftDispatch.dylib /Payload/SwiftPr.app/Frameworks/libswiftFoundation.dylib /Payload/SwiftPr.app/Frameworks/libswiftMetal.dylib /Payload/SwiftPr.app/Frameworks/libswiftObjectiveC.dylib /Payload/SwiftPr.app/Frameworks/libswiftQuartzCore.dylib /Payload/SwiftPr.app/Frameworks/libswiftUIKit.dylib -syslibroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk -o bundle.extract/SwiftPr bundle.extract/01.o bundle.extract/02.o bundle.extract/03.o bundle.extract/08.o bundle.extract/09.o bundle.extract/10.o bundle.extract/11.o bundle.extract/12.o

报错:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

ld: warning: Could not find or use auto-linked library 'swift_Concurrency'
ld: warning: Could not find or use auto-linked library 'swiftDispatch'
ld: warning: Could not find or use auto-linked library 'swiftQuartzCore'
ld: warning: Could not find or use auto-linked library 'swiftos'
ld: warning: Could not find or use auto-linked library 'swiftCoreGraphics'
ld: warning: Could not find or use auto-linked library 'swiftUIKit'
ld: warning: Could not find or use auto-linked library 'swiftCompatibilityConcurrency'
ld: warning: Could not find or use auto-linked library 'swiftDarwin'
ld: warning: Could not find or use auto-linked library 'swiftMetal'
ld: warning: Could not find or use auto-linked library 'swiftObjectiveC'
ld: warning: Could not find or use auto-linked library 'swiftDataDetection'
ld: warning: Could not find or use auto-linked library 'swiftCoreLocation'
ld: warning: Could not find or use auto-linked library 'swiftAccelerate'
ld: warning: Could not find or use auto-linked library 'swiftAVFoundation'
ld: warning: Could not find or use auto-linked library 'swiftCore'
ld: warning: Could not find or use auto-linked library 'swiftFoundation'
ld: warning: Could not find or use auto-linked library 'swiftCoreMedia'
ld: warning: Could not find or use auto-linked library 'swiftCoreData'
ld: warning: Could not find or use auto-linked library 'swiftFileProvider'
ld: warning: Could not find or use auto-linked library 'swiftMapKit'
ld: warning: Could not find or use auto-linked library 'swiftCoreAudio'
ld: warning: Could not find or use auto-linked library 'swiftCoreFoundation'
ld: warning: Could not find or use auto-linked library 'swiftCompatibility51'
ld: warning: Could not find or use auto-linked library 'swiftsimd'
ld: warning: Could not find or use auto-linked library 'swiftUniformTypeIdentifiers'
ld: warning: Could not find or use auto-linked library 'swiftCoreMIDI'
ld: warning: Could not find or use auto-linked library 'swiftCarPlay'
ld: warning: Could not find or use auto-linked library 'swiftCompatibility50'
ld: warning: Could not find or use auto-linked library 'swiftCoreImage'
ld: warning: Could not find or use auto-linked library 'swiftCompatibilityDynamicReplacements'
Undefined symbols for architecture arm64:
  "___isPlatformVersionAtLeast", referenced from:
 _$s10Kingfisher15ImageDownloaderC21createDownloadContext33_1CBBE1CEF600480D48F123F40F117AB5LL4with7options4doney10Foundation3URLV_AA0A17ParsedOptionsInfoVys6ResultOyAC011DownloadingF0VAA0A5ErrorOGctF in 23.o
      _$s10Kingfisher0A7WrapperVAASo11UIImageViewCRbzlE13indicatorTypeAA09IndicatorF0Ovs in 32.o
      __hidden#7229_ in 42.o
ld: symbol(s) not found for architecture arm64
 
ld: can't map file, errno=22 file '/Payload/SwiftPr.app/Frameworks/Alamofire.framework' for architecture arm64

请问是在第3步链接阶段搞错了什么吗?这里我做过的尝试是测试了toc.xml参数里几个<weak>类型的库前面加类似-weak_library等参数都失败了。

4 另外toc.xml中file-type有bundle类型的文件,这种文件应该如何处理?我试过ld bundle的几个参数,没效果。对ld不熟,看ld64的代码看的头晕。是像上面的步骤一样解出来编译成.o,然后拼在bundle.extract/12.o后面一起ld?

 

相关的文件放在这里:https://www.aliyundrive.com/s/zE2QWecytsb


[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)

收藏
免费 0
支持
分享
最新回复 (1)
雪    币: 136
活跃值: (549)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
2
邮件已回复
2023-3-13 19:04
0
游客
登录 | 注册 方可回帖
返回
//