Skip to content

Commit b3fba6c

Browse files
committed
Merge IntelBTPatcher from https://github.com/zxystd/IntelBTPatcher.
1 parent ee1a800 commit b3fba6c

File tree

4 files changed

+329
-0
lines changed

4 files changed

+329
-0
lines changed

IntelBTPatcher/Info.plist

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>$(DEVELOPMENT_LANGUAGE)</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
17+
<key>CFBundleShortVersionString</key>
18+
<string>$(MARKETING_VERSION)</string>
19+
<key>CFBundleVersion</key>
20+
<string>$(CURRENT_PROJECT_VERSION)</string>
21+
<key>IOKitPersonalities</key>
22+
<dict>
23+
<key>IntelBTPatcher</key>
24+
<dict>
25+
<key>CFBundleIdentifier</key>
26+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
27+
<key>IOClass</key>
28+
<string>$(PRODUCT_NAME:rfc1034identifier)</string>
29+
<key>IOMatchCategory</key>
30+
<string>$(PRODUCT_NAME:rfc1034identifier)</string>
31+
<key>IOProviderClass</key>
32+
<string>IOResources</string>
33+
<key>IOResourceMatch</key>
34+
<string>IOKit</string>
35+
</dict>
36+
</dict>
37+
<key>NSHumanReadableCopyright</key>
38+
<string>Copyright © 2022 zxystd. All rights reserved.</string>
39+
<key>OSBundleLibraries</key>
40+
<dict>
41+
<key>as.vit9696.Lilu</key>
42+
<string>1.2.0</string>
43+
<key>com.apple.kpi.bsd</key>
44+
<string>12.0.0</string>
45+
<key>com.apple.kpi.dsep</key>
46+
<string>12.0.0</string>
47+
<key>com.apple.kpi.iokit</key>
48+
<string>12.0.0</string>
49+
<key>com.apple.kpi.libkern</key>
50+
<string>12.0.0</string>
51+
<key>com.apple.kpi.mach</key>
52+
<string>12.0.0</string>
53+
<key>com.apple.kpi.unsupported</key>
54+
<string>12.0.0</string>
55+
</dict>
56+
</dict>
57+
</plist>

