Skip to content

Instantly share code, notes, and snippets.

@mwpcheung
Created October 14, 2020 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwpcheung/ea5dfc585790a311c0dc93b1db6c57d1 to your computer and use it in GitHub Desktop.
Save mwpcheung/ea5dfc585790a311c0dc93b1db6c57d1 to your computer and use it in GitHub Desktop.
fix iOS13 nsdata descrption
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