open-obfuscator / o-mvll

:electron: O-MVLL is a LLVM-based obfuscator for native code (Android & iOS)
https://obfuscator.re/omvll
Apache License 2.0
574 stars 62 forks source link

Selective AArch32 Support? #16

Open weliveindetail opened 1 year ago

weliveindetail commented 1 year ago

Support for 32-bit targets would be interesting for Android targets, even though the primary focus for O-MVLL is AArch64. . Please consider this a starting point for a discussion, not more and not less.

When it comes to multi-target support, we can distinguish three types of passes right now:

  1. Target-agnostic passes, like Arithmetic, that already work
  2. Passes with hardcoded inline assembly, like CFG Flattening, can be fixed individually
  3. JIT-based passes, like String Encoding, that require multi-target support in the JIT

My first commit adds a minimal test for each of the given examples. Initially only type (1) passes. The others expectedly fail.

My second commit fixes the type (2) test. While the given inline assembly might be bogus, the patch isn't very invasive. The big benefit of the change behind the fix is, that we won't bail out in the compiler backend with a cryptic error message anymore in case of an incompatible triple. Instead, we'd deliberately fail with a reasonable error message right away. This approach doesn't add a ton of complexity. We could just keep iterating. Doing it right might improve the quality of the plugin.

JIT support isn't here yet, but maybe it's not terribly complicated either. Clang and ORC are multi-target ready from the start. And we only need to run the frontend anyway, because we don't aim to run the code generated for the target. We only inject the IR into the existing module.

Please note that this is implemented on-top of https://github.com/open-obfuscator/o-mvll/pull/14 (the two first commits) and should be rebased once it landed.

romainthomas commented 1 year ago

There are also other places where passes depend on the target architecture:

For ARM32, there might also be considerations for the thumb mode since the instruction's size can change compared to AArch64.