Created
October 14, 2020 05:18
-
-
Save mwpcheung/ea5dfc585790a311c0dc93b1db6c57d1 to your computer and use it in GitHub Desktop.
fix iOS13 nsdata descrption
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void __attribute__((constructor)) constructor() | |
{ | |
[NSData load]; | |
} | |
@implementation NSData (hook) | |
+(void)load { | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
Method description = class_getInstanceMethod(self, @selector(description)); | |
Method hook_description = class_getInstanceMethod(self, @selector(hook_description)); | |
method_exchangeImplementations(description, hook_description); | |
}); | |
} | |
- (NSString *)hexadecimalString: (NSData *)data { | |
const unsigned char *dataBuffer = (const unsigned char *)[data bytes]; | |
if (!dataBuffer) { | |
return [NSString string]; | |
} | |
NSUInteger dataLength = [data length]; | |
NSMutableString *hexString = [NSMutableString stringWithCapacity:(dataLength * 2)]; | |
for (int i = 0; i < dataLength; ++i) { | |
if (i > 0 && i %16 == 0){ | |
[hexString appendString:@" "]; | |
} | |
[hexString appendFormat:@"%02x", (unsigned int)dataBuffer[i]]; | |
} | |
return [NSString stringWithString:hexString]; | |
} | |
-(NSString*)hook_description { | |
return [self hexadecimalString:self]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment