Gate legacy MQTT hook behind CMake option

This commit is contained in:
√(noham)² committed 2026-10-21 17:35:05 +02:00
1 parent e00ab1d5ed
commit 93b011807c
3 files changed
+23

No files matched your search

+7
View File
@@ -129,6 +129,13 @@ if(BUILD_MODE_DEV)
message(STATUS "Build mode: dev (reverse engineering)") message(STATUS "Build mode: dev (reverse engineering)")
endif() endif()
# MQTT URI patching hook (legacy, disabled by default)
option(RMHOOK_ENABLE_MQTT "Enable MQTT URI patching hook (legacy, requires rmfakecloud mode)" OFF)
if(RMHOOK_ENABLE_MQTT)
target_compile_definitions(RMHook PRIVATE RMHOOK_ENABLE_MQTT=1)
message(STATUS "MQTT hook: enabled (legacy)")
endif()
target_link_libraries(reMarkable PRIVATE target_link_libraries(reMarkable PRIVATE
${LIBS} ${LIBS}
${QT_LIB_TARGETS} ${QT_LIB_TARGETS}
+8
View File
@@ -154,6 +154,14 @@ Examples:
./scripts/build.sh all # Build with all modes enabled ./scripts/build.sh all # Build with all modes enabled
``` ```
### Optional: Legacy MQTT hook
The MQTT URI patching hook (`MQTTAsync_createWithOptions`) is kept for legacy use but is **disabled by default**. To enable it, pass the CMake option when building:
```bash
cmake -DRMHOOK_ENABLE_MQTT=ON ..
```
## Debugging ## Debugging
You can stream the macOS console logs to see output from the hooks: You can stream the macOS console logs to see output from the hooks:
+8
View File
@@ -247,6 +247,7 @@ static void (*original_qWebSocket_open)(
QWebSocket *self, QWebSocket *self,
const QNetworkRequest &request) = NULL; const QNetworkRequest &request) = NULL;
#ifdef RMHOOK_ENABLE_MQTT
typedef void* MQTTAsync; typedef void* MQTTAsync;
typedef void* MQTTAsync_createOptions; typedef void* MQTTAsync_createOptions;
@@ -257,6 +258,7 @@ static int (*original_MQTTAsync_createWithOptions)(
int persistence_type, int persistence_type,
void *persistence_context, void *persistence_context,
MQTTAsync_createOptions *options) = NULL; MQTTAsync_createOptions *options) = NULL;
#endif // RMHOOK_ENABLE_MQTT
#endif #endif
#ifdef BUILD_MODE_QMLREBUILD #ifdef BUILD_MODE_QMLREBUILD
@@ -314,11 +316,13 @@ static inline bool shouldPatchURL(const QString &host) {
originalFunction:(void **)&original_qWebSocket_open originalFunction:(void **)&original_qWebSocket_open
logPrefix:@"[reMarkable]"]; logPrefix:@"[reMarkable]"];
#ifdef RMHOOK_ENABLE_MQTT
[MemoryUtils hookSymbol:@"libpaho-mqtt3as.1.dylib" [MemoryUtils hookSymbol:@"libpaho-mqtt3as.1.dylib"
symbolName:@"_MQTTAsync_createWithOptions" symbolName:@"_MQTTAsync_createWithOptions"
hookFunction:(void *)hooked_MQTTAsync_createWithOptions hookFunction:(void *)hooked_MQTTAsync_createWithOptions
originalFunction:(void **)&original_MQTTAsync_createWithOptions originalFunction:(void **)&original_MQTTAsync_createWithOptions
logPrefix:@"[reMarkable]"]; logPrefix:@"[reMarkable]"];
#endif // RMHOOK_ENABLE_MQTT
#endif #endif
#ifdef BUILD_MODE_QMLREBUILD #ifdef BUILD_MODE_QMLREBUILD
@@ -463,6 +467,7 @@ extern "C" void hooked_qWebSocket_open(
// Patch a paho URI: "ssl://host.remarkable.com:port" -> "ssl://proxy:port" // Patch a paho URI: "ssl://host.remarkable.com:port" -> "ssl://proxy:port"
// Returns patched string, or empty if no patch needed. // Returns patched string, or empty if no patch needed.
#ifdef RMHOOK_ENABLE_MQTT
static std::string PatchMqttUri(const char* uri) static std::string PatchMqttUri(const char* uri)
{ {
if (!uri) return {}; if (!uri) return {};
@@ -510,7 +515,9 @@ static std::string PatchMqttUri(const char* uri)
} }
return patched; return patched;
} }
#endif // RMHOOK_ENABLE_MQTT
#ifdef RMHOOK_ENABLE_MQTT
extern "C" int hooked_MQTTAsync_createWithOptions( extern "C" int hooked_MQTTAsync_createWithOptions(
MQTTAsync *handle, MQTTAsync *handle,
const char *serverURI, const char *serverURI,
@@ -531,6 +538,7 @@ extern "C" int hooked_MQTTAsync_createWithOptions(
return original_MQTTAsync_createWithOptions(handle, serverURI, clientId, persistence_type, persistence_context, options); return original_MQTTAsync_createWithOptions(handle, serverURI, clientId, persistence_type, persistence_context, options);
} }
#endif // RMHOOK_ENABLE_MQTT
#endif // BUILD_MODE_RMFAKECLOUD #endif // BUILD_MODE_RMFAKECLOUD
#ifdef BUILD_MODE_QMLREBUILD #ifdef BUILD_MODE_QMLREBUILD