2 include '../../../examples/x86/include/80386.inc'
\r
4 macro format?.PE? settings
\r
5 PE.Settings.Characteristics = IMAGE_FILE_EXECUTABLE_IMAGE or IMAGE_FILE_32BIT_MACHINE or IMAGE_FILE_LINE_NUMS_STRIPPED or IMAGE_FILE_LOCAL_SYMS_STRIPPED
\r
6 PE.Settings.DllCharacteristics = 0
\r
7 PE.Settings.Stamp = +VERSION
\r
8 PE.Settings.LegacyHeaders = 0
\r
10 define seq settings:
\r
14 else match =DLL? more, seq
\r
15 PE.Settings.Characteristics = PE.Settings.Characteristics or IMAGE_FILE_DLL
\r
17 else match =large? more, seq
\r
18 PE.Settings.Characteristics = PE.Settings.Characteristics or IMAGE_FILE_LARGE_ADDRESS_AWARE
\r
20 else match =WDM? more, seq
\r
21 PE.Settings.DllCharacteristics = PE.Settings.DllCharacteristics or IMAGE_DLLCHARACTERISTICS_WDM_DRIVER
\r
23 else match =NX? more, seq
\r
24 PE.Settings.DllCharacteristics = PE.Settings.DllCharacteristics or IMAGE_DLLCHARACTERISTICS_NX_COMPAT
\r
26 else match =at? base =on? stub :, seq
\r
27 PE.Settings.ImageBase = base
\r
28 PE.Settings.Stub = stub
\r
30 else match =at? base :, seq
\r
31 PE.Settings.ImageBase = base
\r
33 else match =on? stub :, seq
\r
34 PE.Settings.Stub = stub
\r
37 match =GUI? more, seq
\r
38 PE.Settings.Subsystem = IMAGE_SUBSYSTEM_WINDOWS_GUI
\r
40 else match =console? more, seq
\r
41 PE.Settings.Subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI
\r
43 else match =native? more, seq
\r
44 PE.Settings.Subsystem = IMAGE_SUBSYSTEM_NATIVE
\r
45 PE.Settings.SectionAlignment = 32
\r
46 PE.Settings.FileAlignment = 32
\r
48 else match =EFI? more, seq
\r
49 PE.Settings.Magic = 0x20B
\r
50 PE.Settings.Subsystem = IMAGE_SUBSYSTEM_EFI_APPLICATION
\r
52 else match =EFIboot? more, seq
\r
53 PE.Settings.Magic = 0x20B
\r
54 PE.Settings.Subsystem = IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER
\r
56 else match =EFIruntime? more, seq
\r
57 PE.Settings.Magic = 0x20B
\r
58 PE.Settings.Subsystem = IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER
\r
61 err 'invalid argument'
\r
65 PE.Settings.MajorSubsystemVersion = V
\r
66 PE.Settings.MinorSubsystemVersion = v
\r
71 if PE.Settings.Characteristics and IMAGE_FILE_DLL
\r
72 format binary as 'dll'
\r
74 format binary as 'exe'
\r
76 include '../../../examples/x86/include/format/pe.inc'
\r
91 label . : sizeof.name
\r
95 calminstruction invoke? proc*,args&
\r
96 local tmp, tmpst, stack
\r
100 match tmpst=,args, args
\r
106 check args relativeto ebp & args - ebp
\r
108 arrange tmp, =push =eax
\r
110 arrange tmp, =lea =eax,[args]
\r
112 arrange tmp, =xchg =eax,[=esp]
\r
116 arrange tmp, =pushd args
\r
122 arrange tmp, =call [proc]
\r
124 end calminstruction
\r
126 calminstruction mov? dest*,src*
\r
130 check src relativeto ebp & src - ebp
\r
132 arrange tmp, =lea dest,[src]
\r
136 arrange tmp, =mov dest,src
\r
138 end calminstruction
\r
140 macro library? definitions&
\r
142 iterate <name,string>, definitions
\r
143 if ~ name.redundant
\r
144 dd RVA name.lookup,0,0,RVA name.str,RVA name.address
\r
149 iterate <name,string>, definitions
\r
150 if ~ name.redundant
\r
151 name.str db string,0
\r
157 macro import? name,definitions&
\r
159 if defined name.referred
\r
161 iterate <label,string>, definitions
\r
163 if string eqtype ''
\r
166 dd 80000000h + string
\r
177 iterate <label,string>, definitions
\r
179 if string eqtype ''
\r
180 label dd RVA name.label
\r
182 label dd 80000000h + string
\r
186 if ~ name.redundant
\r
189 iterate <label,string>, definitions
\r
190 if used label & string eqtype ''
\r
199 macro export dllname,exports&
\r
200 iterate <label,string>, exports
\r
202 local module,addresses,names,ordinal,count
\r
204 dd 0,0,0,RVA module,1
\r
205 dd count,count,RVA addresses,RVA names,RVA ordinal
\r
213 dd RVA names.name#%
\r
219 module db dllname,0
\r
222 names.name#% db string,0
\r
225 local x,y,z,str1,str2,v1,v2
\r
232 load v1:dword from names+z*4
\r
233 str1 = ($-(RVA $))+v1
\r
234 load v2:dword from names+(z-x)*4
\r
235 str2 = ($-(RVA $))+v2
\r
237 load v1:byte from str1+%-1
\r
238 load v2:byte from str2+%-1
\r
244 load v1:dword from names+z*4
\r
245 load v2:dword from names+(z-x)*4
\r
246 store v1:dword at names+(z-x)*4
\r
247 store v2:dword at names+z*4
\r
248 load v1:word from ordinal+z*2
\r
249 load v2:word from ordinal+(z-x)*2
\r
250 store v1:word at ordinal+(z-x)*2
\r
251 store v2:word at ordinal+z*2
\r
266 include '../kernel32.inc'
\r