# 20220512 开始加速学习逆向,以滴水逆向的教程为路线。

下面的内容基于 32 位 pe 程序

# 1,进制

8 进制的 2-3.(32 位)

010 - 011

补码加法:0000 0000 0000 0000 0000 0000 0000 0010 + 1111 1111 1111 1111 1111 1111 1111 1101

结果 17777777777…(8)

# 2,EXE 执行文件如何执行程序

img

什么是程序。什么是数据

程序是数据与可执行代码的组合。

PE 文件结构

# dos 头

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
typedef struct _IMAGE_DOS_HEADER {      // DOS .EXE header
WORD e_magic; // Magic number
WORD e_cblp; // Bytes on last page of file
WORD e_cp; // Pages in file
WORD e_crlc; // Relocations
WORD e_cparhdr; // Size of header in paragraphs
WORD e_minalloc; // Minimum extra paragraphs needed
WORD e_maxalloc; // Maximum extra paragraphs needed
WORD e_ss; // Initial (relative) SS value
WORD e_sp; // Initial SP value
WORD e_csum; // Checksum
WORD e_ip; // Initial IP value
WORD e_cs; // Initial (relative) CS value
WORD e_lfarlc; // File address of relocation table
WORD e_ovno; // Overlay number
WORD e_res[4]; // Reserved words
WORD e_oemid; // OEM identifier (for e_oeminfo)
WORD e_oeminfo; // OEM information; e_oemid specific
WORD e_res2[10]; // Reserved words
DWORD e_lfanew; // File address of new exe header 0x3c
} IMAGE_DOS_HEADER, *PIMAGE_DOS_HEADER;

DOS 头目前已经没有什么作用了,保留的目的是为了向下兼容 16 位程序

image-20220512103830333

0x3c 地址的数据是 0x000000d8,(windows 中,高地址在前。)这里指向的是数据存储的起点,但不是程序入口。这里指向的是 PE

1
2
3
4
5
struct _iMAGE_NT_HEADERS{
0x00 DWORD Signature
0x04 _iMAGE_FILE_HEADER FileHeader
0x18 _iMAGE_OPTIONAL_HEADER OptionalHeader
}

# 程序入口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
struct _IMAGE_OPTIONAL_HEADER {
WORD Magic;
BYTE MajorLinkerVersion;
BYTE MinorLinkerVersion;
DWORD SizeOfCode;
DWORD SizeOfInitializedData;
DWORD SizeOfUninitializedData;
DWORD AddressOfEntryPoint; //入口点
DWORD BaseOfCode; //代码基址
DWORD BaseOfData; //数据基址
DWORD ImageBase; //镜像基址
DWORD SectionAlignment;
DWORD FileAlignment;
WORD MajorOperatingSystemVersion;
WORD MinorOperatingSystemVersion;
WORD MajorImageVersion;
WORD MinorImageVersion;
WORD MajorSubsystemVersion;
WORD MinorSubsystemVersion;
DWORD Win32VersionValue;
DWORD SizeOfImage;
DWORD SizeOfHeaders;
DWORD CheckSum;
WORD Subsystem;
WORD DllCharacteristics;
DWORD SizeOfStackReserve;
DWORD SizeOfStackCommit;
DWORD SizeOfHeapReserve;
DWORD SizeOfHeapCommit;
DWORD LoaderFlags;
DWORD NumberOfRvaAndSizes;
IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
} IMAGE_OPTIONAL_HEADER32, *PIMAGE_OPTIONAL_HEADER32;

iMAGE_OPTIONAL_HEADER OptionalHeader 结构体紧跟在 iMAGE_NT_HEADERS 的后面。

AddressOfEntryPoint 在结构体中的偏移是 0x10,

上面的截图为例,入口点在 0x100h,数据是 0x00001307

代码基址是 0x00001000, 数据段基址 0x00006000。这里我们通过 ida 分析发现,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
.text:00401000 ;
.text:00401000 ; +-------------------------------------------------------------------------+
.text:00401000 ; | This file was generated by The Interactive Disassembler (IDA) |
.text:00401000 ; | Copyright (c) 2020 Hex-Rays, <support@hex-rays.com> |
.text:00401000 ; | License info: 50-5947-5F4E-42 |
.text:00401000 ; | P.Y.G Team, Personal license |
.text:00401000 ; +-------------------------------------------------------------------------+
.text:00401000 ;
.text:00401000 ; Input SHA256 : F6BCC742755C60202D85EDD7307567103C8804F2249D16591040A3390E571CBE
.text:00401000 ; Input MD5 : 3D47DDF04CC6A8120C400A5F304E3ED6
.text:00401000 ; Input CRC32 : 4F14BDF8
.text:00401000
.text:00401000 ; File Name : C:\Users\32644\Desktop\reverse\csaw2013reversing2\0453d21297a743e199d8a7de75179e52 (1).exe
.text:00401000 ; Format : Portable executable for 80386 (PE)
.text:00401000 ; Imagebase : 400000
.text:00401000 ; Timestamp : 54123A17 (Fri Sep 12 00:11:03 2014)
.text:00401000 ; Section 1. (virtual address 00001000)
.text:00401000 ; Virtual size : 000044D2 ( 17618.)
.text:00401000 ; Section size in file : 00004600 ( 17920.)
.text:00401000 ; Offset to raw data for section: 00000400
.text:00401000 ; Flags 60000020: Text Executable Readable
.text:00401000 ; Alignment : default
.text:00401000 ; PDB File Name : C:\Users\exploitation\documents\visual studio 2010\Projects\csaw2013reversing2\Release\csaw2013reversing2.pdb
.text:00401000 ; OS type : MS Windows
.text:00401000 ; Application type: Executable 32bit
.text:00401000
.text:00401000 .686p
.text:00401000 .mmx
.text:00401000 .model flat
...
.text:00405600 _text ends
.text:00405600
.idata:00406000 ; Section 2. (virtual address 00006000)

这个两个基址,其实是相对地址,也就是关于镜像基址(BaseOfImage)的偏移

Edited on

Give me a cup of [coffee]~( ̄▽ ̄)~*

dreamcat WeChat Pay

WeChat Pay

dreamcat Alipay

Alipay

dreamcat PayPal

PayPal