Skip to content

Commit 463e1aa

Browse files
authored
Merge branch 'opa334:2.x' into 2.x
2 parents c6a0624 + fba5607 commit 463e1aa

File tree

7 files changed

+44
-16
lines changed

7 files changed

+44
-16
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,4 @@ jobs:
100100
with:
101101
name: Dopamine
102102
path: |
103-
${{ github.workspace }}/Application/Dopamine.ipa
103+
${{ github.workspace }}/Application/Dopamine.ipa

Application/Dopamine.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,7 +2234,7 @@
22342234
"$(PROJECT_DIR)/Dopamine/Dependencies",
22352235
"$(PROJECT_DIR)/Dopamine/Resources",
22362236
);
2237-
MARKETING_VERSION = 2.4.1;
2237+
MARKETING_VERSION = 2.4.2;
22382238
PRODUCT_BUNDLE_IDENTIFIER = com.opa334.Dopamine;
22392239
PRODUCT_NAME = "$(TARGET_NAME)";
22402240
SWIFT_EMIT_LOC_STRINGS = YES;
@@ -2271,7 +2271,7 @@
22712271
"$(PROJECT_DIR)/Dopamine/Dependencies",
22722272
"$(PROJECT_DIR)/Dopamine/Resources",
22732273
);
2274-
MARKETING_VERSION = 2.4.1;
2274+
MARKETING_VERSION = 2.4.2;
22752275
PRODUCT_BUNDLE_IDENTIFIER = com.opa334.Dopamine;
22762276
PRODUCT_NAME = "$(TARGET_NAME)";
22772277
SWIFT_EMIT_LOC_STRINGS = YES;

