Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while debugging NSBlock #12

Closed
mtshare opened this issue Mar 4, 2017 · 8 comments · Fixed by #95
Closed

Error while debugging NSBlock #12

mtshare opened this issue Mar 4, 2017 · 8 comments · Fixed by #95
Labels
bug Something isn't working

Comments

@mtshare
Copy link

mtshare commented Mar 4, 2017

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
Copy link
Member

uroboro commented Mar 4, 2017

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
Copy link
Contributor

DHowett commented Mar 4, 2017

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
Copy link
Member

uroboro commented Mar 5, 2017

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

@kirb
Copy link
Member

kirb commented Mar 5, 2017

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
Copy link
Author

mtshare commented Mar 6, 2017

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
Copy link
Member

uroboro commented Mar 6, 2017

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
Copy link
Contributor

rpetrich commented Mar 6, 2017

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
Copy link
Author

mtshare commented Mar 6, 2017

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

@uroboro uroboro transferred this issue from theos/theos Nov 2, 2018
@uroboro uroboro added the bug Something isn't working label Nov 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants