CyberShadow / hax11

Hackbrary to Hook and Augment X11 protocol calls
MIT License
116 stars 9 forks source link

How to enable hax11 for all apps by default #6

Closed d9k closed 1 year ago

d9k commented 2 years ago

Hi!

To try this library, build this library as above, then in the same directory, run the following in a shell:

$ export LD_PRELOAD=`pwd`/\$LIB/hax11.so

Then, from the same shell session, start the desired game or application.

How to preload hax11.so for ALL apps automatically? I tried to add

export LD_PRELOAD=/path/to/hax11.so

to ~/.xsessionrc, ~/.bashrc, ~/profile and even to /etc/environment but nothing works: library is used only when I start GUI app from terminal emulator.

CyberShadow commented 2 years ago

In theory, sudo make install and reboot:

https://github.com/CyberShadow/hax11/blob/d9fa9248fa4cefe5080e56984006b90accae94c0/Makefile#L27

d9k commented 2 years ago

@CyberShadow, thanks, but no luck

> cat /etc/profile.d/hax11.sh 
export LD_PRELOAD=/usr/local/lib64/hax11.so 
> ll /usr/local/lib64/hax11.so
-rw-r--r-- 1 root root 89K Dec 28 00:34 /usr/local/lib64/hax11.so
> cat ~/.config/hax11/profiles/default
Enable=1
NoPrimarySelection=1
> cat /etc/lsb-release
DISTRIB_ID=LinuxMint
DISTRIB_RELEASE=19
DISTRIB_CODENAME=tara
DISTRIB_DESCRIPTION="Linux Mint 19 Tara"
> cat /etc/upstream-release/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04 LTS"
> uname -r
4.15.0-163-generic
CyberShadow commented 2 years ago

How do you know it's not working?

Is it in LD_PRELOAD?

If it is, do you get log output with Debug=1 in the default config file?

d9k commented 2 years ago

How do you know it's not working?

When I start app from terminal emulator select-to-copy is disabled (as I want). When I start app from Alt+F2 launcher select-to-copy isn't disabled.

CyberShadow commented 2 years ago

Got it. Can you try putting LD_PRELOAD=/usr/local/$LIB/hax11.so in /etc/environment and see if that helps.

d9k commented 2 years ago

@CyberShadow, It's already there:

> cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
QT_QPA_PLATFORMTHEME=gtk2
QT_STYLE_OVERRIDE=gtk2

export LD_PRELOAD=/home/d9k/soft/hax11/lib64/hax11.so

Upd: I'll try to set another path and reboot.

CyberShadow commented 2 years ago

No export, it is not a shell script.

Also $LIB must be there verbatim, it is not a shell variable.

d9k commented 2 years ago

Got alert window on startup:

ERROR: ld.so: object '/usr/local/$LIB/hax11.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file)
> cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
QT_QPA_PLATFORMTHEME=gtk2
QT_STYLE_OVERRIDE=gtk2

LD_PRELOAD=/usr/local/$LIB/hax11.so

> cat /etc/profile.d/hax11.sh 
export LD_PRELOAD=/usr/local/\$LIB/hax11.so 

There is slash in cat /etc/profile.d/hax11.sh (created by sudo make install). Is it an error?

CyberShadow commented 2 years ago

There is slash in cat /etc/profile.d/hax11.sh (created by sudo make install). Is it an error?

No, it prevents the shell from interpreting the $ as the variable name prefix.

Could you please try the following:

d9k commented 2 years ago

Post the output from env | grep LD_PRELOAD when you run it in a terminal.

env | grep LD_PRELOAD
LD_PRELOAD=/usr/local/lib64/hax11.so

Run the program via Alt-F2, and then run...

> pgrep textadept | head -1
17585
> cat /proc/$(pgrep textadept | head -1)/environ | xargs -0 -n 1 echo | grep LD_PRELOAD

— nothing

CyberShadow commented 2 years ago

So I guess the launcher program (that runs on Alt-F2) is either unaffected by both /etc/environment and /etc/profile, or for whatever reason it intentionally unsets LD_PRELOAD. I'm not sure what that is without more information; I think the program's authors would be more helpful in figuring it out.

If your desktop environment supports .xinitrc or .xinitrc.d, you could try adding source /etc/profile.d/hax11.sh there.

On a more practical note, you could make a script around the target program which sets LD_PRELOAD:

#!/bin/sh
source /etc/profile.d/hax11.sh 
exec /path/to/real-program "$@"
d9k commented 2 years ago

If I put

export LD_PRELOAD=/usr/local/\$LIB/hax11.so

into /etc/profile.d/hax11.sh there is alert window on cinnamon startup:

ERROR: ld.so: object '/usr/local/$LIB/hax11.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file)

For

export LD_PRELOAD=/usr/local/$LIB/hax11.so

alert says:

ERROR: ld.so: object '/usr/local//hax11.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file)

And when

export LD_PRELOAD=/usr/local/lib64/hax11.so

it just silently doesn't work for run dialog apps.

BTW, I commented out export LD_PRELOAD... in ~/.profile and echo $LD_PRELOAD became empty in terminal emulator after the reboot too!

So user apps ignore env variables exported from /etc/profile.d somehow...

CyberShadow commented 2 years ago

