Reputation: 212
I want to learn how to preload and hook functions in wine running windows apps.
I'm trying to preload a library with ld_preload
to wine(windows game(32-bit)) on Arch Linux (64-bit but I think I installed 32-bit support). I get the error wrong ELF class: ELFCLASS32
and the same for ELFCLASS64
.
Full error text:
"ERROR: ld.so: object './eve.so' from LD_PRELOAD cannot be preloaded (wrong ELF class: ELFCLASS32): ignored."
the same for 64bit and another one
ERROR: ld.so: object './eve.so' from LD_PRELOAD cannot be preloaded (cannot open shared object file): ignored.
How am I getting "wrong class" when I have both 32 and 64-bit installed? What architecture do I need to make it work right?
Wow.exe:
Wow.exe: PE32 executable (GUI) Intel 80386, for MS Windows
I tried to build with and without the -m32
flag ( I changed all uint32
to uint64
):
gcc -std=c99 -Wall -Werror -m32 -O0 -fpic -shared -ldl -lGL -o eve.so eve.c
I saw this answer:
ltrace /lib/ld-linux.so.2 --preload /path/to/lib/strcmp.so ./exec
But don't know how to run it with wine running the app.
I want to learn how to preload and hook functions in wine running windows apps. I saw this guide: https://www.ownedcore.com/forums/world-of-warcraft/world-of-warcraft-bots-programs/wow-memory-editing/276206-linux-simple-injection-ld_preload.html
Upvotes: 2
Views: 2605
Reputation: 12064
The wrong ELF class: ELFCLASS32
means you are trying to inject a 32-bit program into a 64-bit process. This would lead me to believe your game is 64-bit, and you should compile your libraries as 64-bit as well. But since you mention you saw the error for 64-bits as well, it would be best to check your wine installation directly. Run pacman -Q --info wine
to check.
The second error message you reported, cannot open shared object file
, means the dynamic linker can't find your library. Double check all your file paths. Instead of using the relative import ./eve.so
, use a full absolute path (/path/to/lib/eve.so
) so there's no ambiguity to the system. You usually want to specify an absolute path to LD_PRELOAD. The reason is that it being an environment variable, it's inherited by child processes - which may have a different working directory than the parent process. So any relative path would fail to locate the library to preload.
As for how to set the environment variable in Wine, wine
passes on the entire shell environment variable space to the Windows environment variable space, so you just set the variable in Linux beforehand and it will be available to the game inside wine:
export LD_PRELOAD=/path/to/lib/eve.so
wine ...
As another note, LD_PRELOAD
will affect the wine
loader only. If you would like to affect wineserver
as well:
wineserver -k
export LD_PRELOAD=...
wine ...
Finally, see this post for more details if this still isn't working for you, it's a more in depth explanation of how to do injection into wine
specifically.
Upvotes: 1