Skip to content

Commit

Permalink
refactor: split v2sign header and impl apart
Browse files Browse the repository at this point in the history
  • Loading branch information
cinit committed Oct 12, 2023
1 parent 44d676a commit d32860e
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 58 deletions.
2 changes: 2 additions & 0 deletions app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
53 changes: 53 additions & 0 deletions app/src/main/cpp/misc/md5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,59 @@

#include <utility>

/* 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)) {}
Expand Down
55 changes: 1 addition & 54 deletions app/src/main/cpp/misc/md5.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,62 +6,9 @@
#define MD5_H

#include <bitset>
#include <iostream>
#include <string>
#include <vector>

/* 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/cpp/misc/vxsign.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Created by sulfate on 2023-10-12.
//

#ifndef QAUXV_VXSIGN_H
#define QAUXV_VXSIGN_H

#include <cstdint>
#include <string>
#include <jni.h>

namespace teble::v2sign {

bool checkSignature(JNIEnv* env, bool isInHostAsModule);

}

#endif //QAUXV_VXSIGN_H
4 changes: 2 additions & 2 deletions app/src/main/cpp/qauxv_core/Natives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d32860e

Please sign in to comment.