JustasMasiulis / xorstr

heavily vectorized c++17 compile time string encryption.
Apache License 2.0
1.19k stars 193 forks source link

Android ARM support? #39

Closed ghost closed 3 years ago

ghost commented 3 years ago

I can't use this because of AVX2 types that are not available for ARM. Can you make it support for ARM for Android?

SpriteOvO commented 3 years ago

Did you try to define JM_XORSTR_DISABLE_AVX_INTRINSICS macro before including xorstr.hpp?

ghost commented 3 years ago

I didn't, but now I tried, still getting errors

E:/androidsdk/ndk/22.0.7026061/build//../toolchains/llvm/prebuilt/windows-x86_64\lib64\clang\11.0.5\include\mmintrin.h:33:25: error:
      too few arguments to function call, expected 2, have 0
    __builtin_ia32_emms();
                        ^
E:/androidsdk/ndk/22.0.7026061/build//../toolchains/llvm/prebuilt/windows-x86_64\lib64\clang\11.0.5\include\mmintrin.h:50:19: error:
      use of undeclared identifier '__builtin_ia32_vec_init_v2si'
    return (__m64)__builtin_ia32_vec_init_v2si(__i, 0);
                  ^
E:/androidsdk/ndk/22.0.7026061/build//../toolchains/llvm/prebuilt/windows-x86_64\lib64\clang\11.0.5\include\mmintrin.h:67:12: error:
      use of undeclared identifier '__builtin_ia32_vec_ext_v2si'
    return __builtin_ia32_vec_ext_v2si((__v2si)__m, 0);
           ^
E:/androidsdk/ndk/22.0.7026061/build//../toolchains/llvm/prebuilt/windows-x86_64\lib64\clang\11.0.5\include\mmintrin.h:129:19: error:
      use of undeclared identifier '__builtin_ia32_packsswb'
    return (__m64)__builtin_ia32_packsswb((__v4hi)__m1, (__v4hi)__m2);
JustasMasiulis commented 3 years ago

I can't use this because of AVX2 types that are not available for ARM. Can you make it support for ARM for Android?

Sure thing. Will do it today/tomorrow

Did you try to define JM_XORSTR_DISABLE_AVX_INTRINSICS macro before including xorstr.hpp?

That doesn't change anything if he's on ARM

JustasMasiulis commented 3 years ago

Sure thing. Will do it today/tomorrow

Sorry for the horrible time estimate.

It should now be working on arm64 on gcc, clang, MSVC. 32 bit support is still a bit broken (gcc is fine, but clang is unhappy). Also do note that since I don't have an arm machine I have no idea if this actually works 🤷

ghost commented 3 years ago

No problem. It compiles perfectly on Android Studio which is using NDK (clang) and works fine on ARMv7 and ARM64 Android emulators

Now the only problem is xorstr doesn't seems to work on const char *example[] like nothing is added to it and sometimes it crashes (I replaced all OBFUSCATE to xorstr_) https://github.com/LGLTeam/Android-Mod-Menu/blob/master/app/src/main/jni/Main.cpp#L173

If in any case you want to test on ARM system, you can try compile this project and run on any Android emulators without having to use a physical phone https://github.com/LGLTeam/Android-Mod-Menu

JustasMasiulis commented 3 years ago

Now the only problem is xorstr doesn't seems to work on const char *example[] like nothing is added to it and sometimes it crashes (I replaced all OBFUSCATE to xorstr_)

Will have to investigate this. Do you know what is the exception by chance?

If in any case you want to test on ARM system, you can try compile this project and run on any Android emulators without having to use a physical phone

Thanks.

ghost commented 3 years ago

Nvm, the crash seems to be emulator issue. I use a stable version, no crashes, and removed x86 from build.grade to run the app as ARM instead since we don't need x86. Emulators are x86/x86_64 natively but has ARM/ARM64 translation, they run perfectly without native x86 support

So the issue is, sometimes the first item or the last item is missing. It works without xor and if using its own obfuscate

    const char *features[] = {
            xorstr_("InputValue_Input 1"),
            xorstr_("InputValue_Input 2"),
            xorstr_("InputValue_Input 3"),
    };

image

JustasMasiulis commented 3 years ago

Hey, so this isn't exactly correct usage. You need a new macro that saves the xorstr in a static buffer and returns it, like your current OBFUSCATE does, because right now you have an array of pointers to stack memory that's not used anymore.

Here's a a drop-in solution for you.

#define static_xorstr(x) []() { static const auto decrypted = [](){ auto encrypted = xorstr(x); encrypted.crypt(); return encrypted; }(); return decrypted.get(); }()
ghost commented 3 years ago

Thanks, everything is working now!

JustasMasiulis commented 3 years ago

Thanks, everything is working now!

Glad to hear 👍

I'll close the issue then. If any more problems arise feel free to reopen this one or create a new one.