flat assembler
Message board for the users of flat assembler.

flat assembler > Windows > Extened library,import and export macro defines feature

Author
Thread Post new topic Reply to topic
Kevin_Zheng



Joined: 04 Jul 2003
Posts: 125
Location: China
Dear Privalov:
The fasm library, import and export macro defines present some of limitation. So I modified the macro defines.

Pleasee see the below descrption:
1. "library" macro doesn't define OriginalFirstThunk field, It will use 0 to instead it. In the normal application, the windows will load application OK, But if the application is a WDM driver, because it desn't "OriginalFirstThunk" struct, the driver can't be load.
And others, In the pe tutrial of Iczelion, it descript the question about the "OriginalFirstThunk":
"If value of OriginalFirstThunk is not zero, follow the RVA in OriginalFirstThunk to the RVA array. If OriginalFirstThunk is zero, use the value in FirstThunk instead. Some linkers generate PE files with 0 in OriginalFirstThunk. This is considered a bug. Just to be on the safe side, we check the value in OriginalFirstThunk first. "
And I have found that the complier file can't bind by bind.exe. Bind.exe is suported by Microsoft SDK. If we Modified the library macro as the below, the bind.exe worked ok and driver loaded is ok, also.

Code:
macro library [name,string] { forward local _label if ~ name#.needed dd RVA name,0,0,RVA _label,RVA name end if common dd 0,0,0,0,0 forward if ~ name#.needed _label db string,0 end if }


2. import and export macros can't support number reference function import and export features. So we can't invoke some undocument APIs on the user32.dll. And others, an owner dll can't export number reference
functions. So I modified the import and export macros, It will support number reference function import and export features. I have test it ok . Please see the attached package.

Code:
IMAGE_ORDINAL_FLAG32 = 80000000h macro import name,[label,string] { common name: forward if used label if string eqtype "" local _label label dd RVA _label else label dd string+IMAGE_ORDINAL_FLAG32 end if end if common if $ > name name#.needed = FALSE dd 0 else name#.needed = TRUE end if forward if used label if string eqtype "" _label dw 0 db string,0 end if end if } ; macroinstruction for making export section macro export dllname,nbase,[label,string] ; strings must be sorted { common local module,addresses,names,ordinal,count_func,count_name count_func = 0 count_name = 0 forward count_func = count_func+1 IF string eqtype "" count_name = count_name+1 END IF common IF nbase eq dd 0,0,0,RVA module,1 ELSE dd 0,0,0,RVA module,nbase END IF dd count_func,count_name,RVA addresses,RVA names,RVA ordinal addresses: forward dd RVA label common names: forward IF string eqtype "" local name dd RVA name END IF common ordinal: count_name = 0 forward IF string eqtype "" dw count_name END IF count_name = count_name+1 common module db dllname,0 forward IF string eqtype "" name db string,0 END IF }


3. And others, the user defined no parameter proc can't be called through stdcall macro. It only called by "call" instruction. Why can't we unit the present parameters and no prarameter procedure? Please see the
belowing macros:

Code:
macro stdcall proc,[arg] ; call procedure { reverse IF ~ arg eq pushd arg END IF common call proc } macro invoke proc,[arg] ; invoke procedure (indirect) { common stdcall [proc],arg }


4. We often call some APIs used string parameter. The string parameter only used one, I have a macro for the edge:

Code:
macro strcall proc,[arg] { reverse IF arg eq ELSE IF arg eqtype "" call @f DB arg,0 @@: ELSE push arg END IF common call [proc] } strcall LoadCursorFromFile,"dragon.ani"


Do you think it? Thank you.


Description:
Download
Filename: ord_dll.zip
Filesize: 2.88 KB
Downloaded: 99 Time(s)

Post 16 Feb 2004, 09:40
View user's profile Send private message MSN Messenger Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 6862
Location: Kraków, Poland
The Win32 macro library for FASM is currently being redesigned in order to uniform it with the Fresh project. Thanks for all the input.

Do you propose "strcall" to be just separate macro instead of current solution of extended "invoke" in WIN32AX/WIN32WX?
Post 16 Feb 2004, 09:46
View user's profile Send private message Visit poster's website Reply with quote
Kevin_Zheng



Joined: 04 Jul 2003
Posts: 125
Location: China
Dear Privalov:
Yes, The strcall macro can have dword parameter and string parameters,
For example:
strcall MessageBox, [hWnd],'Text','Caption',MB_OK.
Post 16 Feb 2004, 09:55
View user's profile Send private message MSN Messenger Reply with quote
Kevin_Zheng



Joined: 04 Jul 2003
Posts: 125
Location: China
A small change about the "strcall" macro:

Code:
macro strcall proc,[arg] { reverse local .@string IF arg eq ELSE IF arg eqtype "" call .@string DB arg,0 .@string: ELSE pushd arg END IF common call [proc] }


Last edited by Kevin_Zheng on 17 Feb 2004, 01:18; edited 1 time in total
Post 16 Feb 2004, 10:15
View user's profile Send private message MSN Messenger Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3475
Location: Bulgaria
Kevin_Zheng wrote:
Dear Privalov:
Yes, The strcall macro can have dword parameter and string parameters,
For example:
strcall MessageBox, [hWnd],'Text','Caption',MB_OK.


Well, actually I am not a big fan of this approach. It is good to demonstrate macro power, but it is not very suitable for writing real code. (besides for little examples and demos) Yes in real program, there are a lot of invokes using string parameters, but if macro creates this parameters for you, this strings are too obscure and only one-time usable. This approach may overbloat the code very easy and it will be hidden from the programmer. (especially beginner - but you know beginers will use this feature more that advanced). Why to introduce such bad practices? Of course there is another approach - when the macro check the strings and define the strings only once. But unfortunately it is imposible with today macro system of FASM. I think about some "strings manager" tool in Fresh that to make this dirty work, but it is only project.

Regards.
Post 16 Feb 2004, 10:47
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Kevin_Zheng



Joined: 04 Jul 2003
Posts: 125
Location: China
One using edge:
We often used "LoadLibrary" and "GetProcAddress" for getting address of APIs. I think that "srcall" macro is a solution for it.

And others, A beginner should be use the lowest feature to study the assembler. For example: Don't use .if and .whle advanced macro define, the beginner should use pure jxx instruction to implement it. Embarassed
And in the another edge, The beginer will grow on this study period, It will write some big program and have truly understand the black box of Language. I think that some advanced macros will help it.

Do you think it? thank you.
Post 16 Feb 2004, 11:12
View user's profile Send private message MSN Messenger Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3475
Location: Bulgaria
Kevin_Zheng wrote:
One using edge:
We often used "LoadLibrary" and "GetProcAddress" for getting address of APIs. I think that "srcall" macro is a solution for it.


Well, it is a matter of personal writing style. For example I almost never use LoadLibrary. Smile I think that the macroses in standard library should be more "common", "clear", not bounded to someones preferences. Of course there should be some "advanced" libraries for every taste, but now we talking about the "root" - standard macro library.
One example - normal stdcall (and invoke) macro is very simple: push, push, call. It is absolutely clear for everyone, even from HLL's there is the same approach. "stdcall" macro works this way everytime, there is no exceptions and complex behaviour. On other hand "stdcall" with string parameters works completly different way. It have complex behaviour depending from parameters and there are more than one way to define strings in such macro. This IMHO should be very confusing for beginers and even for advanced user.

Quote:
And others, A beginner should be use the lowest feature to study the assembler. For example: Don't use .if and .whle advanced macro define, the beginner should use pure jxx instruction to implement it.


About "if" and "while" - I think that such macroses doesn't have any advantage in comparison with cmp/Jcc instructions. They are simply slavery to habits from HLL's. They are not objectively more short, clear or readable than simple short sequences of native asm instructions. "stdcall" is another deal, because it may short the sequence of instructions from 10 and more rows to one or two, and to make code really much easy to read/understand.
I am follower of the "golden mean" approach for beginers and for advanced users. Not very big, absolutely clear set of standard macroses, especially those that define code. For data definition there may be some more complex macroses, but again without extreams. Smile
For example MASM users often write programs using only HLL constructions (if, while, case, etc.) and that is viciously as much as to push manually parameters in the stack for invoke.

Regards
Post 16 Feb 2004, 11:40
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 861
Location: Colombia
Kevin_Zheng,
Thanks for the macros ! I'm going to use them all but the strcall macro because I agree with JohnFound:

JohnFound wrote:
This approach may overbloat the code very easy and it will be hidden from the programmer.

I fully agree with this. Using string args difficults the debugging process and embedding strings within code forces the cache to flush avoiding processor when tries to optimize jumps.[/code]
Post 16 Feb 2004, 13:32
View user's profile Send private message Yahoo Messenger Reply with quote
comrade



Joined: 16 Jun 2003
Posts: 1114
Location: Russian Federation
Why not use local label instead of @@? If programmer has some @@ he uses and stdcall inside it, it will destroy it.

_________________
comrade (comrade64@live.com; http://comrade.ownz.com/)
Post 16 Feb 2004, 15:27
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Kevin_Zheng



Joined: 04 Jul 2003
Posts: 125
Location: China
Please see the above reply. I have changed it. Thank your advice.
Post 17 Feb 2004, 01:28
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 © 2004-2018, Tomasz Grysztar.

Powered by rwasa.