IntelBTPatcher/IntelBTPatcher.cpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
//
2+
// IntelBTPatcher.cpp
3+
// IntelBTPatcher
4+
//
5+
// Created by qcwap on 2021/2/8.
6+
//
7+
8+
#include <Headers/kern_api.hpp>
9+
#include <Headers/kern_util.hpp>
10+
#include <Headers/plugin_start.hpp>
11+
12+
#include "IntelBTPatcher.hpp"
13+
14+
static CIntelBTPatcher ibtPatcher;
15+
static CIntelBTPatcher *callbackIBTPatcher = nullptr;
16+
17+
static const char *bootargOff[] {
18+
"-ibtcompatoff"
19+
};
20+
21+
static const char *bootargDebug[] {
22+
"-ibtcompatdbg"
23+
};
24+
25+
static const char *bootargBeta[] {
26+
"-ibtcompatbeta"
27+
};
28+
29+
PluginConfiguration ADDPR(config) {
30+
xStringify(PRODUCT_NAME),
31+
parseModuleVersion(xStringify(MODULE_VERSION)),
32+
LiluAPI::AllowNormal | LiluAPI::AllowInstallerRecovery | LiluAPI::AllowSafeMode,
33+
bootargOff,
34+
arrsize(bootargOff),
35+
bootargDebug,
36+
arrsize(bootargDebug),
37+
bootargBeta,
38+
arrsize(bootargBeta),
39+
KernelVersion::MountainLion,
40+
KernelVersion::Monterey,
41+
[]() {
42+
ibtPatcher.init();
43+
}
44+
};
45+
46+
static const char *IntelBTPatcher_IOBluetoothFamily[] { "/System/Library/Extensions/IOBluetoothFamily.kext/Contents/MacOS/IOBluetoothFamily" };
47+
48+
static KernelPatcher::KextInfo IntelBTPatcher_IOBluetoothInfo {
49+
"com.apple.iokit.IOBluetoothFamily",
50+
IntelBTPatcher_IOBluetoothFamily,
51+
1,
52+
{true, true},
53+
{},
54+
KernelPatcher::KextInfo::Unloaded
55+
};
56+
57+
bool CIntelBTPatcher::init()
58+
{
59+
DBGLOG(DRV_NAME, "%s", __PRETTY_FUNCTION__);
60+
callbackIBTPatcher = this;
61+
lilu.onKextLoadForce(&IntelBTPatcher_IOBluetoothInfo, 1,
62+
[](void *user, KernelPatcher &patcher, size_t index, mach_vm_address_t address, size_t size) {
63+
callbackIBTPatcher->processKext(patcher, index, address, size);
64+
}, this);
65+
return true;
66+
}
67+
68+
void CIntelBTPatcher::free()
69+
{
70+
DBGLOG(DRV_NAME, "%s", __PRETTY_FUNCTION__);
71+
}
72+
73+
void CIntelBTPatcher::processKext(KernelPatcher &patcher, size_t index, mach_vm_address_t address, size_t size)
74+
{
75+
DBGLOG(DRV_NAME, "%s", __PRETTY_FUNCTION__);
76+
if (getKernelVersion() < KernelVersion::Monterey) {
77+
if (IntelBTPatcher_IOBluetoothInfo.loadIndex == index) {
78+
DBGLOG(DRV_NAME, "%s", IntelBTPatcher_IOBluetoothInfo.id);
79+
80+
KernelPatcher::RouteRequest findQueueRequestRequest {
81+
"__ZN25IOBluetoothHostController17FindQueuedRequestEtP22BluetoothDeviceAddresstbPP21IOBluetoothHCIRequest",
82+
newFindQueueRequest,
83+
oldFindQueueRequest
84+
};
85+
patcher.routeMultiple(index, &findQueueRequestRequest, 1, address, size);
86+
if (patcher.getError() == KernelPatcher::Error::NoError) {
87+
DBGLOG(DRV_NAME, "routed %s", findQueueRequestRequest.symbol);
88+
} else {
89+
SYSLOG(DRV_NAME, "failed to resolve %s, error = %d", findQueueRequestRequest.symbol, patcher.getError());
90+
patcher.clearError();
91+
}
92+
93+
}
94+
}
95+
}
96+
97+
IOReturn CIntelBTPatcher::newFindQueueRequest(void *that, unsigned short arg1, void *addr, unsigned short arg2, bool arg3, void **hciRequestPtr)
98+
{
99+
IOReturn ret = FunctionCast(newFindQueueRequest, callbackIBTPatcher->oldFindQueueRequest)(that, arg1, addr, arg2, arg3, hciRequestPtr);
100+
if (ret != 0 && arg1 == 0x2019) {
101+
ret = FunctionCast(newFindQueueRequest, callbackIBTPatcher->oldFindQueueRequest)(that, arg1, addr, 0xffff, arg3, hciRequestPtr);
102+
DBGLOG(DRV_NAME, "%s ret: %d arg1: 0x%04x arg2: 0x%04x arg3: %d ptr: %p", __FUNCTION__, ret, arg1, arg2, arg3, *hciRequestPtr);
103+
}
104+
return ret;
105+
}

IntelBTPatcher/IntelBTPatcher.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// IntelBTPatcher.h
3+
// IntelBTPatcher
4+
//
5+
// Created by qcwap on 2021/2/8.
6+
//
7+
8+
#ifndef IntelBTPatcher_h
9+
#define IntelBTPatcher_h
10+
11+
#include <Headers/kern_patcher.hpp>
12+
13+
#define DRV_NAME "IntelBTPatcher"
14+
15+
class BluetoothDeviceAddress;
16+
17+
class CIntelBTPatcher {
18+
public:
19+
bool init();
20+
void free();
21+
22+
void processKext(KernelPatcher &patcher, size_t index, mach_vm_address_t address, size_t size);
23+
static IOReturn newFindQueueRequest(void *that, unsigned short arg1, void *addr, unsigned short arg2, bool arg3, void **hciRequestPtr);
24+
25+
mach_vm_address_t oldFindQueueRequest {};
26+
};
27+
28+
#endif /* IntelBTPatcher_h */

0 commit comments

Comments
 (0)