flat assembler
Message board for the users of flat assembler.

Index > Main > [updated] Multisections

Author
Thread Post new topic Reply to topic
Overclick



Joined: 11 Jul 2020
Posts: 197
Overclick
This is why I like masm -- simple sections, sticked together by compilation. I mean .code .data...Any macro can make parts for sections. What's wrong with fasm?
Original fasm macros uses it once and uses .end macro -- such a silly.
Lets do something with it. Also I don't use entry, end entry etc. First .code section means that for me.
Code:
macro .data {
     section '.idata' import data readable writeable
     library kernel32,'KERNEL32.DLL',\
             user32,'USER32.DLL',\
             gdi32,'GDI32.DLL',\
             advapi32,'ADVAPI32.DLL',\
             comctl32,'COMCTL32.DLL',\
             comdlg32,'COMDLG32.DLL',\
             shell32,'SHELL32.DLL',\
             wsock32,'WSOCK32.DLL'

     import_kernel32
     import_user32
     import_gdi32
     import_advapi32
     import_comctl32
     import_comdlg32
     import_shell32
     import_wsock32

     all_api

     section '.data' data readable writeable 
}
macro .code {
  section '.text' code readable executable
  entry $
  sub rsp,8
}
macro .rsrc value { section '.rsrc' resource from value data readable }
    

How to remake this macros to stick side by side?
Have I use some additional include files as '.code and data.inc' and "if defined" once "store" all lines on it until next pseudo section started? Is it even possible at all?


Last edited by Overclick on 09 Sep 2020, 23:46; edited 2 times in total
Post 21 Jul 2020, 11:27
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17625
Location: In your JS exploiting you and your system
revolution
Post 21 Jul 2020, 11:30
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 197
Overclick
Seems like idea is to use some sort of different names, but I think we can use files to store all subsections together.
Post 21 Jul 2020, 11:36
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 814
Roman
Good macro somthing like this:

macro .dll [arg] {
section '.idata' import data readable writeable
library arg,`arg#'.DLL',\


import_#arg

}

In code:
.dll kernel32,user32,gdi32
Post 22 Jul 2020, 12:39
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 555
fasmnewbie
Overclick wrote:
This is why I like masm -- simple sections, sticked together by compilation. I mean .code .data...Any macro can make parts for sections. What's wrong with fasm?


I don't know man, the last time I tried, MASM's '.data' macro still unable to align to 32-byte boundaries. Horrible macro for dealing with YMM data. Had to move down to raw "dseg segment". I hope it is already fixed by now.
Post 24 Jul 2020, 01:03
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 197
Overclick
I did it
Code:
macro .multisection entry_file {        
        macro .data \{ 
                end if 
                if current='data'
        \}
        macro .idata \{ 
                end if 
                if current='idata'
        \}
        macro .code \{
                end if
                if current='code'
        \}
        current='idata'
        section '.idata' import data readable writeable
        if current='idata'
                include entry_file
        end if
        current='data'
        section '.data' data readable writeable 
        if current='data'
                include entry_file
        end if
        current='code'
        section '.text' code readable executable
        entry $
        sub rsp,8
        if current='code'
                include entry_file
        end if
}       

.multisection 'MyWorkFile.asm'     

Wink
Post 30 Jul 2020, 14:01
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 814
Roman
How use this ?
What code in MyWorkFile.asm ?
Post 30 Jul 2020, 14:50
View user's profile Send private message Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 197
Overclick
Put this macro on header/Main file or include it to there.
Write your program on some separate file then put it there by
.multisection '<your program>'
Post 30 Jul 2020, 14:57
View user's profile Send private message Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 197
Overclick
Upd: Use it carefully with "fix" where you need it. Declare it before or after multisection.
Post 31 Jul 2020, 16:14
View user's profile Send private message Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 197
Overclick
UPDATED RELEASE Cool :
Code:
macro .multisection [entry_file] {
        common
        macro proc [param] \{ 
                end if
                if cuRRent='code'
        \}      
        macro endp \{
                end if
                if cuRRent='code'
        \}
        macro .data \{ 
                end if
                if cuRRent='data'
        \}
        macro .idata \{ 
                end if
                if cuRRent='idata'
        \}
        macro .code \{
                end if
                if cuRRent='code'
        \}
        macro .comment \{
                end if
                if cuRRent='comment'
        \}  
        section '.idata' import data readable writeable 
        cuRRent='idata'
        forward
        if cuRRent='idata'
                include entry_file
        end if
        common
        section '.data' data readable writeable 
        cuRRent='data'
        forward
        if cuRRent='data'
                include entry_file
        end if
        common
        cuRRent='code'
        purge proc
        purge endp
        macro proc [param] \{ 
                \common
                end if
                proc param
                if cuRRent='code'
        \}      
        macro endp \{
                end if
                endp
                if cuRRent='code'
        \}
        section '.text' code readable executable
        entry $
        sub rsp,8
        forward
        if cuRRent='code'
                include entry_file
        end if
}    

FEATURES:
1. Linker. It will combine all your sections in all project files at same time.
2. Proc. You can use multisections inside procedures.
3. Unlimited sections any time you need it.
4. Easy to add some more kind of sections like .rsrc
5. Short names like masm .code .data (up to you actually)
6. No need of .end
7. Comment whole block by .comment

Do not use fix inside linked files. Do not declare sections inside if operators.
To enjoy it put(include) the macro to Header(Main file) then link your project files by:
Code:
.multisection '<your project file 1>','<your project file 2>','<your project file n...>'
    


Last edited by Overclick on 09 Sep 2020, 23:45; edited 1 time in total
Post 07 Aug 2020, 06:26
View user's profile Send private message Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 197
Overclick
New feature:
.comment
Code:
        macro .comment
        \{
                end if
                if cuRRent='comment'
        \}    

Easiest way to comment whole block of code when you need it. Enjoy Wink
Post 09 Sep 2020, 23:43
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.