Skip to content

Commit

Permalink
Add encrypt annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
luoyesiqiu committed Aug 3, 2024
1 parent 0eaddb6 commit 997b238
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
32 changes: 16 additions & 16 deletions shell/src/main/cpp/dpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static JNINativeMethod gMethods[] = {
{"ra", "(Ljava/lang/String;)Ljava/lang/Object;", (void *) replaceApplication}
};

jobjectArray makePathElements(JNIEnv* env,const char *pathChs) {
DPT_ENCRYPT jobjectArray makePathElements(JNIEnv* env,const char *pathChs) {
jstring path = env->NewStringUTF(pathChs);
java_io_File file(env,path);

Expand All @@ -53,7 +53,7 @@ jobjectArray makePathElements(JNIEnv* env,const char *pathChs) {
return elements;
}

void mergeDexElement(JNIEnv* env,jclass __unused, jobject targetClassLoader,const char* pathChs) {
DPT_ENCRYPT void mergeDexElement(JNIEnv* env,jclass __unused, jobject targetClassLoader,const char* pathChs) {
jobjectArray extraDexElements = makePathElements(env,pathChs);

dalvik_system_BaseDexClassLoader targetBaseDexClassLoader(env,targetClassLoader);
Expand Down Expand Up @@ -86,7 +86,7 @@ void mergeDexElement(JNIEnv* env,jclass __unused, jobject targetClassLoader,cons
DLOGD("mergeDexElement success");
}

void mergeDexElements(JNIEnv* env,jclass klass, jobject targetClassLoader) {
DPT_ENCRYPT void mergeDexElements(JNIEnv* env,jclass klass, jobject targetClassLoader) {
char compressedDexesPathChs[256] = {0};
getCompressedDexesPath(env,compressedDexesPathChs, ARRAY_LENGTH(compressedDexesPathChs));

Expand All @@ -98,7 +98,7 @@ void mergeDexElements(JNIEnv* env,jclass klass, jobject targetClassLoader) {
DLOGD("mergeDexElements success");
}

void removeDexElements(JNIEnv* env,jclass __unused,jobject classLoader,jstring elementName){
DPT_ENCRYPT void removeDexElements(JNIEnv* env,jclass __unused,jobject classLoader,jstring elementName){
dalvik_system_BaseDexClassLoader oldBaseDexClassLoader(env,classLoader);

jobject dexPathListObj = oldBaseDexClassLoader.getPathList();
Expand Down Expand Up @@ -167,7 +167,7 @@ void removeDexElements(JNIEnv* env,jclass __unused,jobject classLoader,jstring e
DLOGD("removeDexElements success");
}

jstring readAppComponentFactory(JNIEnv *env, jclass __unused) {
DPT_ENCRYPT jstring readAppComponentFactory(JNIEnv *env, jclass __unused) {

if(appComponentFactoryChs == nullptr) {
void *apk_addr = nullptr;
Expand Down Expand Up @@ -195,7 +195,7 @@ jstring readAppComponentFactory(JNIEnv *env, jclass __unused) {
return env->NewStringUTF((appComponentFactoryChs));
}

jstring readApplicationName(JNIEnv *env, jclass __unused) {
DPT_ENCRYPT jstring readApplicationName(JNIEnv *env, jclass __unused) {

if(applicationNameChs == nullptr) {
void *apk_addr = nullptr;
Expand All @@ -221,7 +221,7 @@ jstring readApplicationName(JNIEnv *env, jclass __unused) {
return env->NewStringUTF((applicationNameChs));
}

void createAntiRiskProcess() {
DPT_ENCRYPT void createAntiRiskProcess() {
pid_t child = fork();
if(child < 0) {
DLOGW("%s fork fail!", __FUNCTION__);
Expand Down Expand Up @@ -287,7 +287,7 @@ jclass getRealApplicationClass(JNIEnv *env, const char *applicationClassName) {
return g_realApplicationClass;
}

jobject getApplicationInstance(JNIEnv *env, jstring applicationClassName) {
DPT_ENCRYPT jobject getApplicationInstance(JNIEnv *env, jstring applicationClassName) {
if (g_realApplicationInstance == nullptr) {
const char *applicationClassNameChs = env->GetStringUTFChars(applicationClassName, nullptr);

Expand Down Expand Up @@ -315,7 +315,7 @@ jobject getApplicationInstance(JNIEnv *env, jstring applicationClassName) {
return g_realApplicationInstance;
}

void callRealApplicationOnCreate(JNIEnv *env, jclass, jstring realApplicationClassName) {
DPT_ENCRYPT void callRealApplicationOnCreate(JNIEnv *env, jclass, jstring realApplicationClassName) {

jobject appInstance = getApplicationInstance(env,realApplicationClassName);
android_app_Application application(env,appInstance);
Expand All @@ -325,7 +325,7 @@ void callRealApplicationOnCreate(JNIEnv *env, jclass, jstring realApplicationCla

}

void callRealApplicationAttach(JNIEnv *env, jclass, jobject context,
DPT_ENCRYPT void callRealApplicationAttach(JNIEnv *env, jclass, jobject context,
jstring realApplicationClassName) {

jobject appInstance = getApplicationInstance(env,realApplicationClassName);
Expand All @@ -337,7 +337,7 @@ void callRealApplicationAttach(JNIEnv *env, jclass, jobject context,

}

jobject replaceApplication(JNIEnv *env, jclass klass, jstring realApplicationClassName){
DPT_ENCRYPT jobject replaceApplication(JNIEnv *env, jclass klass, jstring realApplicationClassName){

jobject appInstance = getApplicationInstance(env, realApplicationClassName);
if (appInstance == nullptr) {
Expand All @@ -350,13 +350,13 @@ jobject replaceApplication(JNIEnv *env, jclass klass, jstring realApplicationCla
return appInstance;
}

void replaceApplicationOnActivityThread(JNIEnv *env,jclass __unused, jobject realApplication){
DPT_ENCRYPT void replaceApplicationOnActivityThread(JNIEnv *env,jclass __unused, jobject realApplication){
android_app_ActivityThread activityThread(env);
activityThread.setInitialApplication(realApplication);
DLOGD("replaceApplicationOnActivityThread success");
}

void replaceApplicationOnLoadedApk(JNIEnv *env, jclass __unused,jobject realApplication) {
DPT_ENCRYPT void replaceApplicationOnLoadedApk(JNIEnv *env, jclass __unused,jobject realApplication) {
android_app_ActivityThread activityThread(env);

jobject mBoundApplicationObj = activityThread.getBoundApplication();
Expand Down Expand Up @@ -406,7 +406,7 @@ void replaceApplicationOnLoadedApk(JNIEnv *env, jclass __unused,jobject realAppl
}


static bool registerNativeMethods(JNIEnv *env) {
DPT_ENCRYPT static bool registerNativeMethods(JNIEnv *env) {
jclass JniBridgeClass = env->FindClass("com/luoyesiqiu/shell/JniBridge");
if (env->RegisterNatives(JniBridgeClass, gMethods, sizeof(gMethods) / sizeof(gMethods[0])) ==
0) {
Expand All @@ -416,7 +416,7 @@ static bool registerNativeMethods(JNIEnv *env) {
}


void init_app(JNIEnv *env, jclass __unused) {
DPT_ENCRYPT void init_app(JNIEnv *env, jclass __unused) {
DLOGD("init_app!");
clock_t start = clock();

Expand Down Expand Up @@ -473,7 +473,7 @@ DPT_ENCRYPT void readCodeItem(uint8_t *data,size_t data_len) {
}
}

JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *__unused) {
DPT_ENCRYPT JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *__unused) {

JNIEnv *env = nullptr;
if (vm->GetEnv((void **) &env, JNI_VERSION_1_6) != JNI_OK) {
Expand Down
6 changes: 3 additions & 3 deletions shell/src/main/cpp/dpt_risk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void junkCodeDexProtect(JNIEnv *env) {
}


void detectFrida() {
DPT_ENCRYPT void detectFrida() {
pthread_t t;
pthread_create(&t, nullptr,detectFridaOnThread,nullptr);
}
Expand All @@ -63,7 +63,7 @@ void doPtrace() {
DLOGD("doPtrace result: %d",ret);
}

void *protectProcessOnThread(void *args) {
DPT_ENCRYPT void *protectProcessOnThread(void *args) {
pid_t child = *((pid_t *)args);

DLOGD("%s waitpid %d", __FUNCTION__ ,child);
Expand All @@ -80,7 +80,7 @@ void *protectProcessOnThread(void *args) {
return nullptr;
}

void protectChildProcess(pid_t pid) {
DPT_ENCRYPT void protectChildProcess(pid_t pid) {
pthread_t t;
pid_t *child = (pid_t *) malloc(sizeof(pid_t));
*child = pid;
Expand Down
12 changes: 6 additions & 6 deletions shell/src/main/cpp/dpt_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ jstring getCompressedDexesPathExport(JNIEnv *env,jclass __unused) {
return env->NewStringUTF(dexesPath);
}

static void writeDexAchieve(const char *dexAchievePath,void *apk_addr,size_t apk_size) {
DPT_ENCRYPT static void writeDexAchieve(const char *dexAchievePath,void *apk_addr,size_t apk_size) {
DLOGD("zipCode open = %s",dexAchievePath);
FILE *fp = fopen(dexAchievePath, "wb");
if(fp != nullptr){
Expand All @@ -197,7 +197,7 @@ static void writeDexAchieve(const char *dexAchievePath,void *apk_addr,size_t apk
}
}

void extractDexesInNeeded(JNIEnv *env,void *apk_addr,size_t apk_size) {
DPT_ENCRYPT void extractDexesInNeeded(JNIEnv *env,void *apk_addr,size_t apk_size) {
char compressedDexesPathChs[256] = {0};
getCompressedDexesPath(env,compressedDexesPathChs, ARRAY_LENGTH(compressedDexesPathChs));

Expand Down Expand Up @@ -227,7 +227,7 @@ void extractDexesInNeeded(JNIEnv *env,void *apk_addr,size_t apk_size) {
}


static void load_zip_by_mmap(const char* zip_file_path,void **zip_addr,size_t *zip_size) {
DPT_ENCRYPT static void load_zip_by_mmap(const char* zip_file_path,void **zip_addr,size_t *zip_size) {
int fd = open(zip_file_path,O_RDONLY);
if(fd <= 0){
DLOGE("load_zip cannot open file!");
Expand Down Expand Up @@ -270,7 +270,7 @@ void unload_apk(void *apk_addr,size_t apk_size) {
}
}

bool read_zip_file_entry(void* zip_addr,off_t zip_size,const char* entry_name,void **entry_addr,uint64_t *entry_size) {
DPT_ENCRYPT bool read_zip_file_entry(void* zip_addr,off_t zip_size,const char* entry_name,void **entry_addr,uint64_t *entry_size) {
DLOGD("read_zip_file_entry prepare read file: %s",entry_name);

void *mem_stream = nullptr;
Expand Down Expand Up @@ -381,7 +381,7 @@ void get_elf_section(Elf_Shdr *target,const char *elf_path,const char *sh_name)
fclose(elf_fp);
}

const char* find_symbol_in_elf_file(const char *elf_file,int keyword_count,...) {
DPT_ENCRYPT const char* find_symbol_in_elf_file(const char *elf_file,int keyword_count,...) {
FILE *elf_fp = fopen(elf_file, "r");
if(elf_fp) {
fseek(elf_fp, 0L, SEEK_END);
Expand Down Expand Up @@ -436,7 +436,7 @@ const char* find_symbol_in_elf_file(const char *elf_file,int keyword_count,...)
return nullptr;
}

int find_in_maps(int count,...) {
DPT_ENCRYPT int find_in_maps(int count,...) {
const int MAX_READ_LINE = 10 * 1024;
char maps_path[128] = {0};
snprintf(maps_path, ARRAY_LENGTH(maps_path), "/proc/%d/maps", getpid());
Expand Down

0 comments on commit 997b238

Please sign in to comment.