Rev 6702 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6702 | Rev 6703 | ||
---|---|---|---|
1 | ; If you know macro language of FASM, there is almost nothing to comment here. |
1 | ; If you know macro language of FASM, there is almost nothing to comment here. |
2 | ; If you don't know macro language of FASM, comments would not help you. |
2 | ; If you don't know macro language of FASM, comments would not help you. |
3 | 3 | ||
4 | filename equ '%EXENAME%' |
4 | filename equ '%EXENAME%' |
5 | 5 | ||
6 | SPE_DIR_ORDER fix IMPORT EXPORT BASERELOC EXCEPTION TLS BOUND_IMPORT RESOURCE |
6 | SPE_DIR_ORDER fix IMPORT EXPORT BASERELOC EXCEPTION TLS BOUND_IMPORT RESOURCE |
7 | count = 0 |
7 | count = 0 |
8 | irps dir,SPE_DIR_ORDER |
8 | irps dir,SPE_DIR_ORDER |
9 | { |
9 | { |
10 | SPE_DIRECTORY_#dir = count |
10 | SPE_DIRECTORY_#dir = count |
11 | count = count + 1 |
11 | count = count + 1 |
12 | } |
12 | } |
13 | 13 | ||
14 | IMAGE_DIRECTORY_ENTRY_EXPORT = 0 |
14 | IMAGE_DIRECTORY_ENTRY_EXPORT = 0 |
15 | IMAGE_DIRECTORY_ENTRY_IMPORT = 1 |
15 | IMAGE_DIRECTORY_ENTRY_IMPORT = 1 |
16 | IMAGE_DIRECTORY_ENTRY_RESOURCE = 2 |
16 | IMAGE_DIRECTORY_ENTRY_RESOURCE = 2 |
17 | IMAGE_DIRECTORY_ENTRY_EXCEPTION = 3 |
17 | IMAGE_DIRECTORY_ENTRY_EXCEPTION = 3 |
18 | IMAGE_DIRECTORY_ENTRY_BASERELOC = 5 |
18 | IMAGE_DIRECTORY_ENTRY_BASERELOC = 5 |
19 | IMAGE_DIRECTORY_ENTRY_TLS = 9 |
19 | IMAGE_DIRECTORY_ENTRY_TLS = 9 |
20 | IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT = 11 |
20 | IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT = 11 |
21 | 21 | ||
22 | virtual at 0 |
22 | virtual at 0 |
23 | file filename:3Ch,4 |
23 | file filename:3Ch,4 |
24 | load pehea dword from 0 |
24 | load pehea dword from 0 |
25 | end virtual |
25 | end virtual |
26 | 26 | ||
27 | virtual at 0 |
27 | virtual at 0 |
28 | file filename:pehea,0F8h |
28 | file filename:pehea,0F8h |
29 | load NumberOfSections word from 6 |
29 | load NumberOfSections word from 6 |
30 | load TimeDateStamp dword from 8 |
30 | load TimeDateStamp dword from 8 |
31 | load SizeOfOptionalHeader word from 14h |
31 | load SizeOfOptionalHeader word from 14h |
32 | if SizeOfOptionalHeader<>0E0h |
32 | if SizeOfOptionalHeader<>0E0h |
33 | error Nonstandard PE header |
33 | error Nonstandard PE header |
34 | end if |
34 | end if |
35 | load Characteristics word from 16h |
35 | load Characteristics word from 16h |
36 | load AddressOfEntryPoint dword from 28h |
36 | load AddressOfEntryPoint dword from 28h |
37 | load ImageBase dword from 34h |
37 | load ImageBase dword from 34h |
38 | load SectionAlignment dword from 38h |
38 | load SectionAlignment dword from 38h |
39 | load FileAlignment dword from 3Ch |
39 | load FileAlignment dword from 3Ch |
40 | load MajorOperatingSystemVersion word from 40h |
40 | load MajorOperatingSystemVersion word from 40h |
41 | load MinorOperatingSystemVersion word from 42h |
41 | load MinorOperatingSystemVersion word from 42h |
42 | load MajorSubsystemVersion word from 48h |
42 | load MajorSubsystemVersion word from 48h |
43 | load MinorSubsystemVersion word from 4Ah |
43 | load MinorSubsystemVersion word from 4Ah |
44 | load SizeOfImage dword from 50h |
44 | load SizeOfImage dword from 50h |
45 | load SizeOfHeaders dword from 54h |
45 | load SizeOfHeaders dword from 54h |
46 | load Subsystem word from 5Ch |
46 | load Subsystem word from 5Ch |
47 | load SizeOfStackReserve dword from 60h |
47 | load SizeOfStackReserve dword from 60h |
48 | load SizeOfHeapReserve dword from 68h |
48 | load SizeOfHeapReserve dword from 68h |
49 | load SrcNumberOfRvaAndSizes dword from 74h |
49 | load SrcNumberOfRvaAndSizes dword from 74h |
50 | 50 | ||
51 | DstNumberOfRvaAndSizes = 0 |
51 | DstNumberOfRvaAndSizes = 0 |
52 | irps dir,SPE_DIR_ORDER |
52 | irps dir,SPE_DIR_ORDER |
53 | { |
53 | { |
54 | if IMAGE_DIRECTORY_ENTRY_#dir < SrcNumberOfRvaAndSizes |
54 | if IMAGE_DIRECTORY_ENTRY_#dir < SrcNumberOfRvaAndSizes |
55 | load DirRVA_#dir dword from 78h + 8*IMAGE_DIRECTORY_ENTRY_#dir |
55 | load DirRVA_#dir dword from 78h + 8*IMAGE_DIRECTORY_ENTRY_#dir |
56 | load DirSize_#dir dword from 7Ch + 8*IMAGE_DIRECTORY_ENTRY_#dir |
56 | load DirSize_#dir dword from 7Ch + 8*IMAGE_DIRECTORY_ENTRY_#dir |
57 | else |
57 | else |
58 | DirRVA_#dir = 0 |
58 | DirRVA_#dir = 0 |
59 | DirSize_#dir = 0 |
59 | DirSize_#dir = 0 |
60 | end if |
60 | end if |
61 | if DirRVA_#dir > 0 & DirSize_#dir > 0 |
61 | if DirRVA_#dir > 0 & DirSize_#dir > 0 |
62 | DstNumberOfRvaAndSizes = SPE_DIRECTORY_#dir + 1 |
62 | DstNumberOfRvaAndSizes = SPE_DIRECTORY_#dir + 1 |
63 | end if |
63 | end if |
64 | } |
64 | } |
65 | 65 | ||
66 | end virtual |
66 | end virtual |
67 | 67 | ||
68 | SectionAlignmentLog = 0 |
68 | SectionAlignmentLog = 0 |
69 | while SectionAlignment <> 1 shl SectionAlignmentLog |
69 | while SectionAlignment <> 1 shl SectionAlignmentLog |
70 | SectionAlignmentLog = SectionAlignmentLog + 1 |
70 | SectionAlignmentLog = SectionAlignmentLog + 1 |
71 | end while |
71 | end while |
72 | FileAlignmentLog = 0 |
72 | FileAlignmentLog = 0 |
73 | while FileAlignment <> 1 shl FileAlignmentLog |
73 | while FileAlignment <> 1 shl FileAlignmentLog |
74 | FileAlignmentLog = FileAlignmentLog + 1 |
74 | FileAlignmentLog = FileAlignmentLog + 1 |
75 | end while |
75 | end while |
76 | 76 | ||
77 | ; header |
77 | ; header |
78 | dw 'PE' xor 'S' ; Signature |
78 | dw 'PE' xor 'S' ; Signature |
79 | dw Characteristics or 0x100 ; IMAGE_FILE_32BIT_MACHINE |
79 | dw Characteristics or 0x100 ; IMAGE_FILE_32BIT_MACHINE |
80 | dd AddressOfEntryPoint |
80 | dd AddressOfEntryPoint |
81 | dd ImageBase |
81 | dd ImageBase |
82 | db SectionAlignmentLog |
82 | db SectionAlignmentLog |
83 | db FileAlignmentLog |
83 | db FileAlignmentLog |
84 | db MajorSubsystemVersion |
84 | db MajorSubsystemVersion |
85 | db MinorSubsystemVersion |
85 | db MinorSubsystemVersion |
86 | dd SizeOfImage |
86 | dd SizeOfImage |
87 | dd SizeOfStackReserve |
87 | dd SizeOfStackReserve |
88 | dd SizeOfHeapReserve |
88 | dd SizeOfHeapReserve |
89 | SizeOfHeadersField: |
89 | SizeOfHeadersField: |
90 | dd 0 |
90 | dd 0 |
91 | db Subsystem |
91 | db Subsystem |
92 | db DstNumberOfRvaAndSizes |
92 | db DstNumberOfRvaAndSizes |
93 | dw NumberOfSections |
93 | dw NumberOfSections |
94 | ; directories |
94 | ; directories |
95 | irps dir,SPE_DIR_ORDER |
95 | irps dir,SPE_DIR_ORDER |
96 | { |
96 | { |
97 | if SPE_DIRECTORY_#dir < DstNumberOfRvaAndSizes |
97 | if SPE_DIRECTORY_#dir < DstNumberOfRvaAndSizes |
98 | dd DirRVA_#dir, DirSize_#dir |
98 | dd DirRVA_#dir, DirSize_#dir |
99 | end if |
99 | end if |
100 | } |
100 | } |
101 | 101 | ||
102 | NumBytesDeleted = pehea + 0F8h - $ + NumberOfSections*0Ch |
102 | NumBytesDeleted = pehea + 0F8h - $ + NumberOfSections*0Ch |
103 | DeltaDeleted = NumBytesDeleted and not (FileAlignment - 1) |
103 | DeltaDeleted = NumBytesDeleted and not (FileAlignment - 1) |
104 | ; Use store instead of declaring SizeOfHeaders - DeltaDeleted directly in dd |
104 | ; Use store instead of declaring SizeOfHeaders - DeltaDeleted directly in dd |
105 | ; to avoid the second compilation pass. |
105 | ; to avoid the second compilation pass. |
106 | store dword SizeOfHeaders - DeltaDeleted at SizeOfHeadersField |
106 | store dword SizeOfHeaders - DeltaDeleted at SizeOfHeadersField |
107 | TimeStampInExportTable = 0 |
107 | TimeStampInExportTable = 0 |
108 | ; sections |
108 | ; sections |
109 | repeat NumberOfSections |
109 | repeat NumberOfSections |
110 | file filename:pehea+0F8h+(%-1)*28h,18h |
110 | file filename:pehea+0F8h+(%-1)*28h,18h |
111 | load VirtualSize dword from $-10h |
111 | load VirtualSize dword from $-10h |
112 | load VirtualAddress dword from $-0Ch |
112 | load VirtualAddress dword from $-0Ch |
113 | load SizeOfRawData dword from $-8 |
113 | load SizeOfRawData dword from $-8 |
114 | load PointerToRawData dword from $-4 |
114 | load PointerToRawData dword from $-4 |
115 | PointerToRawData = PointerToRawData - DeltaDeleted |
115 | PointerToRawData = PointerToRawData - DeltaDeleted |
116 | store dword PointerToRawData at $-4 |
116 | store dword PointerToRawData at $-4 |
117 | if DirRVA_EXPORT <> 0 & DirRVA_EXPORT+4 >= VirtualAddress & DirRVA_EXPORT+8 <= VirtualAddress + VirtualSize & DirRVA_EXPORT+8 <= VirtualAddress + SizeOfRawData |
117 | if DirRVA_EXPORT <> 0 & DirRVA_EXPORT+4 >= VirtualAddress & DirRVA_EXPORT+8 <= VirtualAddress + VirtualSize & DirRVA_EXPORT+8 <= VirtualAddress + SizeOfRawData |
118 | TimeStampInExportTable = DirRVA_EXPORT+4 - VirtualAddress + PointerToRawData |
118 | TimeStampInExportTable = DirRVA_EXPORT+4 - VirtualAddress + PointerToRawData |
119 | end if |
119 | end if |
120 | file filename:pehea+0F8h+(%-1)*28h+24h,4 |
120 | file filename:pehea+0F8h+(%-1)*28h+24h,4 |
121 | end repeat |
121 | end repeat |
122 | ; padding to keep FileAlignment |
122 | ; padding to keep FileAlignment |
123 | times NumBytesDeleted - DeltaDeleted db 0 |
123 | times NumBytesDeleted - DeltaDeleted db 0 |
124 | ; data |
124 | ; data |
125 | file filename:pehea+0F8h+NumberOfSections*28h |
125 | file filename:pehea+0F8h+NumberOfSections*28h |
126 | if TimeDateStamp <> 0 and TimeStampInExportTable <> 0 |
126 | if TimeDateStamp <> 0 & TimeStampInExportTable <> 0 |
127 | store dword TimeDateStamp at TimeStampInExportTable |
127 | store dword TimeDateStamp at TimeStampInExportTable |
128 | end if>>=>=>>>>>>> |
128 | end if>>=>=>>>>>>> |