dzervas / injectionforge

Compile frida scripts into injectable libraries or executables that inject themselfs
58 stars 8 forks source link

:green_circle: (SOLVED) Failed to compile for arm64-v8a Android with Docker #46

Closed decryptable closed 4 days ago

decryptable commented 5 days ago

Is there something in my Dockerfile.Android configuration?

docker run -e FRIDA_CODE_FILE=/script.js -v ${pwd}/target:/injectionforge/target -v ${pwd}/myscript.js:/script.js injectionforge-android

My current customised Dockerfile.Android configuration:

FROM ubuntu

# Rust & sdkmanager
ARG TOOLS_VERSION=13.0
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y clang gcc git rustup google-android-cmdline-tools-${TOOLS_VERSION}-installer

# Set up cargo-ndk
ARG ARCH_TRIPLET_32=armv7-linux-androideabi
ARG ARCH_TRIPLET_64=aarch64-linux-android
RUN rustup default stable && cargo install cargo-ndk && \
    rustup target add ${ARCH_TRIPLET_32} && \
    rustup target install ${ARCH_TRIPLET_32} && \
    rustup target add ${ARCH_TRIPLET_64} && \
    rustup target install ${ARCH_TRIPLET_64}

# Install the NDK
ARG NDK_VERSION=25.2.9519653
RUN yes | sdkmanager --licenses && sdkmanager --install "ndk;${NDK_VERSION}"

# Required environment variables
ENV ANDROID_HOME="/usr/lib/android-sdk"
ENV ANDROID_NDK_HOME="/usr/lib/android-sdk/ndk/${NDK_VERSION}/"
ENV ANDROID_NDK_ROOT="${ANDROID_NDK_HOME}"

ARG NDK_ARCH_32=armeabi-v7a
ARG NDK_ARCH_64=arm64-v8a

COPY . /injectionforge
WORKDIR /injectionforge

# Run with: docker run -it --name iforge -v $(pwd):/injectionforge injectionforge:latest
CMD cargo ndk -t ${NDK_ARCH_32} --bindgen build --release && \
    cargo ndk -t ${NDK_ARCH_64} --bindgen build --release

Build log:

    Building armeabi-v7a (armv7-linux-androideabi)
    Updating git repository `https://github.com/dzervas/frida-rust`
    Updating crates.io index
 Downloading crates ...
  Downloaded base64 v0.22.1
  Downloaded http-body v1.0.1
  Downloaded scroll_derive v0.12.0

... other log

 Compiling injectionforge v0.1.0 (/injectionforge)
    Finished `release` profile [optimized] target(s) in 43.67s
    Building arm64-v8a (aarch64-linux-android)
   Compiling itoa v1.0.10
   Compiling ryu v1.0.17
   Compiling lazy_static v1.5.0
   Compiling serde v1.0.201
   Compiling thiserror v1.0.57
   Compiling frida-sys v0.13.7 (https://github.com/dzervas/frida-rust?branch=armhf-patches#278de57a)
warning: injectionforge@0.1.0: No dll_proxy set, the resulting library has to be manually injected or compiled into the target binary/process
error[E0463]: can't find crate for `core`
  |
  = note: the `aarch64-linux-android` target may not be installed
  = help: consider downloading the target with `rustup target add aarch64-linux-android`

error[E0463]: can't find crate for `std`
  |
  = note: the `aarch64-linux-android` target may not be installed
  = help: consider downloading the target with `rustup target add aarch64-linux-android`

For more information about this error, try `rustc --explain E0463`.
The following warnings were emitted during compilation:

warning: frida-sys@0.13.7: Frida core devkit not found, downloading from https://github.com/frida/frida/releases/download/16.3.3/frida-core-devkit-16.3.3-android-arm64.tar.xz...

error: could not compile `frida-sys` (lib) due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `ryu` (lib) due to 1 previous error
error: could not compile `itoa` (lib) due to 1 previous error
error: could not compile `thiserror` (lib) due to 1 previous error
error: could not compile `lazy_static` (lib) due to 1 previous error
error: could not compile `serde` (lib) due to 1 previous error
note: If the build failed due to a missing target, you can run this command:
note:
note:     rustup target install aarch64-linux-android
dzervas commented 4 days ago

as the log suggests, the rust toolchain for the target is missing. try to slim down the dockerfile to build only for aarch64-linux-android and see what's wrong

decryptable commented 4 days ago

Solved! I used @cross-rs/cross as an alternative.