there is alert window on cinnamon startup:

You should have these files:

(actually 2 files, lib64 should be a symlink to lib or the other way around)

Please check that the files are there.

d9k commented 2 years ago
> ll /usr/local/lib32/hax11.so 
-rw-r--r-- 1 root root 80K Dec 28 01:24 /usr/local/lib32/hax11.so

> ll /usr/local/lib64/hax11.so
-rw-r--r-- 1 root root 89K Dec 28 01:24 /usr/local/lib64/hax11.so

> ll /usr/local/lib/hax11.so 
/bin/ls: cannot access '/usr/local/lib/hax11.so': No such file or directory
d9k commented 2 years ago

If I export another variable from hax11.sh it's visible in terminal after reboot

> cat /etc/profile.d/hax11.sh
export LD_PRELOAD=/usr/local/lib64/hax11.so
export ETC_PROFILE_HAX11_LOADED=1
> echo $ETC_PROFILE_HAX11_LOADED
1
echo $LD_PRELOAD              

# empty
CyberShadow commented 2 years ago

Try sudo mv /usr/local/lib64/hax11.so /usr/local/lib/ && sudo rmdir /usr/local/lib64 && sudo ln -s lib /usr/local/lib64

d9k commented 2 years ago

thanks, tried, there is the same alert window on cinnamon startup:

ERROR: ld.so: object '/usr/local/$LIB/hax11.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file)

> ll /usr/local/lib32/hax11.so 
-rw-r--r-- 1 root root 80K Dec 28 01:24 /usr/local/lib32/hax11.so

> ll /usr/local/lib64/hax11.so 
-rw-r--r-- 1 root root 89K Dec 28 01:24 /usr/local/lib64/hax11.so

> ll /usr/local/lib/hax11.so 
-rw-r--r-- 1 root root 89K Dec 28 01:24 /usr/local/lib/hax11.so

> cat /etc/profile.d/hax11.sh
export LD_PRELOAD=/usr/local/\$LIB/hax11.so
export ETC_PROFILE_HAX11_LOADED=1

> echo $ETC_PROFILE_HAX11_LOADED
1

> echo $LD_PRELOAD              

# empty
CyberShadow commented 2 years ago

Strange. I don't know why.

What about other apps?

d9k commented 2 years ago

What about other apps?

The log is not created at all

> cat ~/.config/hax11/profiles/default
Enable=1
NoPrimarySelection=1
Debug=1

> ll /tmp/hax11.log
/bin/ls: cannot access '/tmp/hax11.log': No such file or directory
d9k commented 2 years ago

I'll try to grep LD_PRELOAD= in system files

CyberShadow commented 2 years ago
> cat /etc/profile.d/hax11.sh
export LD_PRELOAD=/usr/local/\$LIB/hax11.so
export ETC_PROFILE_HAX11_LOADED=1

> echo $ETC_PROFILE_HAX11_LOADED
1

> echo $LD_PRELOAD              

# empty

That is interesting - I guess it's blacklisted by something.

I found this: https://github.com/linuxmint/cinnamon-session/issues/15 There is a suggestion to use .xsessionrc.

d9k commented 2 years ago

I tried ~/.xsessionrc (see the opening message https://github.com/CyberShadow/hax11/issues/6#issue-1089482470). And now I also tried ~/.xinitrc as https://github.com/linuxmint/cinnamon-session/issues/15#issuecomment-657830973 advices and there is some luck, thanks! Looks like hax11.so was loaded for some apps on boot:

> tail /tmp/hax11.log
[4398] Server connection setup reply: 1
[15632] Found X connection!
[15632] Intercepting X connection!
[15632] Server connection setup reply: 1
[15632]  Selection atom: 359
[15632]  Selection atom: 322
[15632] Found X connection!
[15632] Intercepting X connection!
[15632] Server connection setup reply: 1
[15632] Exiting work thread.

But not for apps when I start them from the run dialog (alt+F2)....

Terminal emulator doesn't see LD_PRELOAD variable either.

CyberShadow commented 2 years ago

OK. I suggest seeking support from your distribution. Unfortunately I don't know Linux Mint, and LD_PRELOAD being unset by other software is not really a bug in hax11.

Let's keep this issue open to continue the discussion for a better way to install hax11 system-wide.

d9k commented 2 years ago

Added debug exports LOADED_* variables to most known configs

Terminal emulator:

> env | grep LOADED
LOADED_ZSHRC=1
LOADED_ETC_PROFILE_HAX11=1
LOADED_PROFILE=1
LOADED_XSESSIONRC=1

LD_PRELOAD is being set only from ~/.zshrc

textadept app (started from alt+F2):

> cat /proc/$(pgrep textadept | head -1)/environ | xargs -0 -n 1 echo | grep LOADED
LOADED_PROFILE=1
LOADED_ETC_PROFILE_HAX11=1
LOADED_XSESSIONRC=1

LD_PRELOAD is never set.

~/.xinitrc is not loaded at all, that was my mistake.

d9k commented 2 years ago

Created thread on Linux Mint forum

CyberShadow commented 1 year ago

I'll close this as it can't be fixed by a change to this repository. Hopefully someone can figure out how to set environment variables in Linux Mint / Cinnamon.