logos
logos copied to clipboard
Error while debugging NSBlock
What are the steps to reproduce this issue?
%hook ASDSoftwareUpdatesStore
- (void)reloadFromServerWithCompletionBlock:(void (^)(id data))block { %log; }
%end
What happens?
Here the output: https://ghostbin.com/paste/qqma9
What were you expecting to happen?
Compile the tweak
What versions of software are you using?
Mac 0SX 10.2.1 iOS 10.2 (TARGET = iphone:clang:10.2)
I don't think blocks are supported by %log. How would you log one and what would you expect to get as its description? I remember seeing some projects revolving around block introspection but that would require us introducing a new dependency on Theos.
Still, we should be using %p for blocks and not 0x%x with a cast. That will get us compiling even if we don't display any useful information.
Targets of patch Method.pm#L220 and Method.pm#L156.
Blocks are ObjC objects; we can use %@ which gives something like <NSMallocBlock: 0xb1ab1ab1a>, making the type obvious. How we’ll parse for them is another question. Just check for (^)? Wouldn’t work for typedef’d names though.
So at the moment there is no way to intercept data from block by hooking methods in Theos? All I need to do is intercept end edit data from the block.
That's not what "%log does not support blocks" means. You can intercept blocks as well as log them, but not with %log.
For example, if I'm not mistaken:
%hook ASDSoftwareUpdatesStore
- (void)reloadFromServerWithCompletionBlock:(void (^)(id data))block {
void (^interception)(id data) = ^(id data) {
HBLogDebug(@"data? %@", data);
block(data);
};
%orig(interception);
}
%end
Should be aware that many system methods support receiving NULL for block arguments, and calling them blindly will lead to a crash. Be sure to check for NULL like such:
%hook ASDSoftwareUpdatesStore
- (void)reloadFromServerWithCompletionBlock:(void (^)(id data))block {
void (^interception)(id data) = ^(id data) {
HBLogDebug(@"data? %@", data);
if (block) {
block(data);
}
};
%orig(interception);
}
%end
@uroboro @rpetrich Thanks for the examples guys!
It would be awesome to get %log works.