简单SO加密及ELF头文件修复

本文介绍了如何修复ELF头文件错误,通过分析ELF结构,特别是e_shoff、e_shentsize、e_shnum和e_shstrndx字段,以及使用010 Editor和IDA工具进行验证和修复。同时,讨论了Android环境下SO文件的加密方法。
摘要由CSDN通过智能技术生成

Android(一):简单SO加密及ELF头文件修复

 为了对抗IDA等逆向工具对SO进行逆向,一个简单的方法就是对ELF头文件信息进行修改,使IDA等工具解析出错,从而达到对抗的目的。本文所用到的资源文件都会提供下载,有什么写得不好的地方,请指正,谢谢。

一,ELF文件结构

这里写图片描述

由上图可知ELF有两种视图,当我们应用在执行的时候采用的是执行视图,看图可知,节区头部表是可选的,可选的意思就是存在与不存在对程序都是没有影响的,因此,我们可以改动节区头的相关信息,让IDA等工具解析出错,从而达到对抗的目的。

二,ELF头文件结构

 #define EI_NIDENT 16
     typedef struct{
         
当然可以!以下是一个简单ELF 文件解析器的 C 语言代码实现: ```c #include <stdio.h> #include <stdlib.h> #include <elf.h> int main(int argc, char **argv) { if (argc != 2) { fprintf(stderr, "Usage: %s <ELF file>\n", argv[0]); exit(EXIT_FAILURE); } FILE *file = fopen(argv[1], "rb"); if (file == NULL) { perror("Failed to open file"); exit(EXIT_FAILURE); } Elf64_Ehdr header; if (fread(&header, sizeof(header), 1, file) != 1) { perror("Failed to read ELF header"); exit(EXIT_FAILURE); } printf("ELF header:\n"); printf(" Magic number: %02x %02x %02x %02x\n", header.e_ident[EI_MAG0], header.e_ident[EI_MAG1], header.e_ident[EI_MAG2], header.e_ident[EI_MAG3]); printf(" Class: %u-bit\n", header.e_ident[EI_CLASS] == ELFCLASS32 ? 32 : 64); printf(" Data encoding: %s-endian\n", header.e_ident[EI_DATA] == ELFDATA2LSB ? "little" : "big"); printf(" Version: %u\n", header.e_ident[EI_VERSION]); printf(" OS ABI: %u\n", header.e_ident[EI_OSABI]); printf(" ABI version: %u\n", header.e_ident[EI_ABIVERSION]); printf(" Type: %u\n", header.e_type); printf(" Machine: %u\n", header.e_machine); printf(" Version: %u\n", header.e_version); printf(" Entry point address: 0x%lx\n", header.e_entry); printf(" Program header offset: %lu\n", header.e_phoff); printf(" Section header offset: %lu\n", header.e_shoff); printf(" Flags: %u\n", header.e_flags); printf(" ELF header size: %u\n", header.e_ehsize); printf(" Program header entry size: %u\n", header.e_phentsize); printf(" Number of program header entries: %u\n", header.e_phnum); printf(" Section header entry size: %u\n", header.e_shentsize); printf(" Number of section header entries: %u\n", header.e_shnum); printf(" Section name string table index: %u\n", header.e_shstrndx); if (fseek(file, header.e_shoff, SEEK_SET) != 0) { perror("Failed to seek to section header table"); exit(EXIT_FAILURE); } Elf64_Shdr section_header; for (int i = 0; i < header.e_shnum; i++) { if (fread(&section_header, sizeof(section_header), 1, file) != 1) { perror("Failed to read section header"); exit(EXIT_FAILURE); } printf("Section %d:\n", i); printf(" Name: %u\n", section_header.sh_name); printf(" Type: %lu\n", section_header.sh_type); printf(" Flags: %lu\n", section_header.sh_flags); printf(" Address: 0x%lx\n", section_header.sh_addr); printf(" Offset: %lu\n", section_header.sh_offset); printf(" Size: %lu\n", section_header.sh_size); printf(" Link: %u\n", section_header.sh_link); printf(" Info: %u\n", section_header.sh_info); printf(" Address alignment: %lu\n", section_header.sh_addralign); printf(" Entry size: %lu\n", section_header.sh_entsize); } fclose(file); return EXIT_SUCCESS; } ``` 这个解析器使用标准 C 库函数和 ELF 头文件,打开指定的 ELF 文件,读取和解析 ELF 文件头部信息和节头表信息,并将它们打印到标准输出中。注意这个解析器仅适用于 64 位 ELF 文件,并且没有处理节的内容。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值