Skip to content

Commit

Permalink
优化函数名
Browse files Browse the repository at this point in the history
  • Loading branch information
luoyesiqiu committed Feb 26, 2023
1 parent 5c27eb2 commit 38b261c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
33 changes: 16 additions & 17 deletions shell/src/main/cpp/dpt_hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ void callOriginLoadMethod(void *thiz, void *self, const void *dex_file, const vo
case 23:
case 24:
case 25:
g_originLoadMethod25(thiz, self, dex_file, it, klass, dst);
g_originLoadMethodM(thiz, self, dex_file, it, klass, dst);
break;
case 26:
case 27:
case 28:
g_originLoadMethod28(thiz, dex_file, it, klass, dst);
g_originLoadMethodO(thiz, dex_file, it, klass, dst);
break;
case 29:
case 30:
case 31:
case 32:
case 33:
g_originLoadMethod29(thiz, dex_file, method, klass, dst);
g_originLoadMethodQ(thiz, dex_file, method, klass, dst);
break;
}
}
Expand Down Expand Up @@ -166,9 +166,9 @@ ClassDataItemReader* getClassDataItemReader(const void* it,const void* method){
void LoadMethod(void *thiz, void *self, const void *dex_file, const void *it, const void *method,
void *klass, void *dst) {

if (g_originLoadMethod25 != nullptr
|| g_originLoadMethod28 != nullptr
|| g_originLoadMethod29 != nullptr) {
if (g_originLoadMethodM != nullptr
|| g_originLoadMethodO != nullptr
|| g_originLoadMethodQ != nullptr) {
uint32_t location_offset = getDexFileLocationOffset();
uint32_t begin_offset = getDataItemCodeItemOffset();
callOriginLoadMethod(thiz, self, dex_file, it, method, klass, dst);
Expand All @@ -189,7 +189,9 @@ void LoadMethod(void *thiz, void *self, const void *dex_file, const void *it, co
return;
}

uint16_t firstDvmCode = *((uint16_t*)(begin + classDataItemReader->GetMethodCodeItemOffset() + 16));
uintptr_t insnsPtr = (uintptr_t)(begin + classDataItemReader->GetMethodCodeItemOffset() + 16);

uint16_t firstDvmCode = *((uint16_t*)insnsPtr);
if(firstDvmCode != 0x0012 && firstDvmCode != 0x0016 && firstDvmCode != 0x000e){
NLOG("[*] this method has code no need to patch");
return;
Expand Down Expand Up @@ -227,9 +229,7 @@ void LoadMethod(void *thiz, void *self, const void *dex_file, const void *it, co

if (codeItemIt != codeItemMap->end()) {
CodeItem* codeItem = codeItemIt->second;
uint8_t *realCodeItemPtr = (uint8_t*)(begin +
classDataItemReader->GetMethodCodeItemOffset() +
16);
uint8_t *realCodeItemPtr = (uint8_t *)(insnsPtr);

#ifdef NOICE_LOG
char threadName[128] = {0};
Expand All @@ -243,7 +243,6 @@ void LoadMethod(void *thiz, void *self, const void *dex_file, const void *it, co
}
else{
DLOGE("[*] LoadMethod cannot find methodId: %d in dex: %d(%s)",methodIdx,dexIndex,location->c_str());

}
}
else{
Expand All @@ -255,16 +254,16 @@ void LoadMethod(void *thiz, void *self, const void *dex_file, const void *it, co
}
}

void LoadMethod_MN(void *thiz, void *self, const void *dex_file, const void *it, void *klass,
void LoadMethodM(void *thiz, void *self, const void *dex_file, const void *it, void *klass,
void *dst) {
LoadMethod(thiz, self, dex_file, it, nullptr, klass, dst);
}

void LoadMethod_OP(void *thiz, const void *dex_file, const void *it, void *klass, void *dst) {
void LoadMethodO(void *thiz, const void *dex_file, const void *it, void *klass, void *dst) {
LoadMethod(thiz, nullptr, dex_file, it, nullptr, klass, dst);
}

void LoadMethod_QR(void *thiz, const void *dex_file, const void *method, void *klass, void *dst) {
void LoadMethodQ(void *thiz, const void *dex_file, const void *method, void *klass, void *dst) {
LoadMethod(thiz, nullptr, dex_file, nullptr, method, klass, dst);
};

Expand All @@ -274,19 +273,19 @@ void hook_ClassLinker_LoadMethod() {
case 23:
case 24:
case 25:
DobbyHook(loadMethodAddress, (void *) LoadMethod_MN,(void**)&g_originLoadMethod25);
DobbyHook(loadMethodAddress, (void *) LoadMethodM,(void**)&g_originLoadMethodM);
break;
case 26:
case 27:
case 28:
DobbyHook(loadMethodAddress, (void *) LoadMethod_OP,(void**)&g_originLoadMethod28);
DobbyHook(loadMethodAddress, (void *) LoadMethodO,(void**)&g_originLoadMethodO);
break;
case 29:
case 30:
case 31:
case 32:
case 33:
DobbyHook(loadMethodAddress, (void *) LoadMethod_QR,(void**)&g_originLoadMethod29);
DobbyHook(loadMethodAddress, (void *) LoadMethodQ,(void**)&g_originLoadMethodQ);
break;

}
Expand Down
8 changes: 4 additions & 4 deletions shell/src/main/cpp/dpt_hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
void dpt_hook();

//android M,N
static void (*g_originLoadMethod25)(void* thiz, void* self, const void* dex_file, const void* it, void* klass, void* dst) = nullptr;
static void (*g_originLoadMethodM)(void* thiz, void* self, const void* dex_file, const void* it, void* klass, void* dst) = nullptr;
//android O,P
static void (*g_originLoadMethod28)(void* thiz, const void* dex_file, const void* it, void* klass,void *dst) = nullptr;
//android Q,R
static void (*g_originLoadMethod29)(void* thiz, const void* dex_file, const void* method, void* klass,void *dst) = nullptr;
static void (*g_originLoadMethodO)(void* thiz, const void* dex_file, const void* it, void* klass,void *dst) = nullptr;
//android Q,R,S...
static void (*g_originLoadMethodQ)(void* thiz, const void* dex_file, const void* method, void* klass,void *dst) = nullptr;

void hook_ClassLinker_LoadMethod();
void callOriginLoadMethod(void *thiz, void *self, const void *dex_file, const void *it, const void *method,
Expand Down

0 comments on commit 38b261c

Please sign in to comment.