flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Extended headers and extra imports |
Author |
|
baldr 13 Apr 2010, 10:33
In Windows forum mindcooler has raised interesting question: How do I import CommandLineToArgvW from shell32.dll?
While it seems to involve editing of API\SHELL32.INC, some macro voodoo looks like to work: Code: ;;; This file is named "Win32WX+.Inc" ; These symbolic constants will collect additional libraries/imports irp lib, kernel32,user32,gdi32,advapi32,comctl32,comdlg32,shell32,wsock32 { additional_#lib#_imports equ } additional_libs equ ;;; ;;; Support macros (actually strucs ;-) ;;; struc reequ [value] { common restore .; «value» should not depend on equated symbolic constant, to keep it simple . equ value } struc append [items] { ; assumes list is initialized (at least empty, not undefined) common match items_value, items \{; got something to append match list_value, . \\{; both non-empty, concatenate with comma . reequ list_value, items_value \\} match , . \\{; list was empty, simply equate . reequ items \\} \} } struc if_in_list item, [list] { common . equ 0 forward match =item, list \{ . reequ 1 \} } struc if_odd_in_list item, [first, second] { common . reequ 0 forward match =item, first \{ . reequ 1 \} } ;;; ;;; Some real things ;;; macro library [lib, name] { ; Instead of generating import directory, collect lib names in additional_libs common local .done forward .done if_in_list lib, kernel32,user32,gdi32,advapi32,comctl32,comdlg32,shell32,wsock32 ; just in case somebody forgot that they're imported by default match =0, .done \{; not standard lib additional_libs append lib, name match =additional_#lib#_imports,\; clumsy way to check for undefined equ additional_#lib#_imports \\{ ; «import» before «library» additional_#lib#_imports equ \\} \} restore .done } macro import lib, [functions] { ; Similar to «library» above, collect imports common local .done .done if_in_list lib, kernel32,user32,gdi32,advapi32,comctl32,comdlg32,shell32,wsock32 match =1, .done \{ additional_#lib#_imports append functions \} match =0, .done \{; not standard lib match .libs, additional_libs \\{; dereference libraries list .done if_odd_in_list lib, .libs \\} match =0, .done \\{; «import» before «library» match =additional_#lib#_imports,\; clumsy way to check for undefined equ additional_#lib#_imports \\\{ additional_#lib#_imports equ \\\} \\} additional_#lib#_imports append functions \} } macro .end label { purge library, import; flush collectors down the drain, real workers on the way macro library [args] \{ \common match .libs, additional_libs \\{ library args, .libs \\} match , additional_libs \\{ library args \\} \} macro import lib, [functions] \{ \common local .done .done if_in_list lib, kernel32,user32,gdi32,advapi32,comctl32,comdlg32,shell32,wsock32 match =1, .done \\{; got standard lib match .imports, additional_\#lib\#_imports \\\{; got imports to add import lib, functions, .imports \\\} match , additional_\#lib\#_imports \\\{; got nothing import lib, functions \\\} \\} match =0,.done \\{; not standard lib import lib, functions \\} restore .done \} macro additional_libs_imports [lib, name] \{ match .imports, additional_\#lib\#_imports \\{ import lib, .imports restore additional_\#lib\#_imports \\} \} .end label match .libs, additional_libs \{ additional_libs_imports .libs \} purge library, import, additional_libs_imports; work is done, so are the workers } Code: ;;; This is test example format PE console include "Win32WX.Inc" include "Win32WX+.Inc" import shell32, CommandLineToArgvW, "CommandLineToArgvW"; quite unusual? import MSVCRT, _wprintf, "wprintf"; "Curiouser and curiouser!" import MSVCRT, _putws, "_putws" library MSVCRT, "MSVCRT" .code test_it: invoke CommandLineToArgvW, <invoke GetCommandLine>, argc mov esi, eax cinvoke _wprintf, msg_argc, [argc] .repeat cinvoke _putws, dword[esi] add esi, 4 dec [argc] .until ZERO? ret .data msg_argc TCHAR "argc=%u", 10, 0 align 4 argc rd 1 .end test_it |
|||
13 Apr 2010, 10:33 |
|
mindcooler 07 May 2010, 00:39
I really think fasmw needs complete win32/64 headers, or a really easy way of appending to the import lists not to lose its conciseness.
_________________ This is a block of text that can be added to posts you make. |
|||
07 May 2010, 00:39 |
|
baldr 07 May 2010, 13:39
mindcooler,
What do you mean, "complete"? Platform SDK contains ~1.8 million lines of .h, even if only 5% of them is relevant for FASM, that's almost ten-fold increase of API include files length. Would you take the burden of conversion? However, public repository of community-made include files (not only for Win32/64) can be helpful. It's maintenance that frightens me. Quote: …a really easy way of appending to the import lists not to lose its conciseness. |
|||
07 May 2010, 13:39 |
|
mindcooler 07 May 2010, 14:43
baldr wrote:
Perhaps not an all-encompassing win32, but complete entries (w2k+) for the DLLs already headered in fasm. Wasn't there a header conversion tool project somewhere? baldr wrote:
Not to depreciate your solution, personally I would prefer something like this: Code: include 'win32wxp.inc' import shell32,CommandLineToArgvW,'CommandLineToArgvW',2 import "someobscure.dll",SomeObscureFunction,'SomeObscureFunction'[,PCOUNT] _________________ This is a block of text that can be added to posts you make. |
|||
07 May 2010, 14:43 |
|
baldr 07 May 2010, 17:54
mindcooler,
Those macros do almost as you wish. I'd rather not modify standard import arguments' signature, probably this will do? Code: import rtl60="rtl60.bpl",\ Move(3), "@System@Move$qqrpxvpvi",\ UnicodeNToUtf8(4), "@System@UnicodeToUtf8$qqrpcuipbui" ;... import rtl60,\ UnicodeToUtf8(3), "@System@UnicodeToUtf8$qqrpcpbi" These functions use Borland fastcall calling conventions, another macro (bfinvoke)? Or better, calling convention can be declared right in import statement, saved in some constant and recognized by invoke macro. System::UnicodeToUtf8() is polymorphic, thus different labels. |
|||
07 May 2010, 17:54 |
|
mindcooler 07 May 2010, 19:44
Yeah, something like that would be great.
I will probably not be using borland libraries, but there doesn't seem to be a fastcall macro, direct or indirect, in proc32.inc. I take that it isn't that common. |
|||
07 May 2010, 19:44 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.