Skip to content

Commit 22c739f

Browse files
committed
Local database works now
1 parent 2f2f26e commit 22c739f

4 files changed

Lines changed: 57 additions & 56 deletions

File tree

Makefile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ $(APPLICATION_NAME)_CODESIGN_FLAGS = -Sentitlements.plist -Icom.apple.springboar
3131

3232
include $(THEOS_MAKE_PATH)/application.mk
3333

34-
before-package-sim::
34+
before-package::
3535
@# can't use simforge now
36-
@vtool -arch arm64 -set-build-version 7 14.0 14.0 -replace -output $(THEOS_STAGING_DIR)/Applications/SpringBoard.app/SpringBoard $(THEOS_STAGING_DIR)/Applications/SpringBoard.app/SpringBoard
37-
@vtool -arch arm64 -set-build-version 7 14.0 14.0 -replace -output $(THEOS_STAGING_DIR)/Applications/SpringBoard.app/SpringBoardTweak.dylib $(THEOS_STAGING_DIR)/Applications/SpringBoard.app/SpringBoardTweak.dylib
38-
@vtool -arch arm64 -set-build-version 7 14.0 14.0 -replace -output $(THEOS_STAGING_DIR)/Applications/SpringBoard.app/Frameworks/CydiaSubstrate.framework/CydiaSubstrate $(THEOS_STAGING_DIR)/Applications/SpringBoard.app/Frameworks/CydiaSubstrate.framework/CydiaSubstrate
39-
@ldid -S -M $(THEOS_STAGING_DIR)/Applications/SpringBoard.app
36+
@if [[ "$(SIMULATOR)" == 1 ]]; then \
37+
vtool -arch arm64 -set-build-version 7 14.0 14.0 -replace -output $(THEOS_STAGING_DIR)/Applications/SpringBoard.app/SpringBoard $(THEOS_STAGING_DIR)/Applications/SpringBoard.app/SpringBoard; \
38+
vtool -arch arm64 -set-build-version 7 14.0 14.0 -replace -output $(THEOS_STAGING_DIR)/Applications/SpringBoard.app/SpringBoardTweak.dylib $(THEOS_STAGING_DIR)/Applications/SpringBoard.app/SpringBoardTweak.dylib; \
39+
vtool -arch arm64 -set-build-version 7 14.0 14.0 -replace -output $(THEOS_STAGING_DIR)/Applications/SpringBoard.app/Frameworks/CydiaSubstrate.framework/CydiaSubstrate $(THEOS_STAGING_DIR)/Applications/SpringBoard.app/Frameworks/CydiaSubstrate.framework/CydiaSubstrate; \
40+
ldid -S -M $(THEOS_STAGING_DIR)/Applications/SpringBoard.app; \
41+
fi

