Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to cross-compile extension for host android arm64? #259

Open
Ragnoroct opened this issue Jan 22, 2025 · 0 comments
Open

How to cross-compile extension for host android arm64? #259

Ragnoroct opened this issue Jan 22, 2025 · 0 comments

Comments

@Ragnoroct
Copy link

Ragnoroct commented Jan 22, 2025

For the life of me I cannot figure out how to cross-compile this package to run on android arm64. I have a working python compilation but I can't get this package to work.

The furthest I got was compiling frida/_frida/_frida.abi3.so.p/extension.c.o by adding my cross-compiled python /include dir. It now fails trying to link frida/_frida/_frida.abi3.so because it can't find -lpthread, ect. Which sort of makes sense because android does not have those libs but it is included in their libc implementation.

What do I do to fix this? I want to run Python on my Android device via ADB and connect to the frida-server locally.

When I manually add my ndk lib as a -L link to LDFLAGS I just get more errors.
-L$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android

#27 98.04 ld: error: unable to find library -lpthread
#27 98.04 ld: error: unable to find library -lcrypt
#27 98.04 ld: error: unable to find library -lutil

The furthest I get is #27 98.04 [268/268] Linking target frida/_frida/_frida.abi3.so

#27 98.03 [267/268] Compiling C object frida/_frida/_frida.abi3.so.p/extension.c.o
#27 98.04 [268/268] Linking target frida/_frida/_frida.abi3.so
#27 98.04 FAILED: frida/_frida/_frida.abi3.so 
#27 98.04 /opt/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -target aarch64-none-linux-android21  -o frida/_frida/_frida.abi3.so frida/_frida/_frida.abi3.so.p/extension.c.o -L/cpython/cross-build/aarch64-linux-android/prefix/lib -Wl,--as-needed -Wl,--allow-shlib-undefined -shared -fPIC -Wl,-z,relro -Wl,-z,noexecstack -Wl,--gc-sections '-Wl,-rpath,$ORIGIN/../../subprojects/frida-core/src/api' -Wl,-rpath-link,/frida/build/subprojects/frida-core/src/api -Wl,--start-group subprojects/frida-core/src/api/libfrida-core-1.0.a subprojects/frida-gum/gum/libfrida-gum-1.0.a subprojects/frida-gum/bindings/gumjs/libfrida-gumjs-inspector-1.0.a subprojects/frida-core/lib/selinux/libfrida-selinux.a -Wl,--version-script,/frida/frida/_frida/extension.version -lpthread -ldl -lm -lcrypt -lutil /frida/deps/sdk-android-arm64/lib/libglib-2.0.a -pthread /frida/deps/sdk-android-arm64/lib/libiconv.a /frida/deps/sdk-android-arm64/lib/libpcre2-8.a /frida/deps/sdk-android-arm64/lib/libgobject-2.0.a /frida/deps/sdk-android-arm64/lib/libffi.a -Wl,--export-dynamic /frida/deps/sdk-android-arm64/lib/libgmodule-2.0.a /frida/deps/sdk-android-arm64/lib/libgio-2.0.a /frida/deps/sdk-android-arm64/lib/libz.a /frida/deps/sdk-android-arm64/lib/libgee-0.8.a /frida/deps/sdk-android-arm64/lib/libjson-glib-1.0.a -llog /frida/deps/sdk-android-arm64/lib/libcapstone.a /frida/deps/sdk-android-arm64/lib/libsoup-3.0.a /frida/deps/sdk-android-arm64/lib/libsqlite3.a /frida/deps/sdk-android-arm64/lib/libpsl.a /frida/deps/sdk-android-arm64/lib/libbrotlidec.a /frida/deps/sdk-android-arm64/lib/libbrotlicommon.a /frida/deps/sdk-android-arm64/lib/libnghttp2.a /frida/deps/sdk-android-arm64/lib/gio/modules/libgioopenssl.a /frida/deps/sdk-android-arm64/lib/libssl.a /frida/deps/sdk-android-arm64/lib/libcrypto.a /frida/deps/sdk-android-arm64/lib/libquickjs.a /frida/deps/sdk-android-arm64/lib/libselinux.a /frida/deps/sdk-android-arm64/lib/libsepol.a /frida/deps/sdk-android-arm64/lib/libnice.a /frida/deps/sdk-android-arm64/lib/libgthread-2.0.a /frida/deps/sdk-android-arm64/lib/libusrsctp.a /frida/deps/sdk-android-arm64/lib/liblzma.a /frida/deps/sdk-android-arm64/lib/libunwind.a /frida/deps/sdk-android-arm64/lib/libelf.a /frida/deps/sdk-android-arm64/lib/libdwarf.a /frida/deps/sdk-android-arm64/lib/libminizip.a -llog -Wl,--end-group
#27 98.04 ld: error: unable to find library -lpthread
#27 98.04 ld: error: unable to find library -lcrypt
#27 98.04 ld: error: unable to find library -lutil
#27 98.04 clang-14: error: linker command failed with exit code 1 (use -v to see invocation)
FROM ubuntu:20.04
# ... cross-compiles python parts omitted

# install dependencies
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y \
    # install dependencies
    curl unzip git tar xz-utils \
    # install nodejs
    && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
    && apt-get install -y nodejs \
    # install python
    && apt-get install -y software-properties-common \
    && add-apt-repository ppa:deadsnakes/ppa \
    && apt-get update \
    && apt-get install -y python3.9 python3.9-venv python3.9-distutils python3.9-dev python3-pip \
    && python3.9 -m pip install --upgrade pip setuptools \
    # frida build dependencies \
    && apt-get install -y build-essential git lib32stdc++-9-dev libc6-dev-i386 \
    # clean
    && apt-get clean

# install ndk
RUN curl -L https://dl.google.com/android/repository/android-ndk-r25c-linux.zip -o /tmp/android-ndk.zip && \
    unzip -q /tmp/android-ndk.zip -d /opt && \
    rm /tmp/android-ndk.zip
ENV ANDROID_NDK_ROOT=/opt/android-ndk-r25c

# fetch frida-python git repo
ENV VERSION_FRIDA="16.6.2"
RUN git clone --depth 1 https://github.com/frida/frida-python.git /frida \
    && cd /frida \
    && git fetch --depth 1 origin "$VERSION_FRIDA" \
    && git fetch origin refs/tags/$VERSION_FRIDA:refs/tags/$VERSION_FRIDA \
    && git checkout refs/tags/"$VERSION_FRIDA" \
    && git checkout -b "$VERSION_FRIDA-branch" \
    && git submodule update --init --recursive --depth 1

RUN curl -L https://github.com/frida/frida/releases/download/$VERSION_FRIDA/frida-core-devkit-$VERSION_FRIDA-android-arm64.tar.xz -o /tmp/download.tar.xz && \
    mkdir /frida-core-devkit && \
    tar -xf /tmp/download.tar.xz --strip-components=1 -C /frida-core-devkit && \
    rm /tmp/download.tar.xz

# note python3.9 was installed using apt-get. when I tried the cross-compile I got ELF errors... :P
WORKDIR /frida
ENV CFLAGS="-I/cpython/cross-build/aarch64-linux-android/prefix/include/python3.13"
ENV LDFLAGS="-L/cpython/cross-build/aarch64-linux-android/prefix/lib"
RUN python3.9 -m venv /tmp/venv-builder && \
    . /tmp/venv-builder/bin/activate && \
    ./configure --host=android-arm64 \
    && make
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant