flat assembler
Message board for the users of flat assembler.

Index > Windows > Alternative 'import' macro..

Author
Thread Post new topic Reply to topic
Ancient One



Joined: 28 Feb 2005
Posts: 55
Ancient One 21 Jul 2005, 02:14
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 :
Code:
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 :
Code:
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
}
    
Post 21 Jul 2005, 02:14
View user's profile Send private message MSN Messenger Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.