0

I am trying to find connect symbol in libcrypto.so file using dlsym() and want to replace this connect with my method.

void * lib_orig_tols  = dlopen(libcrypto.so, RTLD_GLOBAL);   

void * p_orig_connectOriginal;
     p_orig_connectOriginal = (void*)dlsym(lib_orig_tols, "connect");

    if (p_orig_connectOriginal != NULL)
        {
        LOGI(" is not NULL");

        void *p_orig_connect = (void*)*((unsigned *)p_orig_connectOriginal);

        *((unsigned *)p_orig_connectOriginal) = (unsigned)( my_crypto_connect);
        }


    int my_crypto_connect(int , const struct sockaddr , socklen_t){
        **
        ***********
        ***************
        **********
    }

My my app got crashed with error
is not NULL

Fatal signal 11 (SIGSEGV), code 2, fault addr 0xb6e4755d in tid 7909

do i am doing something wrong.

7
  • Why is android tagged? Commented Sep 27, 2016 at 5:45
  • Please correct the indentation of your code. You must use function pointers. A unsigned* is not a valid function pointer. Commented Sep 27, 2016 at 5:54
  • 1. You can't do that 2. This code doesn't make sense even if you could do that. Commented Sep 27, 2016 at 5:56
  • Redx, app did not crashed this point it crashed when i try to initialize the new value in ` *((unsigned *)p_orig_connectOriginal) = (unsigned)( my_crypto_connect); ` later i am typecasting p_orig_connectOriginal into function pointer. Commented Sep 27, 2016 at 5:59
  • @hobbs : i want to replace system SO function with my function. So when any app call this SO connect then i will get that call. Commented Sep 27, 2016 at 6:04

1 Answer 1

1

Well, your code is incomplete, it is full with syntactical errors, also it contains bogus typecasts (use intptr_t)

Plus, there is no 'connect' in libcrypto.so. Pick one from these:

BIO_CONNECT_free
BIO_CONNECT_new
BIO_new_connect
BIO_s_connect
Sign up to request clarification or add additional context in comments.

2 Comments

I want to do swizzling in this code. want to change system SO connect function with my connect function. So when any application call that connect i got the call. after some modification i am calling the SO connect using it original function pointer.
I don't understand the "SO" part, but it is perfectly possible -- of course you are not supposed to overwrite share code and other nonsense. Here is an example: tsocks.sourceforge.net

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.