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

break_control_flow: No available targets are compatible with triple "aarch64-none-linux-android27" #33

Open
lry127 opened this issue Feb 13, 2024 · 12 comments
Labels
Android bug Something isn't working
Milestone

Comments

@lry127
Copy link

lry127 commented Feb 13, 2024

cmake can't compile a test program
host: ubuntu 2204 x86_64
app.gradle:

android {
    ndkVersion "25.0.8775105"
    compileSdk 34

    defaultConfig {
        minSdk 27
        targetSdk 34

        ndk {
            abiFilters 'arm64-v8a'
        }
        externalNativeBuild {
            cmake {
                cppFlags '-fpass-plugin=/home/ubuntu/Android/Sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/linux-x86_64/lib64/omvll_ndk_r25c.so'
                cFlags   '-fpass-plugin=/home/ubuntu/Android/Sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/linux-x86_64/lib64/omvll_ndk_r25c.so'
            }
        }
    }
}

C++ compiler (assembler) output:

The output was:
1
No available targets are compatible with triple "aarch64-none-linux-android27"


Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.
Compiler: /home/ubuntu/Android/Sdk/ndk/25.0.8775105/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ 
Build flags: -g;-DANDROID;-fdata-sections;-ffunction-sections;-funwind-tables;-fstack-protector-strong;-no-canonical-prefixes;-D_FORTIFY_SOURCE=2;-Wformat;-Werror=format-security;;-fpass-plugin=/home/ubuntu/Android/Sdk/ndk/25.2.9519653/toolchains/llvm/prebuilt/linux-x86_64/lib64/omvll_ndk_r25c.so
Id flags:  

The output was:
1
error: <inline asm>:3:11: unknown token in expression
  adr x1, #0x10;
          ^



Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" failed.

config file:

import omvll
from functools import lru_cache

class MyConfig(omvll.ObfuscationConfig):
    def __init__(self):
        super().__init__()

    def obfuscate_string(self, module: omvll.Module, func: omvll.Function,
                               string: bytes):

        return True

#     def anti_hooking(self, mod: omvll.Module, func: omvll.Function) -> omvll.AntiHookOpt:
#         if "nativeobfuscatetest" in func.name:
#             return True
#         return False

#     def anti_hooking(self, mod: omvll.Module, func: omvll.Function) -> omvll.AntiHookOpt:
#         return True


#     def anti_hooking(self, mod: omvll.Module, func: omvll.Function) -> omvll.AntiHookOpt:
#         return True

    def obfuscate_arithmetic(self, mod: omvll.Module,
                                   fun: omvll.Function) -> omvll.ArithmeticOpt:
        return True

    def break_control_flow(self, mod: omvll.Module, func: omvll.Function):
        return True

    def flatten_cfg(self, mod: omvll.Module, func: omvll.Function):
        return True

    def obfuscate_constants(_, __, func: omvll.Function):
        return True

    def obfuscate_struct_access(self, _: omvll.Module, __: omvll.Function,
                                      struct: omvll.Struct):
        return True

    def obfuscate_string(self, _, __, string: bytes):
        return omvll.StringEncOptStack()

@lru_cache(maxsize=1)
def omvll_get_config() -> omvll.ObfuscationConfig:
    """
    Return an instance of `ObfuscationConfig` which
    aims at describing the obfuscation scheme
    """
    return MyConfig()
@antoniofrighetto
Copy link
Collaborator

It seems the toolchain you're using (NDK clang on linux-x86_64) does not support the specified target architecture (aarch64-none-linux-android27). Could you please provide the output of the following command?

$ /home/ubuntu/Android/Sdk/ndk/25.0.8775105/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -print-targets

Is there aarch64-linux-android27-clang++ under /home/ubuntu/Android/Sdk/ndk/25.0.8775105/toolchains/llvm/prebuilt/linux-x86_64/bin?

@lry127
Copy link
Author

lry127 commented Feb 13, 2024

thanks for your help and here is the output

$ /home/ubuntu/Android/Sdk/ndk/25.0.8775105/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -print-targets
  Registered Targets:
    aarch64    - AArch64 (little endian)
    aarch64_32 - AArch64 (little endian ILP32)
    aarch64_be - AArch64 (big endian)
    arm        - ARM
    arm64      - ARM64 (little endian)
    arm64_32   - ARM64 (little endian ILP32)
    armeb      - ARM (big endian)
    bpf        - BPF (host endian)
    bpfeb      - BPF (big endian)
    bpfel      - BPF (little endian)
    thumb      - Thumb
    thumbeb    - Thumb (big endian)
    x86        - 32-bit X86: Pentium-Pro and above
    x86-64     - 64-bit X86: EM64T and AMD64

