Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6236 | nosferatus | 1 | filename equ '%EXENAME%' |
2 | |||
3 | virtual at 0 |
||
4 | file filename:3Ch,4 |
||
5 | load pehea dword from 0 |
||
6 | file filename:pehea,0F8h+28h*3 |
||
7 | load NumberOfSections word from 4+6 |
||
8 | load SizeOfOptionalHeader word from 4+14h |
||
9 | if NumberOfSections<>3 |
||
10 | error Expected three sections, .text, .bss and .reloc |
||
11 | end if |
||
12 | if SizeOfOptionalHeader<>0E0h |
||
13 | error Nonstandard PE header |
||
14 | end if |
||
15 | load RelocsRVA dword from 4+0A0h |
||
16 | load RelocsSize dword from 4+0A4h |
||
17 | load ImageBase dword from 4+34h |
||
18 | load TextRVA dword from 4+0F8h+0Ch |
||
19 | load TextSize dword from 4+0F8h+8 |
||
20 | load TextOffs dword from 4+0F8h+14h |
||
21 | load BSSSize dword from 4+0F8h+28h+10h |
||
22 | load RelocRVA dword from 4+0F8h+28h*2+0Ch |
||
23 | load RelocOffs dword from 4+0F8h+28h*2+14h |
||
24 | if BSSSize |
||
25 | error Second section expected to be .bss |
||
26 | end if |
||
27 | if RelocRVA<>RelocsRVA |
||
28 | error Third section expected to be .reloc |
||
29 | end if |
||
30 | ;file 'test.exe':pehea+0F8h,28h |
||
31 | ;load physofs dword from 4+14h |
||
32 | ;load mem dword from 4+8 |
||
33 | ;file 'test.exe':physofs+16,4 |
||
34 | ;load sz dword from $-4 |
||
35 | end virtual |
||
36 | |||
37 | file filename:TextOffs,TextSize |
||
38 | |||
39 | while RelocsSize>8 |
||
40 | virtual at 0 |
||
41 | file filename:RelocOffs,8 |
||
42 | load CurRelocPage dword from 0 |
||
43 | load CurRelocChunkSize dword from 4 |
||
44 | end virtual |
||
45 | RelocsSize=RelocsSize-CurRelocChunkSize |
||
46 | CurRelocChunkSize = CurRelocChunkSize-8 |
||
47 | RelocOffs=RelocOffs+8 |
||
48 | while CurRelocChunkSize |
||
49 | virtual at 0 |
||
50 | file filename:RelocOffs,2 |
||
51 | RelocOffs=RelocOffs+2 |
||
52 | CurRelocChunkSize=CurRelocChunkSize-2 |
||
53 | load s word from 0 |
||
54 | end virtual |
||
55 | CurRelocType = s shr 12 |
||
56 | RelocItem = CurRelocPage + (s and 0xFFF) |
||
57 | if CurRelocType=0 |
||
58 | else if CurRelocType=3 |
||
59 | load z dword from RelocItem-TextRVA |
||
60 | store dword z-(TextRVA+ImageBase) at RelocItem-TextRVA |
||
61 | else |
||
62 | error Unexpected relocation type |
||
63 | end if |
||
64 | end while |
||
65 | end while |
||
66 | |||
67 | store dword TextSize at 10h |
||
68 | store dword RelocRVA-TextRVA at 14h>>> |