flat assembler
Message board for the users of flat assembler.
Index
> Windows > sprintf for xp via fasmg, the codes work well. |
Author |
|
jiangfasm 08 Oct 2016, 05:59
Do you really use?
fasmg looks complicated |
|||
08 Oct 2016, 05:59 |
|
Tomasz Grysztar 08 Oct 2016, 10:08
uor99 wrote: sprintf for xp via fasmg, the codes work well. jiangfasm wrote: fasmg looks complicated Code: format PE GUI entry start macro stdcall proc,[arg] { reverse pushd arg common call proc } macro ccall proc,[arg] { common local size size = 0 reverse pushd arg size = size + 4 common call proc if size add esp,size end if } macro invoke proc,args& { stdcall [proc],args } macro cinvoke proc,args& { ccall [proc],args } ; rest of the source unchanged The fasmg sources use some macros that enable the same syntax as the macros defined in fasm's official headers, you can find them in source/windows/selfhost.inc This example for fasmg could be simplified a bit by using such macros: Code: ; note: the FORMAT.INC from latest packages includes the instruction set ; macros on its own; if you need to select the exact instruction set, ; you have to use the PE.INC formatter directly ; include '80386.inc' include 'format/format.inc' format PE GUI entry start include 'macros.inc' section '.idata' import data readable writeable library kernel,'KERNEL32.DLL',\ user,'USER32.DLL' import kernel,\ ExitProcess,'ExitProcess',\ CreateFile,'CreateFileA',\ ReadFile,'ReadFile',\ WriteFile,'WriteFile',\ CloseHandle,'CloseHandle',\ SetFilePointer,'SetFilePointer',\ GetCommandLine,'GetCommandLineA',\ GetEnvironmentVariable,'GetEnvironmentVariable',\ GetStdHandle,'GetStdHandle',\ VirtualAlloc,'VirtualAlloc',\ VirtualFree,'VirtualFree',\ GetTickCount,'GetTickCount',\ GetSystemTime,'GetSystemTime',\ GlobalMemoryStatus,'GlobalMemoryStatus' import user,\ MessageBoxA,'MessageBoxA',\ wsprintfA,'wsprintfA' ; rest of the source unchanged Code: macro struct? name macro ends?! end namespace iterate definition, args@struct match name:value, definition store value at .name else match name==value, definition store value at .name else match value, definition err 'unnamed values not supported' end match end iterate end struc virtual at 0 name name sizeof.name = $ end virtual purge ends? end macro struc name args@struct& label . : sizeof.name namespace . end macro macro stdcall proc*,args& iterate arg, args indx 1+%%-% pushd arg end iterate call proc end macro macro ccall proc*,args& local size size = 0 iterate arg, args indx 1+%%-% pushd arg size = size + 4 end iterate call proc if size add esp,size end if end macro macro invoke proc*,args& stdcall [proc],args end macro macro cinvoke proc*,args& ccall [proc],args end macro macro library? definitions& PE.Imports: iterate <name,string>, definitions if ~ name.redundant dd RVA name.lookup,0,0,RVA name.str,RVA name.address end if name.referred = 1 end iterate dd 0,0,0,0,0 iterate <name,string>, definitions if ~ name.redundant name.str db string,0 align 2 end if end iterate end macro macro import? name,definitions& align 4 if defined name.referred name.lookup: iterate <label,string>, definitions if used label if string eqtype '' dd RVA name.label else dd 80000000h + string end if end if end iterate if $ > name.lookup name.redundant = 0 dd 0 else name.redundant = 1 end if name.address: iterate <label,string>, definitions if used label if string eqtype '' label dd RVA name.label else label dd 80000000h + string end if end if end iterate if ~ name.redundant dd 0 end if iterate <label,string>, definitions if used label & string eqtype '' name.label dw 0 db string,0 align 2 end if end iterate end if end macro I have not yet started working on an official set of Windows macro headers for fasmg, because my thought was that perhaps the could make a better use fasmg macro engine by adopting some new syntax. The macros like "import", and all resource macros, use the syntax that is a relic of times when fasm had only a very basic macro processor. With the macros of fasmg it could be possible to implement something much more sophisticated, or even emulate syntax of some other assemblers if needed. Still, because fasm's old resource macros are so simple, it should be a straightforward work to convert them when anyone needs them. |
|||
08 Oct 2016, 10:08 |
|
uor99 11 Oct 2016, 08:20
Eager to have more powerful macros of fasmg !
As for my codes, I have not found out the bug yet. It doesn't crash after exit. |
|||
11 Oct 2016, 08:20 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.