there is a c++ compiler on that path and in fact if i don't specify -fpass-plugin flag, code compiles without problem.

ubuntu@ubuntu:~$ ls /home/ubuntu/Android/Sdk/ndk/25.0.8775105/toolchains/llvm/prebuilt/linux-x86_64/bin | grep aarch64-linux-android27-clang++
aarch64-linux-android27-clang++

the full error logs are here:
CMakeOutput.log
CMakeError.log

and the ndk was downloaded from the offical sdk manager
image

@lry127
Copy link
Author

lry127 commented Feb 13, 2024

here is my gradle project with all sensitive information removed.
project.tar.gz
my environmental varibles are:

ubuntu@ubuntu:~/AndroidStudioProjects$ echo $LD_LIBRARY_PATH 
/home/ubuntu/Android/Sdk/ndk/25.0.8775105/toolchains/llvm/prebuilt/linux-x86_64/lib64
ubuntu@ubuntu:~/AndroidStudioProjects$ echo $OMVLL_CONFIG
/home/ubuntu/AndroidStudioProjects/NativeObfuscateTest3/ollvm-cfg.py
ubuntu@ubuntu:~/AndroidStudioProjects$ echo $OMVLL_PYTHONPATH 
/home/ubuntu/AndroidStudioProjects/NativeObfuscateTest3/Python-3.10.7/Lib

I followed the documentation found here and the version of o-mvll so file was release 1.0.3.
thanks for your kind help :)

@antoniofrighetto
Copy link
Collaborator

Thanks for the output. We are evaluating a few solutions, meanwhile would you disable break_control_flow in the config file for now? We tested it internally and it works correctly. We experienced other orthogonal issues in the execution though, so you may need to disable obfuscate_string too.

@lry127
Copy link
Author

lry127 commented Feb 14, 2024

Thanks for your advice. Code now compiles and executes correctly. I also found that obfuscate_string will still work provided that obfuscate_string returns omvll.StringEncOptGlobal() rather than omvll.StringEncOptStack().

@lry127
Copy link
Author

lry127 commented Feb 14, 2024

obfuscate_string works if the config file returns omvll.StringEncOptGlobal() and there's only one file contains string literals. Otherwise, errors are emitted by the linker because of duplicate symbol. For example, if two source files, say foo.cpp and bar.cpp, are compiled into one shared library and each contains one string literal, the linker will report the following error.

  ld: error: duplicate symbol: __omvll_decode
  >>> defined at foo.cpp
  >>>            CMakeFiles/nativeobfuscatetest3.dir/foo.cpp.o:(__omvll_decode)
  >>> defined at bar.cpp
  >>>            CMakeFiles/nativeobfuscatetest3.dir/bar.cpp.o:(.text.__omvll_decode+0x0)

@marcobrador
Copy link
Collaborator

Dear lry127,

Many thanks for your input. We managed to reproduce the issue but couldn't find a quick solution to it. Our focus right now is on iOS, so it might take a while until we can fix this, but eventually we will.

Best regards,
Marc

@lry127
Copy link
Author

lry127 commented Feb 16, 2024

I'm trying to compile the library on my own and studying the source code, I think maybe I can help with the android part after understanding major part of the code. :-)

@lry127 lry127 closed this as completed Feb 16, 2024
@marcobrador
Copy link
Collaborator

Awesome! Please let us know if you need any assistance, we'd be more than happy to help!

@marcobrador marcobrador reopened this Feb 19, 2024
@marcobrador
Copy link
Collaborator

Re-opening the issue as there's a bug that we have to figure out at some point, even if it doesn't have top prio

@marcobrador marcobrador added the bug Something isn't working label Feb 19, 2024
@antoniofrighetto
Copy link
Collaborator

Closing this, as implicitly solved by bd1440f, thanks @lry127 for the additional feedback.

@marcobrador marcobrador added this to the v1.1.0 milestone Mar 12, 2024
@marcobrador
Copy link
Collaborator

Hi @antoniofrighetto ,

I kept this open because of the issue related to break_control_flow. So I am reopening it and changing the title to avoid future confusion.

BR,
Marc

@marcobrador marcobrador reopened this Mar 19, 2024
@marcobrador marcobrador changed the title unknown token in expression break_control_flow: No available targets are compatible with triple "aarch64-none-linux-android27" Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants