theos / logos

Preprocessor that simplifies Objective-C hooking.
https://theos.dev/docs/logos
Other
206 stars 34 forks source link

Error while debugging NSBlock #12

Closed mtshare closed 1 year ago

mtshare commented 7 years ago

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)

uroboro commented 7 years ago

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.

DHowett commented 7 years ago

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.

uroboro commented 7 years ago

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

kirb commented 7 years ago

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.

mtshare commented 7 years ago

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.

uroboro commented 7 years ago

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
rpetrich commented 7 years ago

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
mtshare commented 7 years ago

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