diff --git a/junkcode/proguard-rules.pro b/junkcode/proguard-rules.pro index fc0cca0..8293362 100644 --- a/junkcode/proguard-rules.pro +++ b/junkcode/proguard-rules.pro @@ -21,4 +21,6 @@ #-renamesourcefileattribute SourceFile -dontshrink --keep class com.luoye.dpt.junkcode.JunkClass \ No newline at end of file +-keep class com.luoye.dpt.junkcode.JunkClass +-keep class com.luoye.dpt.junkcode.JunkClass1 +-keep class com.luoye.dpt.junkcode.JunkClass2 \ No newline at end of file diff --git a/junkcode/src/main/java/com/luoye/dpt/junkcode/JunkClass1.java b/junkcode/src/main/java/com/luoye/dpt/junkcode/JunkClass1.java new file mode 100644 index 0000000..000b9b4 --- /dev/null +++ b/junkcode/src/main/java/com/luoye/dpt/junkcode/JunkClass1.java @@ -0,0 +1,7 @@ +package com.luoye.dpt.junkcode; + +public class JunkClass1 { + public JunkClass1() { + System.exit(0); + } +} diff --git a/junkcode/src/main/java/com/luoye/dpt/junkcode/JunkClass2.java b/junkcode/src/main/java/com/luoye/dpt/junkcode/JunkClass2.java new file mode 100644 index 0000000..9b12a19 --- /dev/null +++ b/junkcode/src/main/java/com/luoye/dpt/junkcode/JunkClass2.java @@ -0,0 +1,7 @@ +package com.luoye.dpt.junkcode; + +public class JunkClass2 { + public JunkClass2() { + System.exit(0); + } +} diff --git a/shell/src/main/cpp/CMakeLists.txt b/shell/src/main/cpp/CMakeLists.txt index c98fbd0..274c1e1 100644 --- a/shell/src/main/cpp/CMakeLists.txt +++ b/shell/src/main/cpp/CMakeLists.txt @@ -9,6 +9,7 @@ set(DPT_NATIVE_SOURCE dpt_util.cpp dpt_risk.cpp rc4/rc4.c + common/dpt_string.c dex/dex_file.cpp dex/MultiDexCode.cpp dex/CodeItem.cpp diff --git a/shell/src/main/cpp/common/dpt_string.c b/shell/src/main/cpp/common/dpt_string.c new file mode 100644 index 0000000..9425eeb --- /dev/null +++ b/shell/src/main/cpp/common/dpt_string.c @@ -0,0 +1,42 @@ +// +// Created by luoyesiqiu on 2024/9/7. +// + +#include "dpt_string.h" + +int dpt_memcmp(const void *cs, const void *ct, size_t count) +{ + const unsigned char *su1, *su2; + int res = 0; + + for (su1 = (unsigned char *)cs, su2 = (unsigned char *)ct; 0 < count; ++su1, ++su2, count--) + if ((res = *su1 - *su2) != 0) + break; + return res; +} + +size_t dpt_strlen(const char *s) +{ + const char *sc; + + for (sc = s; *sc != '\0'; ++sc) + /* nothing */; + return sc - s; +} + +char *dpt_strstr(const char *s1, const char *s2) +{ + size_t l1, l2; + + l2 = dpt_strlen(s2); + if (!l2) + return (char *)s1; + l1 = dpt_strlen(s1); + while (l1 >= l2) { + l1--; + if (!dpt_memcmp(s1, s2, l2)) + return (char *)s1; + s1++; + } + return NULL; +} \ No newline at end of file diff --git a/shell/src/main/cpp/common/dpt_string.h b/shell/src/main/cpp/common/dpt_string.h new file mode 100644 index 0000000..e0d014c --- /dev/null +++ b/shell/src/main/cpp/common/dpt_string.h @@ -0,0 +1,18 @@ +// +// Created by luoyesiqiu on 2024/9/7. +// + +#ifndef DPT_DPT_STRING_H +#define DPT_DPT_STRING_H + +#include +#ifdef __cplusplus +extern "C" { +#endif +int dpt_memcmp(const void *cs, const void *ct, size_t count); +size_t dpt_strlen(const char *s); +char *dpt_strstr(const char *s1, const char *s2); +#ifdef __cplusplus +}; +#endif +#endif //DPT_DPT_STRING_H diff --git a/shell/src/main/cpp/dpt_hook.cpp b/shell/src/main/cpp/dpt_hook.cpp index 0a7fa70..1f0bd43 100644 --- a/shell/src/main/cpp/dpt_hook.cpp +++ b/shell/src/main/cpp/dpt_hook.cpp @@ -5,6 +5,7 @@ #include #include #include +#include "common/dpt_string.h" #include "dpt_hook.h" #include "dpt_risk.h" #include "bytehook.h" @@ -106,7 +107,7 @@ DPT_ENCRYPT void patchMethod(uint8_t *begin,__unused const char *location,uint32 } } else{ - DLOGE("[*] patchMethod cannot find dex: '%s' in dex map",location); + DLOGW("[*] patchMethod cannot find dex: '%s' in dex map",location); } } @@ -114,6 +115,13 @@ DPT_ENCRYPT void patchClass(__unused const char* descriptor, const void* dex_file, const void* dex_class_def) { + if(UNLIKELY(dpt_strstr(descriptor,"com/luoye/dpt/junkcode/JunkClass1") != nullptr + || dpt_strstr(descriptor,"com/luoye/dpt/junkcode/JunkClass2") != nullptr)) { + DLOGE("Find illegal call!"); + crash(); + return; + } + if(LIKELY(dex_file != nullptr)){ std::string location; uint8_t *begin = nullptr;