Skip to content

How to hook socket or connect #40

Open
@d6638219

Description

@d6638219

Use fishhook in the simulator hook to connect and socket, but not in the iphone hook.

`static int (*orig_socket)(int, int, int);
static int (*orig_connect)(int, const struct sockaddr *, socklen_t);
int my_socket(int domain, int type, int protocol)
{
printf("this is my socket!");
return orig_socket(domain,type,protocol);;
}
int my_connect(int socket, const struct sockaddr * addr, socklen_t len)
{
printf("this is my connect");
return orig_connect(socket,addr,len);
}
int main(int argc, char * argv[])
{
@autoreleasepool {
rebind_symbols((struct rebinding[2]){{"connect", my_connect, (void *)&orig_connect},{"socket", my_socket, (void *)&orig_socket}}, 2);
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}

`

Activity

kastiglione

kastiglione commented on Apr 16, 2017

@kastiglione
Contributor

People have had issues with socket and/or connect in the past. One problem is that fishhook can only hook external calls, which means function calls within the same library generally cannot be hooked. In this case, calls to socket and connect from within the same library (libSystem) cannot be hooked. With the simulator, the system libraries are broken out into many sub-libraries, including libsystem_networking. With many sub-libraries, this means function calls from one sub-library to another can be hooked on the simulator, but on device where there's just a single libSystem, those same calls are within the same library and cannot be hooked.

waitianlou

waitianlou commented on May 11, 2017

@waitianlou

Is there any inspiration how to hook connect in libSystem? inline hook can not work on un jailbreaking system. may be there is another way?

luckyCity

luckyCity commented on Apr 17, 2018

@luckyCity

@kastiglione @waitianlou Looking forward to yours, thinks

BackWorld

BackWorld commented on Apr 25, 2019

@BackWorld

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @kastiglione@waitianlou@luckyCity@BackWorld@d6638219

        Issue actions

          How to hook socket or connect · Issue #40 · facebook/fishhook