Skip to content

Commit

Permalink
Prevent illegal calls
Browse files Browse the repository at this point in the history
  • Loading branch information
luoyesiqiu committed Sep 7, 2024
1 parent 076bf1e commit d35fd00
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 2 deletions.
4 changes: 3 additions & 1 deletion junkcode/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@
#-renamesourcefileattribute SourceFile
-dontshrink

-keep class com.luoye.dpt.junkcode.JunkClass
-keep class com.luoye.dpt.junkcode.JunkClass
-keep class com.luoye.dpt.junkcode.JunkClass1
-keep class com.luoye.dpt.junkcode.JunkClass2
7 changes: 7 additions & 0 deletions junkcode/src/main/java/com/luoye/dpt/junkcode/JunkClass1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.luoye.dpt.junkcode;

public class JunkClass1 {
public JunkClass1() {
System.exit(0);
}
}
7 changes: 7 additions & 0 deletions junkcode/src/main/java/com/luoye/dpt/junkcode/JunkClass2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.luoye.dpt.junkcode;

public class JunkClass2 {
public JunkClass2() {
System.exit(0);
}
}
1 change: 1 addition & 0 deletions shell/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 42 additions & 0 deletions shell/src/main/cpp/common/dpt_string.c
Original file line number Diff line number Diff line change
@@ -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;
}
18 changes: 18 additions & 0 deletions shell/src/main/cpp/common/dpt_string.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Created by luoyesiqiu on 2024/9/7.
//

#ifndef DPT_DPT_STRING_H
#define DPT_DPT_STRING_H

#include <string.h>
#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
10 changes: 9 additions & 1 deletion shell/src/main/cpp/dpt_hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <map>
#include <unordered_map>
#include <dex/CodeItem.h>
#include "common/dpt_string.h"
#include "dpt_hook.h"
#include "dpt_risk.h"
#include "bytehook.h"
Expand Down Expand Up @@ -106,14 +107,21 @@ 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);
}
}

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;
Expand Down

0 comments on commit d35fd00

Please sign in to comment.