Tweak.x

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,13 @@ typedef void (^LSBundleProxyHandler)(LSBundleProxy *proxy, BOOL *stop);
292292
- (void *)_perThreadContextsLock_createPerThreadContextForThisThread;
293293
@end
294294
%hook LSDBExecutionContext
295+
- (void *)_perThreadContextsLock_createPerThreadContextForThisThread {
296+
void *context = self._perThreadContextsLock_findPerThreadContextForThisThreadIfExists;
297+
if(context) {
298+
return context;
299+
}
300+
return %orig;
301+
}
295302
- (void *)_perThreadContextsLock_findPerThreadContextForThisThread {
296303
void *context = self._perThreadContextsLock_findPerThreadContextForThisThreadIfExists;
297304
if(context) {

hook.m

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ @implementation _LSDefaultsHook
7171
- (NSURL *)databaseContainerDirectoryURL {
7272
static NSURL *dbContainerURL = nil;
7373
if(!dbContainerURL) {
74-
NSURL *rootDocURL = [[NSClassFromString(@"LCSharedUtils") appGroupPath] URLByAppendingPathComponent:@"LiveContainer"];
74+
// Use Documents dir for ease of access
75+
NSURL *rootDocURL = nil;
76+
//[[NSClassFromString(@"LCSharedUtils") appGroupPath] URLByAppendingPathComponent:@"LiveContainer"];
7577
if(!rootDocURL) {
7678
rootDocURL = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%s/Documents", getenv("LC_HOME_PATH")]];
7779
}
@@ -143,21 +145,57 @@ - (NSURL *)specialAppEligibilityStateURL {
143145
- (NSURL *)defaultAppQueryStateURL {
144146
return [self.databaseContainerDirectoryURL URLByAppendingPathComponent:@"DefaultAppQueryState.plist"];
145147
}
148+
@end
146149

150+
@interface MIExecutableBundleHook : NSObject
151+
@end
152+
@implementation MIExecutableBundleHook
153+
- (BOOL)needsDataContainer {
154+
// guest apps don't have entitlements so it will fail if we return YES
155+
return NO;
156+
}
147157
@end
148158

149-
__attribute__((constructor)) void SwizzleLSDDefaults(void) {
150-
Class lsdClass = NSClassFromString(@"_LSDefaults");
159+
@interface MIGlobalConfiguration : NSObject
160+
@end
161+
@interface MIGlobalConfigurationHook : NSObject
162+
@end
163+
@implementation MIGlobalConfigurationHook
164+
/*
165+
- (BOOL)hasInternalContent {
166+
return YES;
167+
}
168+
- (NSURL *)internalAppsDirectory {
169+
// returns private apps directory
170+
return [NSURL fileURLWithPath:[NSString stringWithFormat:@"%s/Documents/Applications", getenv("LC_HOME_PATH")]];
171+
}
172+
*/
173+
- (NSURL *)systemAppsDirectory {
174+
NSURL *appGroupPath = [[NSClassFromString(@"LCSharedUtils") appGroupPath] URLByAppendingPathComponent:@"LiveContainer/Applications"];
175+
if(appGroupPath) {
176+
return appGroupPath;
177+
}
178+
return [NSURL fileURLWithPath:@"/Applications"];
179+
}
180+
@end
181+
182+
static void ReplaceMethods(Class origClass, Class newClass) {
151183
uint32_t mc = 0;
152-
Method *mlist = class_copyMethodList(_LSDefaultsHook.class, &mc);
184+
Method *mlist = class_copyMethodList(newClass, &mc);
153185
for(uint32_t i = 0; i < mc; i++) {
154186
Method swizzledMethod = mlist[i];
155-
Method originalMethod = class_getInstanceMethod(lsdClass, method_getName(swizzledMethod));
187+
Method originalMethod = class_getInstanceMethod(origClass, method_getName(swizzledMethod));
156188
method_setImplementation(originalMethod, method_getImplementation(swizzledMethod));
157189
}
158190
free(mlist);
159191
}
160192

193+
__attribute__((constructor)) void SwizzleLSDDefaults(void) {
194+
ReplaceMethods(NSClassFromString(@"_LSDefaults"), _LSDefaultsHook.class);
195+
ReplaceMethods(NSClassFromString(@"MIExecutableBundle"), MIExecutableBundleHook.class);
196+
ReplaceMethods(NSClassFromString(@"MIGlobalConfiguration"), MIGlobalConfigurationHook.class);
197+
}
198+
161199
#if 0
162200

163201
@implementation _LSApplicationRecordEnumerator

main.m

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -23,49 +23,6 @@ bool hook_os_variant_has_internal_content(const char* subsystem) {
2323
return NULL;
2424
}
2525

26-
void SBLCRegisterInstalledApps(void) {
27-
static NSMutableArray *installedApps = nil;
28-
installedApps = [NSMutableArray array];
29-
NSURL *docPath = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%s/Documents/Applications", getenv("LC_HOME_PATH")]];
30-
NSURL *appGroupPath = [[NSClassFromString(@"LCSharedUtils") appGroupPath] URLByAppendingPathComponent:@"LiveContainer/Applications"];
31-
32-
LSApplicationWorkspace *workspace = [NSClassFromString(@"LSApplicationWorkspace") defaultWorkspace];
33-
NSFileManager *fileManager = [NSFileManager defaultManager];
34-
NSMutableArray *apps = [fileManager contentsOfDirectoryAtURL:docPath includingPropertiesForKeys:@[NSURLIsDirectoryKey]
35-
options:NSDirectoryEnumerationSkipsHiddenFiles error:nil].mutableCopy;
36-
if(appGroupPath) {
37-
NSArray *sharedApps = [fileManager contentsOfDirectoryAtURL:appGroupPath includingPropertiesForKeys:@[NSURLIsDirectoryKey]
38-
options:NSDirectoryEnumerationSkipsHiddenFiles error:nil];
39-
[apps addObjectsFromArray:sharedApps];
40-
}
41-
for (NSURL *url in apps) {
42-
if (![url.pathExtension isEqualToString:@"app"]) continue;
43-
// TODO: handle hidden apps?
44-
NSDictionary *infoPlist = [NSDictionary dictionaryWithContentsOfURL:[url URLByAppendingPathComponent:@"Info.plist"]];
45-
NSString *bundleID = infoPlist[@"CFBundleIdentifier"];
46-
[workspace registerApplicationDictionary:@{
47-
@"ApplicationType": @"System",
48-
@"CFBundleIdentifier": bundleID,
49-
@"CodeInfoIdentifier": bundleID,
50-
@"CompatibilityState": @0,
51-
@"IsContainerized": @(YES),
52-
@"EnvironmentVariables": @{},
53-
@"IsDeletable": @(NO),
54-
@"Path": url.path,
55-
@"SignerOrganization": @"Apple Inc.",
56-
@"SignatureVersion": @0x20500,
57-
@"SignerIdentity": @"Apple iPhone OS Application Signing",
58-
@"IsAdHocSigned": @YES,
59-
@"LSInstallType": @1,
60-
@"HasMIDBasedSINF": @0,
61-
@"MissingSINF": @0,
62-
@"FamilyID": @0,
63-
@"IsOnDemandInstallCapable": @0,
64-
@"HasAppGroupContainers": @YES
65-
}];
66-
}
67-
}
68-
6926
int (*SBSystemAppMain)(int argc, char *argv[], char *envp[]);
7027
int main(int argc, char *argv[], char *envp[]) {
7128
// initialize lsd
@@ -104,9 +61,6 @@ int main(int argc, char *argv[], char *envp[]) {
10461
abort();
10562
}
10663

107-
// register installed apps, can only be done after loading SpringBoardTweak
108-
SBLCRegisterInstalledApps();
109-
11064
dlopen("/var/jb/usr/lib/TweakInject/FLEXing.dylib", RTLD_GLOBAL|RTLD_NOW);
11165
SBSystemAppMain = dlsym(handle, "SBSystemAppMain");
11266
return SBSystemAppMain(argc, argv, envp);

0 commit comments

Comments
 (0)