-
首先了解 elf 文件结构:
- 可重定位文件: 包含适合于与其他目标文件链接来创建可执行文件或者共享目标文件的代码和数据。
- 可执行文件: 包含适合于执行的一个程序,此文件规定了exec() 如何创建一个程序的进程映像。
- 共享目标文件: 包含可在两种上下文中链接的代码和数据。首先链接编辑器可以将它和其它可重定位文件和共享目标文件一起处理,生成另外一个目标文件。其次,动态链接器(Dynamic Linker)可能将它与某个可执行文件以及其它共享目标一起组合,创建进程映像。
详细细节参考: Linux及安全实践四——ELF文件格式分析 , ELF格式可执行程序的代码嵌入(同目录下的 pdf 文件)
-
知道 Linux 下的汇编与 WIN32 汇编的区别
-
开始动手实现向现有 elf 文件中插入功能,如:让程序首先执行创建一个 output.txt 文件,并写入 hello world
- 先生成一个 elf 程序,并通过 FILE *fp = fopen("test", "rb+") 读取该 elf 文件
- 接着获取 elf 文件的入口地址,程序头,节区头等信息
- 然后写出要添加的附加功能的汇编程序并编译获取机器码,通过 readelf -e elf文件名 查看 elf 文件的程序入口地址等信息,并根据 elf 文件的程序地址等信息修改生成的机器码中相应的地址信息
- 将修改好的机器码添加进elf的text段的最后(为了方便,此处我将数据也一并添加进了text段)
- 修改elf 的入口地址为嵌入的程序首地址,当嵌入程序执行结束再跳转到原 elf 文件的首地址,使程序继续执行原本的 elf 文件程序,再修改 elf 的程序头,节区头
- 通过 fclose(fp) 关闭 elf 文件
-
懂得如何根据文件信息修改对应的机器码
参考:
change-elf's Introduction
change-elf's People
Forkers
tianylijun gyy1225 netyum jianfeizhou truedei zhengxiaowei-github hrbu18044334 magicjva rex-ms szf-2000 kongqbinRecommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.