flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Convert fasm1 macro to fasmg (macro export dllname, [l, s])

Author
Thread Post new topic Reply to topic
dunkaist



Joined: 31 Jul 2015
Posts: 24
dunkaist 19 Jan 2017, 18:19
Hello,

I'm converting some macros to fasmg syntax and here is one I don't know how to deal with.
Code:
macro export dllname, [label, string]
{
}    

It's valid for fasm1. Unfortunately, corresponding fasmg macro doesn't work.
Code:
$ cat c.asm 
macro export dllname, [label, string]
end macro

$ INCLUDE=/tmp/fasmg/examples/x86/include fasmg c.asm c.dll
flat assembler  version g.hoh12
c.asm [1]:
        macro export dllname, [label, string]
Processed: macro export dllname, [label, string]
Error: invalid argument.    
Is it possible to convert this macro in a more or less straightforward way?
Post 19 Jan 2017, 18:19
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 19 Jan 2017, 20:26
I quickly prepared this more or less straightforward conversion:
Code:
macro export dllname,exports&
        iterate <label,string>, exports

                local module,addresses,names,ordinal,count
                count = %%
                dd 0,0,0,RVA module,1
                dd count,count,RVA addresses,RVA names,RVA ordinal
                addresses:
                repeat count
                        indx %
                        dd RVA label
                end repeat
                names:
                repeat count
                        dd RVA names.name#%
                end repeat
                ordinal:
                repeat count
                        dw %-1
                end repeat
                module db dllname,0
                repeat count
                        indx %
                        names.name#% db string,0
                end repeat

                local x,y,z,str1,str2,v1,v2
                x = count shr 1
                while x > 0
                        y = x
                        while y < count
                                z = y
                                while z-x >= 0
                                        load v1:dword from names+z*4
                                        str1 = ($-(RVA $))+v1
                                        load v2:dword from names+(z-x)*4
                                        str2 = ($-(RVA $))+v2
                                        while v1 > 0
                                                load v1:byte from str1+%-1
                                                load v2:byte from str2+%-1
                                                if v1 <> v2
                                                        break
                                                end if
                                        end while
                                        if v1 < v2
                                                load v1:dword from names+z*4
                                                load v2:dword from names+(z-x)*4
                                                store v1:dword at names+(z-x)*4
                                                store v2:dword at names+z*4
                                                load v1:word from ordinal+z*2
                                                load v2:word from ordinal+(z-x)*2
                                                store v1:word at ordinal+(z-x)*2
                                                store v2:word at ordinal+z*2
                                        else
                                                break
                                        end if
                                        z = z-x
                                end while
                                y = y+1
                        end while
                        x = x shr 1
                end while

                break
        end iterate
end macro    
I'm going to add it into my Win32 headers for fasmg basic package.

Some notes about the conversion: where fasm 1 had FORWARD/REVERSE blocks I use a combination of REPEAT and INDX to iterate through the parameter values, and since this way everything is done within the first iteration of the outer ITERATE directive, I use the final BREAK to skip the next (unnecessary) iterations.

I updated the syntax of LOAD/STORE to the new one recommended for fasmg. I also had to put additional brackets in the expression with RVA, because this is not an internal operator and it is defined by PE formatting macros as a symbolic value "-PE.IMAGE_BASE+", so it no longer has precedence over minus sign like the RVA operator in fasm 1. Other than that, the export sorting code stayed as it was in fasm 1 version.
Post 19 Jan 2017, 20:26
View user's profile Send private message Visit poster's website Reply with quote
dunkaist



Joined: 31 Jul 2015
Posts: 24
dunkaist 19 Jan 2017, 20:53
Tomasz,
thank you for the quick and complete answer!

I'm keeping an eye on your 'compatibility' package, and this macro is just what I need. I learned a lot from your post.
Post 19 Jan 2017, 20:53
View user's profile Send private message 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.