frida / frida-rust

Frida Rust bindings
Other
176 stars 46 forks source link

Fix building on Android #112

Open saruman9 opened 11 months ago

saruman9 commented 11 months ago

This PR contains several workarounds in order to be able to use the crate for Android. Some of them look quite messy, but unfortunately I couldn't find a way to do it better.

For NDK versions 25 and higher, it is also necessary to create a symbolic link to ar, since there is no longer the ability to set custom ar in Rust (cargo config, codegen options):

$ ln -s ./llvm-ar $ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android-ar
$ ln -s ./llvm-ar $ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android-ar

If someone knows how to solve this, then I will add it to the PR.

saruman9 commented 11 months ago

Surely there is a better solution?

To be honest, I'm not sure, I tried to do it as much as possible without the user's involvement, but this is impossible, because in addition to having to create symbolic links, you still have to set environment variables for Android.

FYI https://github.com/rust-lang/cargo/issues/12183#issuecomment-1563860569

meme commented 11 months ago

Symlinks are a no-go because they don't function correctly under Windows. Honestly, I'm not clear on why it's needed at all because we have the frida-build crate which is around to provide shared code for build.rs. Can we use that instead please? Thanks.

saruman9 commented 11 months ago

Unfortunately, I did not find any way to set the path to ar (the Rust developers removed this feature), including via build.rs or Cargo config file. And anyway: making changes to Android NDK by Frida --- is wrong. An user himself must understand what he/she is doing, what he/she is making changes to the files already installed on his/her system.

These changes (including symlinks) are only necessary to build and run examples or libraries and executables that will include Frida as a dependency:

I can delete them, nothing will change from this except that the examples will no longer be built for Android platform. I added these changes so that an user would have an example of how and what to do to build Frida as a dependency for his/her Android project, but unfortunately I still run into a problem with ar.

Once again, I did not find another way to set the path to ar, so I had to modify the files as part of Android NDK. If someone knows the solution, then I would be happy to add it to the PR!