Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add tvOS support #61

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ jobs:
flags: ""
- name: release
flags: "RELEASE=1"
- name: release-tv
flags: "RELEASE=1 TV=1"
- name: mac
flags: "RELEASE=1 MAC=1"

Expand Down Expand Up @@ -59,7 +61,7 @@ jobs:
name: ${{ matrix.name }} package
path: ${{ github.workspace }}/packages/*
- name: Upload packages to release
if: github.event_name == 'release' && matrix.name == 'release'
if: github.event_name == 'release' && (matrix.name == 'release' || matrix.name == 'release-tv')
uses: svenstaro/[email protected]
with:
file: ${{ github.workspace }}/packages/*.deb
Expand Down
69 changes: 67 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ endif

ifneq ($(MAC),)
COMMON_OPTIONS += -destination 'generic/platform=macOS'
else ifneq ($(TV),)
COMMON_OPTIONS += -destination 'generic/platform=tvOS'
else
COMMON_OPTIONS += -destination 'generic/platform=iOS'
endif

ifneq ($(MAC),)
PRODUCTS_DIR = build/$(CONFIGURATION)
else ifneq ($(TV),)
PRODUCTS_DIR = build/$(CONFIGURATION)-appletvos
else
PRODUCTS_DIR = build/$(CONFIGURATION)-iphoneos
endif
Expand All @@ -49,6 +53,12 @@ build-ios:
xcodebuild -scheme loader $(COMMON_OPTIONS)
xcodebuild -scheme safemode-ui $(COMMON_OPTIONS)

build-tvos:
xcodebuild -scheme ellekit $(COMMON_OPTIONS)
xcodebuild -scheme injector $(COMMON_OPTIONS)
xcodebuild -scheme launchd $(COMMON_OPTIONS)
xcodebuild -scheme loader $(COMMON_OPTIONS)

build-macos:
xcodebuild -scheme ellekit $(COMMON_OPTIONS)
xcodebuild -scheme launchd $(COMMON_OPTIONS)
Expand All @@ -60,6 +70,9 @@ deb-ios-rootful: INSTALL_PREFIX =
deb-ios-rootless: ARCHITECTURE = iphoneos-arm64
deb-ios-rootless: INSTALL_PREFIX = /var/jb

deb-tvos-rootful: ARCHITECTURE = appletvos-arm64
deb-tvos-rootful: INSTALL_PREFIX =

deb-ios-rootful deb-ios-rootless: build-ios
@rm -rf work-$(ARCHITECTURE)
@mkdir -p $(STAGE_DIR)
Expand All @@ -76,7 +89,7 @@ deb-ios-rootful deb-ios-rootless: build-ios

@find $(INSTALL_ROOT)/usr/lib -type f -exec ldid -S {} \;
@ldid -S./loader/taskforpid.xml $(INSTALL_ROOT)/usr/libexec/ellekit/loader

@ln -s $(INSTALL_PREFIX)/usr/lib/ellekit/libinjector.dylib $(INSTALL_ROOT)/usr/lib/TweakLoader.dylib
@ln -s $(INSTALL_PREFIX)/usr/lib/ellekit/libinjector.dylib $(INSTALL_ROOT)/usr/lib/TweakInject.dylib
@ln -s $(INSTALL_PREFIX)/usr/lib/libellekit.dylib $(INSTALL_ROOT)/usr/lib/libsubstrate.dylib
Expand Down Expand Up @@ -105,10 +118,58 @@ deb-ios-rootful deb-ios-rootless: build-ios

@mkdir -p packages
dpkg-deb --root-owner-group -b $(STAGE_DIR) packages/ellekit_$(DEB_VERSION)_$(ARCHITECTURE).deb


@rm -rf work-$(ARCHITECTURE)

deb-tvos-rootful: build-tvos
@rm -rf work-$(ARCHITECTURE)
@mkdir -p $(STAGE_DIR)

@# Because BSD install does not support -D
@mkdir -p $(INSTALL_ROOT)/usr/lib/ellekit
@mkdir -p $(INSTALL_ROOT)/usr/libexec/ellekit

@install -m644 $(PRODUCTS_DIR)/libellekit.dylib $(INSTALL_ROOT)/usr/lib/libellekit.dylib
@install -m644 $(PRODUCTS_DIR)/libinjector.dylib $(INSTALL_ROOT)/usr/lib/ellekit/libinjector.dylib
@install -m644 $(PRODUCTS_DIR)/pspawn.dylib $(INSTALL_ROOT)/usr/lib/ellekit/pspawn.dylib
@install -m755 $(PRODUCTS_DIR)/loader $(INSTALL_ROOT)/usr/libexec/ellekit/loader

@find $(INSTALL_ROOT)/usr/lib -type f -exec ldid -S {} \;
@ldid -S./loader/taskforpid.xml $(INSTALL_ROOT)/usr/libexec/ellekit/loader

@ln -s $(INSTALL_PREFIX)/usr/lib/ellekit/libinjector.dylib $(INSTALL_ROOT)/usr/lib/TweakLoader.dylib
@ln -s $(INSTALL_PREFIX)/usr/lib/ellekit/libinjector.dylib $(INSTALL_ROOT)/usr/lib/TweakInject.dylib
@ln -s $(INSTALL_PREFIX)/usr/lib/libellekit.dylib $(INSTALL_ROOT)/usr/lib/libsubstrate.dylib
@ln -s $(INSTALL_PREFIX)/usr/lib/libellekit.dylib $(INSTALL_ROOT)/usr/lib/libhooker.dylib
@ln -s $(INSTALL_PREFIX)/usr/lib/libellekit.dylib $(INSTALL_ROOT)/usr/lib/libblackjack.dylib

@mkdir -p $(INSTALL_ROOT)/etc/rc.d
@ln -s ${INSTALL_PREFIX}/usr/libexec/ellekit/loader $(INSTALL_ROOT)/etc/rc.d/ellekit-loader

@mkdir -p $(INSTALL_ROOT)/usr/lib/TweakInject

@mkdir -p $(INSTALL_ROOT)/Library/Frameworks/CydiaSubstrate.framework
@ln -s ${INSTALL_PREFIX}/usr/lib/libellekit.dylib $(INSTALL_ROOT)/Library/Frameworks/CydiaSubstrate.framework/CydiaSubstrate
@mkdir -p $(INSTALL_ROOT)/Library/MobileSubstrate
@ln -s ${INSTALL_PREFIX}/usr/lib/TweakInject $(INSTALL_ROOT)/Library/MobileSubstrate/DynamicLibraries

@mkdir -p $(INSTALL_ROOT)/usr/share/doc/ellekit
@install -m644 LICENSE $(INSTALL_ROOT)/usr/share/doc/ellekit/LICENSE

@mkdir -p $(STAGE_DIR)/DEBIAN
@sed -e "s|@DEB_VERSION@|$(DEB_VERSION)|g" -e "s|@DEB_ARCH@|$(ARCHITECTURE)|g" packaging/control >$(STAGE_DIR)/DEBIAN/control
@sed -e "s|@DEB_VERSION@|$(DEB_VERSION)|g" -e "s|@DEB_ARCH@|$(ARCHITECTURE)|g" -e "s|@INSTALL_PREFIX@|$(INSTALL_PREFIX)|g" packaging/preinst >$(STAGE_DIR)/DEBIAN/preinst
@sed -e "s|@DEB_VERSION@|$(DEB_VERSION)|g" -e "s|@DEB_ARCH@|$(ARCHITECTURE)|g" -e "s|@INSTALL_PREFIX@|$(INSTALL_PREFIX)|g" packaging/postinst >$(STAGE_DIR)/DEBIAN/postinst
@sed -e "s|@DEB_VERSION@|$(DEB_VERSION)|g" -e "s|@DEB_ARCH@|$(ARCHITECTURE)|g" -e "s|@INSTALL_PREFIX@|$(INSTALL_PREFIX)|g" packaging/postrm >$(STAGE_DIR)/DEBIAN/postrm
@chmod 0755 $(STAGE_DIR)/DEBIAN/preinst $(STAGE_DIR)/DEBIAN/postinst $(STAGE_DIR)/DEBIAN/postrm

@mkdir -p packages
dpkg-deb --root-owner-group -b $(STAGE_DIR) packages/ellekit_$(DEB_VERSION)_$(ARCHITECTURE).deb

@rm -rf work-$(ARCHITECTURE)

deb-ios: deb-ios-rootful deb-ios-rootless
deb-tvos: deb-tvos-rootful

deb-macos: ARCHITECTURE = macos
deb-macos: build-macos
Expand Down Expand Up @@ -141,12 +202,16 @@ deb-macos: build-macos

ifneq ($(MAC),)
deb: deb-macos
else ifeq ($(TV),1)
deb: deb-tvos
else
deb: deb-ios
endif

ifneq ($(MAC),)
build: build-macos
else ifeq ($(TV),1)
build: build-tvos
else
build: build-ios
endif
36 changes: 32 additions & 4 deletions ellekit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
objects = {

/* Begin PBXBuildFile section */
017796D52BAF2E1D00BCC2C3 /* IOKit.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 017796D42BAF2E1D00BCC2C3 /* IOKit.tbd */; };
017796D62BAF2E2E00BCC2C3 /* IOKit.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 017796D42BAF2E1D00BCC2C3 /* IOKit.tbd */; };
9E12F79229FD528F0021CB75 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9E12F79129FD528F0021CB75 /* Foundation.framework */; platformFilters = (ios, maccatalyst, macos, tvos, watchos, ); };
9E18B4A92A142E8D002E471A /* Trampoline+Location.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E18B4A82A142E8D002E471A /* Trampoline+Location.swift */; };
9E18B4AC2A142EAA002E471A /* Trampoline.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E18B4AB2A142EAA002E471A /* Trampoline.swift */; };
Expand Down Expand Up @@ -102,12 +104,10 @@
9EC2B2DF296B8CAE0079379D /* Load Commands.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E6EBF99296136A300D0D186 /* Load Commands.swift */; };
9EC2B2E1296B96350079379D /* Batch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC2B2E0296B96350079379D /* Batch.swift */; };
9EC2B2E3296C774B0079379D /* button.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9ED5277E29673BC9009319AA /* button.swift */; };
9EC2B2E4296C77610079379D /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9ED5278129673C0F009319AA /* IOKit.framework */; };
9EC2B2E6296C89920079379D /* Replacements.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9EC2B2E5296C89920079379D /* Replacements.swift */; };
9ECAA39229FC61720024CB07 /* JITLess.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9ECAA39129FC61720024CB07 /* JITLess.swift */; };
9ECAA39429FC625F0024CB07 /* JITLess.c in Sources */ = {isa = PBXBuildFile; fileRef = 9ECAA39329FC625F0024CB07 /* JITLess.c */; };
9ED080CA29417AA900A81AF1 /* launchd.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9ED080C929417AA900A81AF1 /* launchd.swift */; };
9ED5278229673C0F009319AA /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9ED5278129673C0F009319AA /* IOKit.framework */; platformFilters = (ios, maccatalyst, macos, tvos, ); };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -162,6 +162,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
017796D42BAF2E1D00BCC2C3 /* IOKit.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = IOKit.tbd; path = ellekitc/IOKit.tbd; sourceTree = "<group>"; };
9E080FA2294AA5A000EDC301 /* lib */ = {isa = PBXFileReference; lastKnownFileType = folder; name = lib; path = ../../../../usr/local/lib; sourceTree = "<group>"; };
9E080FA4294AA5AC00EDC301 /* libes-injector.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = "libes-injector.dylib"; path = "../../../../usr/local/lib/libes-injector.dylib"; sourceTree = "<group>"; };
9E12F78F29FD52860021CB75 /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/System/Library/Frameworks/CoreFoundation.framework; sourceTree = DEVELOPER_DIR; };
Expand Down Expand Up @@ -277,15 +278,15 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9EC2B2E4296C77610079379D /* IOKit.framework in Frameworks */,
017796D62BAF2E2E00BCC2C3 /* IOKit.tbd in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
9ED5278029673C0A009319AA /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
9ED5278229673C0F009319AA /* IOKit.framework in Frameworks */,
017796D52BAF2E1D00BCC2C3 /* IOKit.tbd in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -337,6 +338,7 @@
9E2D4F552938391C00EF6619 /* Frameworks */ = {
isa = PBXGroup;
children = (
017796D42BAF2E1D00BCC2C3 /* IOKit.tbd */,
9E12F79129FD528F0021CB75 /* Foundation.framework */,
9E12F78F29FD52860021CB75 /* CoreFoundation.framework */,
9ED5278129673C0F009319AA /* IOKit.framework */,
Expand Down Expand Up @@ -1135,6 +1137,10 @@
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/ellekitc",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
ONLY_ACTIVE_ARCH = NO;
OTHER_SWIFT_FLAGS = "";
Expand Down Expand Up @@ -1173,6 +1179,10 @@
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/ellekitc",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
ONLY_ACTIVE_ARCH = NO;
OTHER_SWIFT_FLAGS = "";
Expand Down Expand Up @@ -1326,6 +1336,11 @@
KEEP_PRIVATE_EXTERNS = NO;
MACOSX_DEPLOYMENT_TARGET = 10.13;
ONLY_ACTIVE_ARCH = NO;
OTHER_CFLAGS = (
"-U__TVOS_PROHIBITED",
"-U__WATCHOS_PROHIBITED",
);
OTHER_SWIFT_FLAGS = "";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -1360,6 +1375,11 @@
KEEP_PRIVATE_EXTERNS = NO;
MACOSX_DEPLOYMENT_TARGET = 10.13;
ONLY_ACTIVE_ARCH = NO;
OTHER_CFLAGS = (
"-U__TVOS_PROHIBITED",
"-U__WATCHOS_PROHIBITED",
);
OTHER_SWIFT_FLAGS = "";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SKIP_INSTALL = YES;
Expand Down Expand Up @@ -1413,6 +1433,10 @@
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
EXECUTABLE_PREFIX = lib;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/ellekitc",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
Expand All @@ -1434,6 +1458,10 @@
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
EXECUTABLE_PREFIX = lib;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/ellekitc",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = iphoneos;
Expand Down
2 changes: 1 addition & 1 deletion ellekit/API/MobileSubstrate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public func MSFindSymbol(_ image: UnsafeRawPointer?, _ name: UnsafeRawPointer?)
if swiftName.first == "_", let symbol = dlsym(UnsafeMutableRawPointer(mutating: UnsafeRawPointer(hdr)), String(swiftName.dropFirst())) {
return .init(symbol)
}
if #available(iOS 14.0, macOS 11.0, *) {
if #available(iOS 14.0, tvOS 14.0, watchOS 7.0, macOS 11.0, *) {
if _dyld_shared_cache_contains_path(_dyld_get_image_name(img)), let symbol = try? ellekit.findPrivateSymbol(image: hdr, symbol: swiftName) {
return .init(symbol)
}
Expand Down
6 changes: 3 additions & 3 deletions ellekit/ExceptionHandler/Exception.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class ExceptionHandler {
}

#if arch(arm64) || _ptrauth(_arm64e)
if task_set_exception_ports(
if custom_task_set_exception_ports(
mach_task_self_,
exception_mask_t(EXC_MASK_BREAKPOINT),
targetPort,
Expand Down Expand Up @@ -69,7 +69,7 @@ public final class ExceptionHandler {

defer { msg_header.deallocate() }

let krt1 = mach_msg(
let krt1 = custom_mach_msg(
msg_header,
MACH_RCV_MSG | MACH_RCV_LARGE | Int32(MACH_MSG_TIMEOUT_NONE),
0,
Expand Down Expand Up @@ -106,7 +106,7 @@ public final class ExceptionHandler {
reply.NDR = req.NDR
reply.RetCode = KERN_SUCCESS

mach_msg (
custom_mach_msg (
&reply.Head,
1,
reply.Head.msgh_size,
Expand Down
2 changes: 1 addition & 1 deletion ellekit/Languages/C/Trampoline/Trampoline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public struct Trampoline {
var info = Dl_info()
dladdr(base, &info)

if #available(iOS 9999.0, macOS 11.0, *) {
if #available(iOS 9999.0, tvOS 9999.0, watchOS 9999.0, macOS 11.0, *) {
if info.dli_fname != nil && _dyld_shared_cache_contains_path(info.dli_fname) {
print("in dyld cache")
} else {
Expand Down
21 changes: 10 additions & 11 deletions ellekit/Mach-O/Dyld.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,17 @@ public func sharedCachePath() -> String {
#endif
}
#else
if #available(iOS 16.0, *) {
if FileManager.default.fileExists(atPath: "/System/Cryptexes/OS/System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64e") {
return "/System/Cryptexes/OS/System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64e"
} else {
return "/System/Cryptexes/OS/System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64"
}
// We do this as a side effect of forcing iOS libellekit to run on tvOS
// The systemhook will attempt to correct iOS availability into tvOS, but that
// would be wrong here.
if FileManager.default.fileExists(atPath: "/System/Cryptexes/OS/System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64e") {
return "/System/Cryptexes/OS/System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64e"
} else if FileManager.default.fileExists(atPath: "/System/Cryptexes/OS/System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64") {
return "/System/Cryptexes/OS/System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64"
} else if FileManager.default.fileExists(atPath: "/System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64e") {
return "/System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64e"
} else {
if FileManager.default.fileExists(atPath: "/System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64e") {
return "/System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64e"
} else {
return "/System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64"
}
return "/System/Library/Caches/com.apple.dyld/dyld_shared_cache_arm64"
}
#endif
}
Expand Down
Loading
Loading