kubo / injector

Library for injecting a shared library into a Linux or Windows process
GNU General Public License v2.0
505 stars 97 forks source link

Pass an argument to function #33

Closed enty8080 closed 1 year ago

enty8080 commented 1 year ago

Hey @kubo,

Love your tool so much and tend to use it for my experiments! I was just wondering, is it possible to pass an argument to a shared object which is being injected. For example, I need to pass sockfd which is int to my init function.

__attribute__((constructor))
void init(int sockfd)
{
... snip ...
}

How can I do this? Or, if it can be implemented, can you suggest me how to do this and I fork your repository and add this by myself.

I also found injector_call, but it works only with void(*)(void), I just want to add a support for void(*)(int). Is it possible?

I really need this for my new project, so I'll be glad if you help me.

Thanks in advance.

P.S. Another question that comes to my mind: Will injector work within statically linked executable (compiled with libinjector and -static)?

P.P.S. I checked it with -static and it works. It's a surprise for me, because I thought that dlopen works only with dynamic linking. Turns out, if you compile cmd/main.c with -static injection will work.

enty8080 commented 1 year ago

I implemented this functionality.

zhiying8710 commented 1 year ago

@enty8080 i want use this feature with ur fork, can u add a doc to use it? thanks

enty8080 commented 1 year ago

@zhiying8710 I just pass an argument of type int to injector__call_function here - https://github.com/enty8080/injector/blob/9e8a34eafce49042546881ef8c442982031d6b15/src/linux/injector.c#L187