logos icon indicating copy to clipboard operation
logos copied to clipboard

Error while debugging NSBlock

Open mtshare opened this issue 7 years ago • 8 comments

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)

mtshare avatar Mar 04 '17 17:03 mtshare

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.

uroboro avatar Mar 04 '17 21:03 uroboro

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.

DHowett avatar Mar 04 '17 22:03 DHowett

Targets of patch Method.pm#L220 and Method.pm#L156.

uroboro avatar Mar 05 '17 00:03 uroboro

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.

kirb avatar Mar 05 '17 09:03 kirb

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.

mtshare avatar Mar 06 '17 01:03 mtshare

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

uroboro avatar Mar 06 '17 15:03 uroboro

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

rpetrich avatar Mar 06 '17 16:03 rpetrich

@uroboro @rpetrich Thanks for the examples guys! It would be awesome to get %log works.

mtshare avatar Mar 06 '17 17:03 mtshare