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

call a function in the dynamic library after injected #9

Closed noword closed 3 years ago

noword commented 3 years ago

After the dynamic library was injected, user can call a function in this library.

It's useful for Linux, cause Linux hasn't DllMain entry point like Windows, and the function with attribute((constructor)) declaring, has the "static value initialization" issue.

The called function in the dynamic library should be void(*)(void). For example: void Init() {...}

Tips: be careful the c++ naming conventions, "Init" => "_Z4Initv"

kubo commented 3 years ago

@noword Could you separate calling a function from injecting a library? The header file injector.h is for not only Linux but also Windows. However you didn't implement calling a function on Windows.

In addition, your PR fails tests on travis-ci. https://travis-ci.com/github/kubo/injector/pull_requests

noword commented 3 years ago

Sorry, I didn't tested it in Windows. Anyway, what the new function should be named? int injector_call(injector_t *injector, void *handle, const char* name); Is it fine? I will separate it and write the windows supported codes, then pull again.

kubo commented 3 years ago

Sorry, my words weren't enough. When an argument is added to injector_inject() in injector.h, both codes on Linux and Windows must be modified to accept the argument. However when a function is added to injector.h, I don't request to support it on both Linux and Windows.

Anyway, what the new function should be named? int injector_call(injector_t *injector, void *handle, const char* name); Is it fine?

Fine.

I will separate it and write the windows supported codes, then pull again.

If it supports both Linux and Windows, it is welcome. However even if it works only on Linux, I'll accept it.