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

Is the library loaded by dlopen replaceable? #50

Open
linuxlin365 opened this issue Nov 28, 2024 · 0 comments
Open

Is the library loaded by dlopen replaceable? #50

linuxlin365 opened this issue Nov 28, 2024 · 0 comments

Comments

@linuxlin365
Copy link

I want to hook XSetSelectionOwner,libx11.so is loaded dlopen.
What should I do?

  1. ProcessA
        HANDLE hOneSo = dlopen("libOneSo.so", RTLD_LAZY);
        if (hOneSo == NULL)
        {
            printf("Test:: dlopen Failed.\n");
            return 1;
        }

        typedef void (*PFN_OneSo)();
        PFN_OneSo pOneSo = (PFN_OneSo)dlsym(hOneSo, "OneSo");
        if (pOneSo == NULL)
        {
            printf("Test:: dlsym failed.Err:%d\n", errno);
            return 1;
        }

        pOneSo();
        dlclose(hOneSo);
$ ldd Test.bin 
	linux-vdso.so.1 (0x00007fffd7dd7000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f30952db000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f30952b8000)
	libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f3095087000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f309506a000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f3094e78000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f3095424000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f3094b0c000)

  1. libOneSo.so
void OneSo()
{
    Display * display = XOpenDisplay(":0");
    if (display == NULL)
    {
        printf("OneSo:: Open Display Failed.\n");
        return;
    }
    int rlt = XSetSelectionOwner(display,1,1,1);
    printf("OneSo:: XSetSelectionOwner Rlt:%d\n",rlt);

}
$ ldd libOneSo.so 
	linux-vdso.so.1 (0x00007fffac99f000)
	libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x00007f599b5d1000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f599b3df000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f599b3d9000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f599b3b6000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f599b84d000)
	libxcb.so.1 => /lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f599b38a000)
	libXau.so.6 => /lib/x86_64-linux-gnu/libXau.so.6 (0x00007f599b384000)
	libXdmcp.so.6 => /lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f599b37c000)
	libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f599b362000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant