ptitSeb / box64

Box64 - Linux Userspace x86_64 Emulator with a twist, targeted at ARM64 Linux devices
https://box86.org
MIT License
3.81k stars 273 forks source link

Using BOX64_LD_PRELOAD to modify function arguments is ineffective. #1879

Closed zh522130 closed 3 weeks ago

zh522130 commented 3 weeks ago

I want to use BOX64_LD_PRELOAD to modify the arguments passed to a function. I have verified that this works on the x64 platform without any issues. However, when I use BOX64_LD_PRELOAD=myintercept.so box64 myapp to make the modification, the log shows that the modification was successful, but the final result indicates that the arguments were not actually modified.

zh522130 commented 3 weeks ago

I am not familiar with the box64 source code. If I were to modify the box64 source code myself to add the LD_PRELOAD dynamic library's source code into box64, mainly to modify the function arguments or the buffer pointed to by the passed pointer, how much work would it involve? Which parts would I need to modify? I hope to get some guidance.

zh522130 commented 3 weeks ago

It seems that the functions intercepted by BOX64_LD_PRELOAD are only called once. On the x64 platform, I see that the function is intercepted multiple times, but with box64, it is intercepted only once.

ptitSeb commented 3 weeks ago

Looks like an elf loader issue. I have to chec this. It should work, but there seems to be an issue somewhere...

zh522130 commented 3 weeks ago

Looks like an elf loader issue. I have to chec this. It should work, but there seems to be an issue somewhere...

From the observed phenomenon, I suspect that the issue is due to the dynamic library functions being intercepted only the first time they are loaded. When testing without restarting the program running under box64, every time the program reloads the dynamic library, the interception information is printed. However, if the dynamic library is not reloaded, and the function is called multiple times, the interception information will no longer be printed.

zh522130 commented 3 weeks ago

@ptitSeb Thank you. I think I should close this issue. I suspect that my earlier debugging caused some system problems. After I restarted the system, I could no longer reproduce the phenomenon. Now, LD_PRELOAD is working normally.

ptitSeb commented 3 weeks ago

Ok, glad it works!