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BySBgjf0vCwkqF1vaT3tvyavVtlMzHMU+GtvXs0hKoJApPOK8akF417qxWqhiliXTOHygkvTzUQR3AB9TxS1HOkM2yk6lrFTlaDKvFxDUCcIx0E4daht+67lD6SVuEVUpPfKovcRH7yFPcHbN/TEhdhd4YnFUNgUwVGqQ8IhTwQjVc78jIBKfq8qS+pCtKxxlZdmG/0Pd4eHAoGdoJQ7uUh2+jkMP3jA6RpjUV+xp5YzdifaGvSMDQKWgiWAnJsg/nTjL0gMYgImIoSvTy+//hNvWkNaDifSmdFVWfjNdvhozAHp0jWWx7h6B18/6DWxOIbv2k6rdSToZGfamnUGmv3Bgqu4cB6ElXEw0f5CJdtLhtrRP2an0Fz0vEBOrruAMEF8d/B8WytpiIG7NtKyOoc8aZDthGwjTqod5JkP3qw37yaI2qHgpeu9fYlBKYNIXKcADaWJKI5WOV+j+CnxVE+3QM5iAgXHVat3IRcMQ+jrURqfnTwdTYqWkO8Ip31qXiR9a9XL93RNH2qqp+VHKv7sMu5Rh7cdBz7VYkQRBJVBzq5ZliqwsR8V9Rf7tDnwg6FPER+9dejjWPI4QcUy8o5oV7GMPfaoHzim401GxKb+YNqHPKhnjTwUcW6tFPWmYa+qD1R5r5ePt6g/NbmhzEDv1cIW9WxkIX5E4AjHr3Gk09vO3Sccl5O+p0I5XGdvpf3UnOxT/7Bx7JYllx2XFzrUPZOgufunZWHcdn+YtR//BA==

Porting

The first step is setting up the build system. Let’s assume you’re about to port Frida to run on Linux/MIPS. As Frida already supports Linux, all we need to do is add the architecture-specific bits.

Porting the build system

Depending on the architecture, you may need to tweak releng/machine_spec.py. Review the generated machine file in build/, e.g. build/frida-linux-mips.txt, to make sure the toolchain is configured correctly.

Building frida-gum

This is the lowest level component and where most of the porting effort is typically needed. To build it, run:

$ git clone https://github.com/frida/frida-gum.git
$ cd frida-gum
$ make

This will probably not succeed, but should at least get the environment set up.

Once you get the code to compile, it’s time to focus on getting tests passing:

$ make test

You can also run a single test, e.g.

$ FRIDA_TEST_OPTIONS="--test-args='-p /Core/Process/process_modules' -v" make test

Porting frida-gum

Add the directory gum/backend-mips by duplicating for example gum/backend-arm64, and then search-replace everything. The important part to port here is guminterceptor-mips.c and gumspinlock-mips.c. You should leave gumstalker-mips.c as a stub, as it’s an advanced feature that takes a lot of effort to port.

Building frida-core

Now that frida-gum works, it’s time to repeat the same process for frida-core.

Porting frida-core

This should only be a matter of porting the injector. The implementation is here and the recommended approach is to follow the #if X86 breadcrumbs to port the architecture-specific bits. For a walkthrough of the Linux injector, check out our presentation here.