Skip to content

Commit

Permalink
handle null
Browse files Browse the repository at this point in the history
  • Loading branch information
jjolano committed Jan 27, 2023
1 parent 493f192 commit 640c95b
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions HookKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ + (instancetype)defaultSubstitutor {
}

- (hookkit_status_t)hookMessageInClass:(Class)objcClass withSelector:(SEL)selector withReplacement:(void *)replacement outOldPtr:(void **)old_ptr {
if(!objcClass || !selector || !replacement) {
return HK_ERR;
}

if(_types & HK_LIB_LIBHOOKER) {
if(_LBHookMessage) {
int lh_result = _LBHookMessage(objcClass, selector, replacement, old_ptr);
Expand Down Expand Up @@ -396,6 +400,10 @@ - (hookkit_status_t)hookMessageInClass:(Class)objcClass withSelector:(SEL)select
}

- (hookkit_status_t)hookFunction:(void *)function withReplacement:(void *)replacement outOldPtr:(void **)old_ptr {
if(!function || !replacement) {
return HK_ERR;
}

if(_batching) {
HKFunctionHook* hook = [HKFunctionHook new];
[hook setFunction:[NSValue valueWithPointer:function]];
Expand Down Expand Up @@ -483,6 +491,10 @@ - (hookkit_status_t)hookFunction:(void *)function withReplacement:(void *)replac
}

- (hookkit_status_t)hookMemory:(void *)target withData:(const void *)data size:(size_t)size {
if(!target) {
return HK_ERR;
}

if(_batching) {
HKMemoryHook* hook = [HKMemoryHook new];
[hook setTarget:[NSValue valueWithPointer:target]];
Expand Down Expand Up @@ -548,6 +560,10 @@ - (hookkit_status_t)hookMemory:(void *)target withData:(const void *)data size:(
}

- (HKImageRef)openImage:(NSString *)path {
if(!path) {
return NULL;
}

if(_types & HK_LIB_LIBHOOKER) {
if(_LHOpenImage) {
return (HKImageRef)_LHOpenImage([path fileSystemRepresentation]);
Expand Down Expand Up @@ -666,6 +682,10 @@ - (hookkit_status_t)findSymbolsInImage:(HKImageRef)image symbolNames:(NSArray<NS
}

- (void *)findSymbolInImage:(HKImageRef)image symbolName:(NSString *)symbolName {
if(!symbolName) {
return NULL;
}

NSArray<NSValue *>* syms = nil;
hookkit_status_t result = [self findSymbolsInImage:image symbolNames:@[symbolName] outSymbols:&syms];

Expand Down

0 comments on commit 640c95b

Please sign in to comment.