Analysis of notepad process loading
来源:互联网 发布:app生成器软件 编辑:程序博客网 时间:2024/06/06 01:08
因为上一篇博客PE文件格式学习笔记 ,我萌生了分析Windows7系统自带记事本程序的process loading过程的念头。正好,自己也亲自计算一下其中的细节,毕竟这都是逆向的基本功呀。当然文中可能有些许错误,恳请大家指正 :)
①Headers
the DOS Header is parsed.the PE Header is parsed. (its offset is DOS Header's e_lfanew)the Optional Header is parsed. (it follows the PE header)
由起始两bytes判断DOS Header ==> 由DOS Header的最后4 bytes确定PE Header位置 ==> 紧挨在PE Header后面的是Optional Header,但其大小不确定,需要由PE Header中的SizeofOptionalHeader告知
②Section table
Section table里的条目个数不是确定的,由PE Header里的第6、7个字节(从第0个字节数起)告知。由上图可知为 00 04,即有四个section。
Section table紧接在Optional Header后面,每一个条目占用40 bytes.
可将四个条目分析出来:
③Mapping
要将PE文件从磁盘映射到内存里,首先得知道PE file section和内存之间的映射关系。这里可能会疑惑,为啥要映射呢?因为PE文件的对齐规则和内存的对齐规则是不一样的,因此不能说直接把file拷贝进内存就可以了,而必须通过一定的地址换算,这个换算过程就是映射。Optional Header里的FileFileAlignment、SectionAlignment参数分别对应了PE file、内存的对齐规则。
FileFileAlignment represents where sections should start on file.SectionAlignmenet represents where sections should start in memory.
映射示意图如下,这里只画了.text section的映射部分:
由上图的映射可知一个关系等式:
某section的某处相对于该section起始处的offset == 加载到内存后该section的该处相对于该section起始处的offset
对了,这里顺便也po一张好图:
凭借这个等式我们可以计算一些东西。
比如说,想要知道PE file的ImportTable的具体内容,步骤如下:
由Optional Header可知ImportTable(RVA):A0 48 和ImportTable占用的大小SizeofExportTable:01 2C;
由上述运算法则计算ImportTable相对于PE file起始处的offset:
首先把RVA地址A0 48加上imagebase值01 00 00 00,得01 00 A0 48,由此可判断ImportTable in memory位于image的.text setion区域由等式【01 00 A0 48 - 01 00 10 00 == ImportTable相对于PE file起始处的offset - 00 00 04 00】可求出: ImportTable相对于PE file起始处的offset为94 48
查看PE file的94 48处:
黄色部分为对应的Import条目的Name的RVA。通过类似于上述的计算可得,RVA 00 00 A2 24处对应的相对于PE file起始处的offset为【01 00 A2 24 - 01 00 10 00 + 00 00 04 00 = 96 24】,对应上图中的ADVAPI32.dll;RVA 00 00 A2 14处对应的相对于PE file起始处的offset为96 14,对应上图中的KERNEL32.dll;……
④Imports
结合③中的计算:DataDirectories are parsed.ImportTable are parsed. each descriptor specifies a DLL name this DLL is loaded in memory INT and IAT are parsed simultaneously for each API in INT: its address is written in the IAT entry
具体的IAT输入过程如下:
⑤Excecution
Code is called at the EntryPoint.the calls of the code go via the IAT to the APIs.
- Analysis of notepad process loading
- the design principles and code analysis of hibernate lazy loading
- Linux Process analysis
- Multi-process Resource Loading
- show dynamic loading process
- Business analysis and SOA part 3 of 6: Process-centric business services [by Thomas Erl]
- Analysis of Process Multi-Thread Manangement Based on a simpilified Linux Kernel--myKernel
- tips of notepad++
- analysis of wait_event_interruptible()
- analysis of wake_up_interruptible()
- analysis communication of ucenter
- Infinispan Analysis of Distribution
- Analysis of DefaultConsistentHash.java
- The analysis of suse_register
- Analysis of pNFS
- Analysis of 【Dropout】
- Summary of Analysis of Algorithm
- Requirements Analysis Process:Requirements Elicitation, Analysis And Specification
- GLSurfaceView,SurfaceView中出现暂停、播放等UI遮挡问题.
- 分词工具介绍与简单实例
- map/multimap容器
- Hi3518EV200平台直接操作GPIO输入或输出高低电平
- turret
- Analysis of notepad process loading
- Android四大组件之服务--Service
- java实现哈夫曼编码
- Qt中LineEdit的文本数字等的读取
- 块状链表---by konnyakuxzy
- ONVIF协议网络摄像机(IPC)客户端程序开发(12):读取音视频流
- 5-18
- LintCode-比较字符串
- Maven创建第一个java项目(官方教程)