Here's my alternative macro set for building pe import directory. It's different from the standard fasm's macro that
-the 'library' macro is not needed anymore.
-the 'import' macro now only build a list of dll and its imported functions (so we need another macro that build the import directory, i name it '.import' here). this allow us to seperate the import in another file (as in win32ax.inc) but still allow us to add import dll (before '.import' is used)
here's an example of how to use it :
format pe gui 4.0
entry mula
import kernel32.dll,\
GetModuleHandle,"GetModuleHandle"
import kernel32.dll,\
ExitProcess,"ExitProcess"
import user32.dll,\
MessageBox,"MessageBoxA"
mula:
push 0
push title
push msg
push MB_ICONINFORMATION
call [MessageBox]
call [ExitProcess]
ret
msg db "Hello Universe",0
title db "Test", 0
.import
;Win32 consts
MB_ICONINFORMATION=0x40
and here's the macro :
macro import dll, [func] {
common
match =dll#@listed, dll#@listed \{
dll#@listed equ
lib@list equ lib@list, dll
\}
local @temp
@temp equ dll#@list
restore dll#@list
dll#@list equ @temp, func
restore @temp
}
macro .import {
match =lib@list=,libs, lib@list \{
build_import_desc libs
\}
}
macro build_import_desc [lib] {
common
align 4
data import
forward
if defined lib#@used
dd rva lib#@oft, 0, 0, rva lib#@name, rva lib#@ft
end if
common dd 0,0,0,0,0
end data
forward
match =lib#@list=,funcs,lib#@list \{
build_thunk lib, funcs
\}
if defined lib#@used
lib#@name db `lib,0
end if
restore lib#@listed, lib#@list
}
macro build_thunk lib, [label, name] {
common
lib#@ft:
forward
if used label
if name eqtype ''
local _label
label dd rva _label
else
label dd 0x80000000 or name
end if
end if
common
if $>lib#@ft
lib#@used=1
dd 0
end if
lib#@oft:
forward
if used label
if name eqtype ''
dd rva _label
else
dd 0x80000000 or name
end if
end if
common
if defined lib#@used
dd 0
end if
forward
if used label & name eqtype ''
_label dw 0
db name, 0
end if
}