mirror of
https://github.com/NohamR/RMHook.git
synced 2026-04-08 07:59:58 +00:00
Add build modes and dev hooks, improve injection and docs
Introduces build mode options (rmfakecloud, qmldiff, dev, all) to CMake and build scripts, enabling selective compilation of hooks for cloud redirection, Qt resource hooking, and reverse engineering. Adds new hooks and memory logging for dev mode, updates injection script to handle libzstd.1.dylib dependency, and documents build modes in README.
This commit is contained in:
@@ -30,4 +30,20 @@
|
||||
logPrefix:(NSString *)logPrefix
|
||||
delayInSeconds:(NSTimeInterval)delayInSeconds;
|
||||
|
||||
/**
|
||||
* Hooks a function at a specific address after calculating ASLR slide.
|
||||
*
|
||||
* @param imageName The name of the image/library (e.g., "QtNetwork" or "reMarkable").
|
||||
* @param staticAddress The static address from the binary (before ASLR).
|
||||
* @param hookFunction The function to replace the original with.
|
||||
* @param originalFunction Pointer to store the original function address.
|
||||
* @param logPrefix Prefix for log messages (optional, can be nil).
|
||||
* @return YES if the hook was successfully installed, NO otherwise.
|
||||
*/
|
||||
+ (BOOL)hookAddress:(NSString *)imageName
|
||||
staticAddress:(uintptr_t)staticAddress
|
||||
hookFunction:(void *)hookFunction
|
||||
originalFunction:(void **)originalFunction
|
||||
logPrefix:(NSString *)logPrefix;
|
||||
|
||||
@end
|
||||
|
||||
@@ -103,4 +103,37 @@
|
||||
}
|
||||
}
|
||||
|
||||
+ (BOOL)hookAddress:(NSString *)imageName
|
||||
staticAddress:(uintptr_t)staticAddress
|
||||
hookFunction:(void *)hookFunction
|
||||
originalFunction:(void **)originalFunction
|
||||
logPrefix:(NSString *)logPrefix {
|
||||
|
||||
NSLogger(@"%@ Starting hook installation at static address: 0x%lx", logPrefix, staticAddress);
|
||||
|
||||
int imageIndex = [self indexForImageWithName:imageName];
|
||||
if (imageIndex < 0) {
|
||||
NSLogger(@"%@ ERROR: Image %@ not found", logPrefix, imageName);
|
||||
return NO;
|
||||
}
|
||||
|
||||
// Calculate ASLR slide
|
||||
intptr_t slide = _dyld_get_image_vmaddr_slide(imageIndex);
|
||||
NSLogger(@"%@ Image %@ ASLR slide: 0x%lx", logPrefix, imageName, slide);
|
||||
|
||||
// Calculate actual runtime address
|
||||
void *actualAddress = (void *)(staticAddress + slide);
|
||||
NSLogger(@"%@ Calculated runtime address: %p (static: 0x%lx + slide: 0x%lx)", logPrefix, actualAddress, staticAddress, slide);
|
||||
|
||||
int hookResult = tiny_hook(actualAddress, hookFunction, originalFunction);
|
||||
|
||||
if (hookResult == 0) {
|
||||
NSLogger(@"%@ Hook successfully installed at address %p", logPrefix, actualAddress);
|
||||
return YES;
|
||||
} else {
|
||||
NSLogger(@"%@ ERROR: Failed to install hook at address %p (code: %d)", logPrefix, actualAddress, hookResult);
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -36,6 +36,7 @@ static NSString *ReMarkableDumpRootDirectory(void) {
|
||||
return dumpDirectory;
|
||||
}
|
||||
|
||||
#ifdef BUILD_MODE_QMLDIFF
|
||||
uint32_t readUInt32(uint8_t *addr, int offset) {
|
||||
return (uint32_t)(addr[offset + 0] << 24) |
|
||||
(uint32_t)(addr[offset + 1] << 16) |
|
||||
@@ -379,3 +380,4 @@ void processNode(struct ResourceRoot *root, int node, const char *rootName) {
|
||||
ReMarkableDumpResourceFile(root, node, rootName ? rootName : "", nameBuffer, fileFlags);
|
||||
}
|
||||
}
|
||||
#endif // BUILD_MODE_QMLDIFF
|
||||
Reference in New Issue
Block a user