Skip to content

Commit

Permalink
BlueToolFixup: Add Skip Address Check patch for 13.0 Beta 1 and newer (
Browse files Browse the repository at this point in the history
  • Loading branch information
PMheart authored Jun 25, 2022
1 parent 8c04849 commit 7f3254b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
24 changes: 21 additions & 3 deletions BrcmPatchRAM/BlueToolFixup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,27 @@ static const uint8_t kSkipUpdateFilePathPatched[] = "/System/Library/CoreServic
static const uint8_t kSkipAddressCheckOriginal[] =
{
0x48, 0x89, 0xF3, // mov rbx, rsi
0xE8, 0xE3, 0xF3, 0xFE, 0xFF, // call sub_1000c5bc6
0xE8, 0x00, 0x00, 0x00, 0x00, // call <somewhere>
0x85, 0xC0, // test eax, eax
0x74, 0x1D, // je
};

static const uint8_t kSkipAddressCheckPatched[] =
{
0x48, 0x89, 0xF3, // mov rbx, rsi
0xE8, 0xE3, 0xF3, 0xFE, 0xFF, // call sub_1000c5bc6
0xE8, 0x00, 0x00, 0x00, 0x00, // call <somewhere>
0x85, 0xC0, // test eax, eax
0x72, 0x1D, // jb short
};

static const uint8_t kSkipAddressCheckMask[] =
{
0xFF, 0xFF, 0xFF,
0xFF, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFF,
0xFF, 0xFF,
};

static const uint8_t kVendorCheckOriginal[] =
{
0x81, 0xFA, // cmp edx
Expand Down Expand Up @@ -137,6 +145,16 @@ static inline void searchAndPatch(const void *haystack, size_t haystackSize, con
searchAndPatch(haystack, haystackSize, path, needle, findSize * sizeof(T), patch, replaceSize * sizeof(T));
}

static inline void searchAndPatchWithMask(const void *haystack, size_t haystackSize, const char *path, const void *needle, size_t findSize, const void *findMask, size_t findMaskSize, const void *patch, size_t replaceSize, const void *patchMask, size_t replaceMaskSize) {
if (KernelPatcher::findAndReplaceWithMask(const_cast<void *>(haystack), haystackSize, needle, findSize, findMask, findMaskSize, patch, replaceSize, patchMask, replaceMaskSize))
DBGLOG(MODULE_SHORT, "found string to patch at %s!", path);
}

template <size_t findSize, size_t findMaskSize, size_t replaceSize, size_t replaceMaskSize, typename T>
static inline void searchAndPatchWithMask(const void *haystack, size_t haystackSize, const char *path, const T (&needle)[findSize], const T (&findMask)[findMaskSize], const T (&patch)[replaceSize], const T (&patchMask)[replaceMaskSize]) {
searchAndPatchWithMask(haystack, haystackSize, path, needle, findSize * sizeof(T), findMask, findMaskSize * sizeof(T), patch, replaceSize * sizeof(T), patchMask, replaceSize * sizeof(T));
}


#pragma mark - Patched functions

Expand All @@ -157,7 +175,7 @@ static void patched_cs_validate_page(vnode_t vp, memory_object_t pager, memory_o
if (shouldPatchBoardId)
searchAndPatch(data, PAGE_SIZE, path, boardIdsWithUSBBluetooth[0], kBoardIdSize, BaseDeviceInfo::get().boardIdentifier, kBoardIdSize);
if (shouldPatchAddress)
searchAndPatch(data, PAGE_SIZE, path, kSkipAddressCheckOriginal, kSkipAddressCheckPatched);
searchAndPatchWithMask(data, PAGE_SIZE, path, kSkipAddressCheckOriginal, kSkipAddressCheckMask, kSkipAddressCheckPatched, kSkipAddressCheckMask);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ BrcmPatchRAM Changelog
======================
#### v2.6.3
- Added constants for macOS 13 support
- Fixed Skip Address Check patch for 13.0 Beta 1 and newer

#### v2.6.2
- Added Skip Address Check patch for 12.4 Beta 3 and newer (thx @khronokernel)
Expand Down

0 comments on commit 7f3254b

Please sign in to comment.