├── .gitignore ├── LICENSE.md ├── Makefile ├── README.md ├── control ├── entitlements.plist └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | .theos/ 2 | packages/ 3 | .DS_Store 4 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Lars Fröder 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TARGET := iphone:clang:14.5:7.0 2 | ARCHS = armv7 arm64 3 | 4 | include $(THEOS)/makefiles/common.mk 5 | 6 | TOOL_NAME = slice_fixup 7 | 8 | slice_fixup_FILES = main.m 9 | slice_fixup_CFLAGS = -fobjc-arc 10 | slice_fixup_CODESIGN_FLAGS = -Sentitlements.plist 11 | slice_fixup_INSTALL_PATH = /usr/local/bin 12 | 13 | include $(THEOS_MAKE_PATH)/tool.mk 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SliceFixup 2 | 3 | ## Problem 4 | 5 | The arm64e ABI was changed in iOS 14 (Xcode 12) and therefore any arm64e dylib compiled with Xcode 12 or newer does not support iOS 13. The old ABI was upwards compatible so for the longest time people were just compiling their dylibs with Xcode 11. This changed in iOS 15 now however, there are now issues with loading old ABI slices into new ABI processes. For whatever reason most dylibs still work fine, but one of mine (CraneSupport.dylib) was not working. 6 | 7 | Back in the iOS 14 days, before I discovered the old ABI was upwards compatible, I made a script that uses a patched lipo to join together a slice of both the old and new arm64e ABIs. Now that this script is actually needed I tested it some more and discovered that dyld would always prefer the old ABI slice over the new ABI slice, which means that having the old slice in the binary always also breaks iOS 15. 8 | 9 | ## Solution 10 | 11 | SliceFixup is a tool that, based on the iOS version it's running on, removes the incompatible arm64e slice, so that the outcome is a dylib that only has the supported slice in it, so everything works fine. It is supposed to be called in the `postinst` on all of the dylibs that require this fix (e.g. all dylibs that need to inject into an arm64e process). It does this by only removing the slice from the FAT header, so the actual slice is still in the binary, it's just not found. 12 | 13 | Before you can use this tool, you need to setup something like [plipo_package.sh](https://github.com/opa334/CCSupport/blob/74762743acb839fcdcaeb61785fa54662b860542/plipo_package.sh) to have both an Xcode 11 and an Xcode 12+ slice in your dylibs. 14 | -------------------------------------------------------------------------------- /control: -------------------------------------------------------------------------------- 1 | Package: com.opa334.slicefixup 2 | Name: Slice Fixup 3 | Version: 1.0 4 | Architecture: iphoneos-arm 5 | Description: Removes incompatible arm64e slice from dylibs 6 | Maintainer: opa334 7 | Author: opa334 8 | Section: System 9 | Tag: role::hacker 10 | -------------------------------------------------------------------------------- /entitlements.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | platform-application 5 | 6 | com.apple.private.security.container-required 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /main.m: -------------------------------------------------------------------------------- 1 | #include 2 | #import 3 | #import 4 | #import 5 | #import 6 | #import 7 | 8 | void printUsage(void) 9 | { 10 | printf("Usage: slice_fixup \n"); 11 | } 12 | 13 | void removeSlice(NSString* binaryPath, cpu_type_t cputypeToRemove, cpu_subtype_t cpusubtypeToRemove) 14 | { 15 | FILE* machoFile = fopen(binaryPath.fileSystemRepresentation, "rb+"); 16 | if(!machoFile) 17 | { 18 | printf("ERROR: file %s does not exist\n", binaryPath.fileSystemRepresentation); 19 | } 20 | 21 | struct mach_header header; 22 | fread(&header,sizeof(header),1,machoFile); 23 | 24 | if(header.magic == FAT_MAGIC || header.magic == FAT_CIGAM) 25 | { 26 | fseek(machoFile,0,SEEK_SET); 27 | struct fat_header fatHeader; 28 | fread(&fatHeader,sizeof(fatHeader),1,machoFile); 29 | 30 | size_t fatTableSize = sizeof(struct fat_arch) * OSSwapBigToHostInt32(fatHeader.nfat_arch); 31 | char* newFatTable = malloc(fatTableSize); 32 | memset(&newFatTable[0], 0, fatTableSize); 33 | int newFatI = 0; 34 | 35 | for(int i = 0; i < OSSwapBigToHostInt32(fatHeader.nfat_arch); i++) 36 | { 37 | uint32_t archFileOffset = sizeof(fatHeader) + sizeof(struct fat_arch) * i; 38 | struct fat_arch fatArch; 39 | fseek(machoFile, archFileOffset,SEEK_SET); 40 | fread(&fatArch,sizeof(fatArch),1,machoFile); 41 | 42 | if(OSSwapBigToHostInt32(fatArch.cputype) != cputypeToRemove || OSSwapBigToHostInt32(fatArch.cpusubtype) != cpusubtypeToRemove) 43 | { 44 | memcpy(&newFatTable[sizeof(struct fat_arch) * newFatI], &fatArch, sizeof(struct fat_arch)); 45 | newFatI++; 46 | } 47 | } 48 | 49 | if(OSSwapBigToHostInt32(fatHeader.nfat_arch) != newFatI) 50 | { 51 | fseek(machoFile,0,SEEK_SET); 52 | fatHeader.nfat_arch = OSSwapHostToBigInt32(newFatI); 53 | fwrite(&fatHeader, sizeof(fatHeader), 1, machoFile); 54 | fwrite(&newFatTable[0], fatTableSize, 1, machoFile); 55 | } 56 | 57 | free(newFatTable); 58 | } 59 | 60 | fclose(machoFile); 61 | } 62 | 63 | int main(int argc, char *argv[], char *envp[]) { 64 | @autoreleasepool { 65 | if(argc != 2) 66 | { 67 | printUsage(); 68 | return 0; 69 | } 70 | 71 | NSString* dylibPath = [NSString stringWithUTF8String:argv[1]]; 72 | 73 | cpu_type_t cputypeToRemove = 0x100000C; 74 | cpu_type_t cpusubtypeToRemove; 75 | if(kCFCoreFoundationVersionNumber >= kCFCoreFoundationVersionNumber_iOS_14_0) 76 | { 77 | cpusubtypeToRemove = 0x00000002; 78 | } 79 | else 80 | { 81 | cpusubtypeToRemove = 0x80000002; 82 | } 83 | 84 | removeSlice(dylibPath, cputypeToRemove, cpusubtypeToRemove); 85 | return 0; 86 | } 87 | } 88 | --------------------------------------------------------------------------------