flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Match around include

Author
Thread Post new topic Reply to topic
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 03 Jul 2020, 19:09
Suppose we have the following main.asm file:
Code:
match ! , abc
{
  include 'library.inc'
}    
and the following library.inc file:
Code:
!    

What I see is that the ! symbol is defined as itself in library.inc although I personally would expect it to be abc.

Current behaviour can definitely be overriden by putting the match into the library.inc but, as one might guess, it’s an attempt to simplify unit management, and that would require wrapping it into a more meaningfully-named macro at the beginning and using a fix directive for the closing }. Besides that would require additional level of {} escaping inside the unit which is not quite convenient.

I wonder if this behaviour is intended and if it is, it would be good to know about the reasoning behind it.
Post 03 Jul 2020, 19:09
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20414
Location: In your JS exploiting you and your system
revolution 04 Jul 2020, 01:37
The macro is expanded before the stuff inside is processed. So the match will find-and-replace all !'s in the single line "include 'library.inc'". Since there are no instances of ! in that line then it has no effect.
Post 04 Jul 2020, 01:37
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 04 Jul 2020, 07:59
And since it is processed line by line it is impossible to inject some symbolic value from outside the file being included, right? I mean, it’s impossible to expand include before the outer match gets processed, isn’t it?

The workaround might be to use equ for the symbol but I’m not quite sure if it is completely equivalent. Requires much more attention to restore it properly while match would make FASM check for balanced {}.
Post 04 Jul 2020, 07:59
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20414
Location: In your JS exploiting you and your system
revolution 04 Jul 2020, 08:10
You can use equ
Code:
! equ int3
include 'test.inc'    
Code:
!    
Code:
~ fasm test.asm && hd test.bin
flat assembler  version 1.73.08  (4053744 kilobytes memory)
1 passes, 1 bytes.
00000000  cc                                                |.|
00000001
~    
And enclose it in a macro
Code:
macro my_include file, var, replacement {
  var equ replacement
  include file
  restore var
}
my_include 'test.inc', !, int3    
Post 04 Jul 2020, 08:10
View user's profile Send private message Visit poster's website 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.