News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

External function scanner supporting HLA

Started by Vortex, January 18, 2005, 08:18:47 PM

Previous topic - Next topic

Vortex

Hi friends,

Originally, the tool was intended for Fasm, by the time, I decided to extend the features of my tool, it supports various assemblers Masm,Tasm,LzAsm,GoAsm and finally my little "scanning" tool can be used with HLA.

So what does exactly the scanner? It reads an asm source file and looks for "invoked" functions which are originally external functions and then it creates a file containing a list of external function declarations.

Let's consider this simple FASM example:

format PE GUI 4.0
entry start

include '%fasminc%\win32a.inc'

section '.data' data readable writeable

text    db "Hi! I'm the example program!",0
caption db "Win32 Assembly",0

section '.code' code readable executable
start:
        invoke  MessageBox,0,text,caption,MB_OK
        invoke  ExitProcess,0

include 'Msgbox.imp'


scan Msgbox.asm

The resulting imp file:

section '.idata' import data readable writeable

  library kernel32,'kernel32.dll',\
          user32,'user32.dll'

  import kernel32,\
         ExitProcess,'ExitProcess'

  import user32,\
         MessageBox,'MessageBoxA'


So, what is the benefit of using this technique based on creating the list with the "just necessary" function declarations? Simply, it reduces the work of the assembler\compiler which means "reduced assembly time \ faster compilation"

To apply this technique to HLA, I created a very simple macro, invoke for stdall API functions:

#macro invoke;
#endmacro;


A quick demonstration:


// Iczelion's tutorial #2: MessageBox

program msgBoxDemo;
#Include( "w2.hhf" )

#macro invoke;
#endmacro;

static

#include("Msgbox.imp")
               
caption:string:="Iczelion's tutorial no.2";
msg:string:="Win32/HLA Assembly is Great!";

begin msgBoxDemo;

   invoke MessageBox(
   0,
                msg,
                caption,
   w.MB_OK   
   );
           
end msgBoxDemo;



scan Msgbox.hla -h


Msgbox.imp file:

MessageBox : procedure
(
p0:DWORD;
p1:DWORD;
p2:DWORD;
p3:DWORD
);
@stdcall;
returns("eax");
external("__imp__MessageBoxA@16");


The tool supports nested include files. To reduce the processing time of the tool,by-pass the include files which doesn't contain any API function, this is possible by typing Invoke with uppercase I :

#Include( "strings.hhf" )
#Include( "memory.hhf" )
#Include( "args.hhf" )
#Include( "conv.hhf" )


w2.hhf is a smaller version of the original windows include file w.hhf   It doesn't contain any API function declaration.

You can check the attachment to see some HLA examples adapted for faster compilation.



[attachment deleted by admin]

Sevag.K


Hi Vortex,

This latest version simplifies things.  I see that you scan the actual dll files to get the templates.
Although this works, it doesn't do justice to HLA's type checking facilities.

I have a suggestion if you would like to implement for a future version:
Add an option to scan the w.hhf (or a file with only export definitions stripped out of w.hhf), and
scan the dlls if the object is not found there.  Then you can copy the declaration right from the
export declaration file to ensure that the correct types that everyone expects will be copied.


Vortex

Hi Sevag,

Thamks for your idea about scanning w.hhf  I will think about it.