From d32860e4dc8d5c66a6ceb8dd218b7e41ceded728 Mon Sep 17 00:00:00 2001 From: ACh Sulfate Date: Thu, 12 Oct 2023 22:34:54 +0800 Subject: [PATCH] refactor: split v2sign header and impl apart --- app/src/main/cpp/CMakeLists.txt | 2 + app/src/main/cpp/misc/md5.cpp | 53 ++++++++++++++++++ app/src/main/cpp/misc/md5.h | 55 +------------------ app/src/main/cpp/misc/{v2sign.h => v2sign.cc} | 4 +- app/src/main/cpp/misc/vxsign.h | 18 ++++++ app/src/main/cpp/qauxv_core/Natives.cpp | 4 +- 6 files changed, 78 insertions(+), 58 deletions(-) rename app/src/main/cpp/misc/{v2sign.h => v2sign.cc} (99%) create mode 100644 app/src/main/cpp/misc/vxsign.h diff --git a/app/src/main/cpp/CMakeLists.txt b/app/src/main/cpp/CMakeLists.txt index a1519c5583..543ddf9fda 100644 --- a/app/src/main/cpp/CMakeLists.txt +++ b/app/src/main/cpp/CMakeLists.txt @@ -53,6 +53,8 @@ target_compile_definitions(fmt-header-only INTERFACE FMT_STATIC_THOUSANDS_SEPARA add_library(qauxv SHARED misc/version.c + misc/v2sign.cc + misc/md5.cpp ../../../../libs/dexkit/DexKit/dexkit/src/main/cpp/native-bridge.cpp diff --git a/app/src/main/cpp/misc/md5.cpp b/app/src/main/cpp/misc/md5.cpp index a275379fd5..4000061533 100644 --- a/app/src/main/cpp/misc/md5.cpp +++ b/app/src/main/cpp/misc/md5.cpp @@ -6,6 +6,59 @@ #include +/* Parameters of MD5. */ +#define S11 7 +#define S12 12 +#define S13 17 +#define S14 22 +#define S21 5 +#define S22 9 +#define S23 14 +#define S24 20 +#define S31 4 +#define S32 11 +#define S33 16 +#define S34 23 +#define S41 6 +#define S42 10 +#define S43 15 +#define S44 21 + +#define F(x, y, z) (((x) & (y)) | ((~(x)) & (z))) +#define G(x, y, z) (((x) & (z)) | ((y) & (~(z)))) +#define H(x, y, z) ((x) ^ (y) ^ (z)) +#define I(x, y, z) ((y) ^ ((x) | (~(z)))) + +#define ROTATELEFT(num, n) (((num) << (n)) | ((num) >> (32 - (n)))) + +/** + * @Transformations for rounds 1, 2, 3, and 4. + */ +#define FF(a, b, c, d, x, s, ac) \ + { \ + (a) += F((b), (c), (d)) + (x) + (ac); \ + (a) = ROTATELEFT((a), (s)); \ + (a) += (b); \ + } +#define GG(a, b, c, d, x, s, ac) \ + { \ + (a) += G((b), (c), (d)) + (x) + (ac); \ + (a) = ROTATELEFT((a), (s)); \ + (a) += (b); \ + } +#define HH(a, b, c, d, x, s, ac) \ + { \ + (a) += H((b), (c), (d)) + (x) + (ac); \ + (a) = ROTATELEFT((a), (s)); \ + (a) += (b); \ + } +#define II(a, b, c, d, x, s, ac) \ + { \ + (a) += I((b), (c), (d)) + (x) + (ac); \ + (a) = ROTATELEFT((a), (s)); \ + (a) += (b); \ + } + MD5::MD5() = default; MD5::MD5(std::string str) : input_msg(std::move(str)) {} diff --git a/app/src/main/cpp/misc/md5.h b/app/src/main/cpp/misc/md5.h index c1b1d3b212..9595797576 100644 --- a/app/src/main/cpp/misc/md5.h +++ b/app/src/main/cpp/misc/md5.h @@ -6,62 +6,9 @@ #define MD5_H #include -#include +#include #include -/* Parameters of MD5. */ -#define S11 7 -#define S12 12 -#define S13 17 -#define S14 22 -#define S21 5 -#define S22 9 -#define S23 14 -#define S24 20 -#define S31 4 -#define S32 11 -#define S33 16 -#define S34 23 -#define S41 6 -#define S42 10 -#define S43 15 -#define S44 21 - -#define F(x, y, z) (((x) & (y)) | ((~(x)) & (z))) -#define G(x, y, z) (((x) & (z)) | ((y) & (~(z)))) -#define H(x, y, z) ((x) ^ (y) ^ (z)) -#define I(x, y, z) ((y) ^ ((x) | (~(z)))) - -#define ROTATELEFT(num, n) (((num) << (n)) | ((num) >> (32 - (n)))) - -/** - * @Transformations for rounds 1, 2, 3, and 4. - */ -#define FF(a, b, c, d, x, s, ac) \ - { \ - (a) += F((b), (c), (d)) + (x) + (ac); \ - (a) = ROTATELEFT((a), (s)); \ - (a) += (b); \ - } -#define GG(a, b, c, d, x, s, ac) \ - { \ - (a) += G((b), (c), (d)) + (x) + (ac); \ - (a) = ROTATELEFT((a), (s)); \ - (a) += (b); \ - } -#define HH(a, b, c, d, x, s, ac) \ - { \ - (a) += H((b), (c), (d)) + (x) + (ac); \ - (a) = ROTATELEFT((a), (s)); \ - (a) += (b); \ - } -#define II(a, b, c, d, x, s, ac) \ - { \ - (a) += I((b), (c), (d)) + (x) + (ac); \ - (a) = ROTATELEFT((a), (s)); \ - (a) += (b); \ - } - typedef unsigned int bit32; class MD5 { diff --git a/app/src/main/cpp/misc/v2sign.h b/app/src/main/cpp/misc/v2sign.cc similarity index 99% rename from app/src/main/cpp/misc/v2sign.h rename to app/src/main/cpp/misc/v2sign.cc index 685eaaae11..34d4ab43b0 100644 --- a/app/src/main/cpp/misc/v2sign.h +++ b/app/src/main/cpp/misc/v2sign.cc @@ -12,7 +12,7 @@ #include "utils/Log.h" #include "zip_helper.h" -#include "md5.cpp" +#include "md5.h" #ifndef MODULE_SIGNATURE #define MODULE_SIGNATURE 294E0ABF933AAA14C6EB986A005E5CCB @@ -59,7 +59,7 @@ int dumpMemory(int fd, const void *address, size_t size) { } -namespace { +namespace teble::v2sign { const char magic[16]{ 0x32, 0x34, 0x20, 0x6b, 0x63, 0x6f, 0x6c, 0x42, 0x20, 0x67, 0x69, 0x53, 0x20, 0x4b, 0x50, 0x41, diff --git a/app/src/main/cpp/misc/vxsign.h b/app/src/main/cpp/misc/vxsign.h new file mode 100644 index 0000000000..472b8f7cd0 --- /dev/null +++ b/app/src/main/cpp/misc/vxsign.h @@ -0,0 +1,18 @@ +// +// Created by sulfate on 2023-10-12. +// + +#ifndef QAUXV_VXSIGN_H +#define QAUXV_VXSIGN_H + +#include +#include +#include + +namespace teble::v2sign { + +bool checkSignature(JNIEnv* env, bool isInHostAsModule); + +} + +#endif //QAUXV_VXSIGN_H diff --git a/app/src/main/cpp/qauxv_core/Natives.cpp b/app/src/main/cpp/qauxv_core/Natives.cpp index 32a427b38a..d6b75f6eaa 100644 --- a/app/src/main/cpp/qauxv_core/Natives.cpp +++ b/app/src/main/cpp/qauxv_core/Natives.cpp @@ -16,7 +16,7 @@ #include "Natives.h" #include "utils/shared_memory.h" -#include "misc/v2sign.h" +#include "misc/vxsign.h" static bool throwIfNull(JNIEnv *env, jobject obj, const char *msg) { if (obj == nullptr) { @@ -419,7 +419,7 @@ EXPORT extern "C" jint JNI_OnLoad(JavaVM *vm, void *reserved) { env->ExceptionClear(); } #if defined(NDEBUG) || defined(TEST_SIGNATURE) - if (!checkSignature(env, appInterface != nullptr)) { + if (!::teble::v2sign::checkSignature(env, appInterface != nullptr)) { return -1; } #endif