Skip to content

Commit

Permalink
Do not encrypt the .rodata section
Browse files Browse the repository at this point in the history
  • Loading branch information
luoyesiqiu committed Aug 8, 2024
1 parent 3229a1d commit a98fee5
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dpt/src/main/java/com/luoye/dpt/builder/Apk.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private void encryptSoFiles(String apkDir){
readElf.close();
for (ReadElf.SectionHeader sectionHeader : sectionHeaders) {

if(".bitcode".equals(sectionHeader.getName()) || ".rodata".equals(sectionHeader.getName())) {
if(".bitcode".equals(sectionHeader.getName())) {

LogUtils.info("start encrypt %s section: %s,offset: %s,size: %s",
soFile.getAbsolutePath(),
Expand Down
4 changes: 2 additions & 2 deletions shell/src/main/cpp/bhook/bh_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

int bh_util_set_addr_protect(void *addr, int prot) {
uintptr_t start_addr = PAGE_START((uintptr_t)addr);
uintptr_t end_addr = PAGE_START((uintptr_t)addr + sizeof(uintptr_t) - 1) + PAGE_SIZE;
uintptr_t end_addr = PAGE_START((uintptr_t)addr + sizeof(uintptr_t) - 1) + getpagesize();
size_t size = end_addr - start_addr;

if (0 != mprotect((void *)start_addr, size, prot)) return -1;
Expand All @@ -56,7 +56,7 @@ int bh_util_set_addr_protect(void *addr, int prot) {

int bh_util_set_protect(void *start, void *end, int prot) {
uintptr_t start_addr = PAGE_START((uintptr_t)start);
uintptr_t end_addr = PAGE_START((uintptr_t)end - 1) + PAGE_SIZE;
uintptr_t end_addr = PAGE_START((uintptr_t)end - 1) + getpagesize();
size_t size = end_addr - start_addr;

if (0 != mprotect((void *)start_addr, size, prot)) return -1;
Expand Down
3 changes: 1 addition & 2 deletions shell/src/main/cpp/dpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ DPT_ENCRYPT void createAntiRiskProcess() {
}
}

void decrypt_section(const char* section_name,int temp_prot,int target_prot) {
void decrypt_section(const char* section_name, int temp_prot, int target_prot) {
Dl_info info;
dladdr((const void *)decrypt_section,&info);
Elf_Shdr shdr;
Expand Down Expand Up @@ -273,7 +273,6 @@ void decrypt_section(const char* section_name,int temp_prot,int target_prot) {
}

void decrypt_bitcode() {
decrypt_section((char *)DATA_SECTION_RO_DATA,PROT_READ | PROT_WRITE,PROT_READ);
decrypt_section((char *)DATA_SECTION_BITCODE,PROT_READ | PROT_WRITE | PROT_EXEC,PROT_READ | PROT_EXEC);
}

Expand Down
5 changes: 1 addition & 4 deletions shell/src/main/cpp/dpt_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ DPT_DATA_SECTION uint8_t DATA_R_FLAG[] = "r";

int dpt_mprotect(void *start,void *end,int prot) {
uintptr_t start_addr = PAGE_START((uintptr_t)start);
uintptr_t end_addr = PAGE_START((uintptr_t)end - 1) + PAGE_SIZE;
uintptr_t end_addr = PAGE_START((uintptr_t)end - 1) + getpagesize();
size_t size = end_addr - start_addr;

DLOGD("%s begin: %p, size: %zu",__FUNCTION__,(void *)start_addr,size);


if (0 != mprotect((void *)start_addr, size, prot)) return -1;
return 0;
}
Expand Down

0 comments on commit a98fee5

Please sign in to comment.