BaseBin/MachOMerger/Sources/MachOMerger/SegmentLoadCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func generateSegmentLoadCommands(infoA: MachOMergeData, infoB: MachOMergeData, r
6363
for sect in seg.1[0].origCommand.sections {
6464
var sectLC = section_64()
6565
_ = withUnsafeMutableBytes(of: &sectLC.sectname) { ptr in
66-
strcpy(ptr.baseAddress!, sect.section + (seg.1.count > 1 ? "_1" : ""))
66+
strcpy(ptr.baseAddress!, sect.section)
6767
}
6868
_ = withUnsafeMutableBytes(of: &sectLC.segname) { ptr in
6969
strcpy(ptr.baseAddress!, seg.0)

BaseBin/MachOMerger/Sources/MachOMerger/main.swift

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ func collectData(fromMachO machO: MachO) -> MachOMergeData {
177177
var dataA = collectData(fromMachO: a)
178178
var dataB = collectData(fromMachO: b)
179179

180+
// Patch out magic of both MachOs
181+
// Fixes issues with some third party software (e.g. Frida) finding the wrong place and mistaking it for the header
182+
// Of course the root issue is in third party software, but I guess we can make their life easier
183+
let magicReplacement = UInt32(0xd0d0d0d0)
184+
180185
/*
181186
* Now comes the real magic: Merging the MachOs.
182187
* To do this, the following steps have to be performed:
@@ -193,14 +198,26 @@ for seg in dataA.segments {
193198
print("Found duplicate segment! [A]")
194199
exit(-1)
195200
}
201+
202+
var data = seg.1
203+
204+
if seg.0.name == "__TEXT" {
205+
data = Data(fromObject:magicReplacement) + data.subdata(in: 4..<data.count)
206+
}
196207

197-
segments.append((seg.0.name, [(isB: false, origCommand: seg.0, data: seg.1, offset: 0)]))
208+
segments.append((seg.0.name, [(isB: false, origCommand: seg.0, data: data, offset: 0)]))
198209
}
199210

200211
var sortingRequired = false
201212

202213
for seg in dataB.segments {
203-
let newEntry = [(isB: true, origCommand: seg.0, data: seg.1, offset: 0 as UInt64)]
214+
var data = seg.1
215+
216+
if seg.0.name == "__TEXT" {
217+
data = Data(fromObject:magicReplacement) + data.subdata(in: 4..<data.count)
218+
}
219+
220+
let newEntry = [(isB: true, origCommand: seg.0, data: data, offset: 0 as UInt64)]
204221

205222
var found = false
206223
var new: [(String, [(isB: Bool, origCommand: Segment64LoadCommand, data: Data, offset: UInt64)])] = []

BaseBin/_external/basebin/.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.4.1
1+
2.4.2

BaseBin/systemhook/src/main.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,18 @@ int __execve_hook(const char *path, char *const argv[], char *const envp[])
248248

249249
const struct mach_header_64 *get_dyld_mach_header(void)
250250
{
251-
task_dyld_info_data_t dyldInfo;
252-
uint32_t count = TASK_DYLD_INFO_COUNT;
253-
kern_return_t kr = task_info(mach_task_self_, TASK_DYLD_INFO, (task_info_t)&dyldInfo, &count);
254-
if (kr != KERN_SUCCESS) return NULL;
255-
struct dyld_all_image_infos *infos = (struct dyld_all_image_infos *)dyldInfo.all_image_info_addr;
256-
return (const struct mach_header_64 *)infos->dyldImageLoadAddress;
251+
static const struct mach_header_64 *dyldMachHeader = NULL;
252+
static dispatch_once_t onceToken;
253+
dispatch_once (&onceToken, ^{
254+
task_dyld_info_data_t dyldInfo;
255+
uint32_t count = TASK_DYLD_INFO_COUNT;
256+
kern_return_t kr = task_info(mach_task_self_, TASK_DYLD_INFO, (task_info_t)&dyldInfo, &count);
257+
if (kr == KERN_SUCCESS) {
258+
struct dyld_all_image_infos *infos = (struct dyld_all_image_infos *)dyldInfo.all_image_info_addr;
259+
dyldMachHeader = (const struct mach_header_64 *)infos->dyldImageLoadAddress;
260+
}
261+
});
262+
return dyldMachHeader;
257263
}
258264

259265
int parse_dyldhook_jbinfo(char **jbRootPathOut, char **bootUUIDOut, char **sandboxExtensionsOut, bool *fullyDebuggedOut)
@@ -317,8 +323,7 @@ __attribute__((constructor)) static void initializer(void)
317323
}
318324
else {
319325
// On iOS 15 there is a way to hook posix_spawn and execve without doing instruction replacements
320-
// This is fairly convenient due to instruction replacements being presumed to be the primary trigger for spinlock panics on iOS 15 arm64e
321-
// Unfortunately Apple decided to remove these in iOS 16 :( Doesn't matter too much though because spinlock panics are fixed there
326+
// Unfortunately Apple decided to remove these in iOS 16 :(
322327

323328
void **posix_spawn_with_filter = litehook_find_dsc_symbol("/usr/lib/system/libsystem_kernel.dylib", "_posix_spawn_with_filter");
324329
void **execve_with_filter = litehook_find_dsc_symbol("/usr/lib/system/libsystem_kernel.dylib", "_execve_with_filter");
@@ -327,6 +332,12 @@ __attribute__((constructor)) static void initializer(void)
327332
*execve_with_filter = __execve_hook;
328333
}
329334

335+
// Hook the dyld_shared_cache __fcntl to jump to the dyld __fcntl instead
336+
// This makes it so that library validation is also bypassed if someone calls fcntl in userspace to attach a signature manually
337+
void *dyld___fcntl = litehook_find_symbol(get_dyld_mach_header(), "___fcntl");
338+
extern int __fcntl(int fd, int op, ... /* arg */ );
339+
litehook_hook_function(__fcntl, dyld___fcntl);
340+
330341
// Initialize stuff neccessary for sandbox_apply hook
331342
gLibSandboxHandle = dlopen("/usr/lib/libsandbox.1.dylib", RTLD_FIRST | RTLD_LOCAL | RTLD_LAZY);
332343
sandbox_apply_orig = dlsym(gLibSandboxHandle, "sandbox_apply");

0 commit comments

Comments
 (0)