flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > how use "`" operator inside the macroinstruction?

Author
Thread Post new topic Reply to topic
tomz1



Joined: 10 May 2005
Posts: 2
tomz1
how use "`" operator to get the right parameter inside the macroinstruction?
thank you
some code:
Code:
include 'win32ax.inc'

cr fix 0dh,0ah
zzz db 'str1',0
tmp dd 0

macro ppp name,a1,a2,a3,a4,a5,a6,a7,a8,[args]
{
common
  display 'MessageBox='    ,`name,cr ;result:MessageBox
  display 'MB_OK='         ,`a1,cr   ;result:MB_OK
  display 'zzz='           ,`a2,cr   ;result:zzz
; display 'str2='          ,`a3,cr   ;result:error:unexpected characters
; display 'MB_OK+MB_YESNO=',`a4,cr   ;result:error:value out of range
  display '22='            ,`a5,cr   ;result:22
; display '[eax]='         ,`a6,cr   ;result:error:unexpected characters
  display 'NULL='          ,`a7,cr   ;result:NULL
; display 'DWORD[tmp]='    ,`a8,cr   ;result:error:extra characters on line
forward
  display '[args]='        ,`args,cr ;result:1234
}
     
macro ppp1 name,[args]
{
common
  display `name,cr
forward
  display '[args]=',`args,cr
}

.code
  start:
    ppp MessageBox,MB_OK,zzz,'str2',MB_OK+MB_YESNO,22,[eax],NULL,DWORD[tmp],1,2,3,4
    display 'str3',cr
    ppp1 MessageBox,1,eax,'3',[ebx] ;resurt:error!  
    ret
    
.end start
    
Post 10 May 2005, 07:26
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7724
Location: Kraków, Poland
Tomasz Grysztar
This operator applies only to the one symbol that immediately follows it, for example `MB_OK+MB_YESNO becomes 'MB_OK'+MB_YESNO. Also special characters, like [ are treated differently than symbols by preprocessor and therefore cause an error (this actually might be changed, but again, even if allowed, the `[ebx] would make the '['ebx] for you, since preprocessor sees each of [, ebx and ] as separate line elements. This is all because preprocessor operates on its own internal format, which looses some of the original information from source (like spacing) - for that reason I have not used the other possible syntax for this operator, which was like `argument` - converting everything enclosed within, as it wouldn't preserve the original formatting of text, since it was lost anyway while loading the source into preprocessor.
This feature was added in a late stage of fasm's development, mainly for the specific needs of the Fresh project - that's why it's design had to be affected by already existing architecture of fasm (reverse to how it should be usually). And more and more of such problems appear when I try to design (due to requests) some new features that were not initially planned - there are some limits: fasm was designed differently and it cannot become to be like any other assembler without rewriting it and breaking some of the most substantial features it has and principles it follows.


Last edited by Tomasz Grysztar on 10 May 2005, 11:49; edited 2 times in total
Post 10 May 2005, 11:37
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
ok, here it is.

`'str2' doesn't work, because you only can convert symbols to strings, not string to string.

`MB_OK+MB_YESNO
"`" operator converts next symbol to string, so it will become "MB_OK"+MB_YESNO

`[eax] - [eax] is not a symbol

`dword [tmp] isn't symbol too

in conclusion - you only can convert single symbols with "`" operator. To chekc others you have to use "eqtype"s, but there are many types.
I suggest something like (not tested)
[code]
macro displayvalue arg
{
if arg eqtype "a" ;if arg is string
display arg
else if arg eqtype 0 ;if arg is numeric constant/label/number
display `arg
else if arg eqtype ss ;if arg is semgnet register
display `arg
else
;we can't display things like [eax]. In theory it could have be done
;with virtually generating code, loading it and testing value
;in opcode, but IMHO that's not worth of effort, too many
;possibilietes ([ss:edi],dword [eax], byte [ss:4*eax+ebx+3], ...)
}
Post 10 May 2005, 11:43
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
tomz1



Joined: 10 May 2005
Posts: 2
tomz1
I just want to carry out the source code to debug to try in the olldbg.
so My problem is: How get a line of source code?
for try it,my some steps is as follows:

Code:
1.make F8.bat:
  @echo off
  del F:\Ollydbg_v1.10\udd\%1.*
  F:\fasm\bin\FASM.EXE %1.asm %1.exe >map.txt
  F:\Ollydbg_v1.10\Ollydbg.exe %1.exe

2.modify some macro:
  macro proc name,[arg]
  { 
    common
      if used name
         if BuildSourceCodeDebugMap=true
            display name,' CALL  ',`name
         end if
      name:
    ...
  }
  macro invoke proc,[arg]
  {
    common
      if BuildSourceCodeDebugMap=true
         nop
         display $-1,' <INVOKE ',`proc,'>'
      end if  
    ... 
  }
  macro .until [vars]
  {
    common
      if BuildSourceCodeDebugMap=true
         display $,' <.until>'
      end if  
    ...
  }
  ....

3.use F8.bat compile project,and For example,Include the nether code
  proc TApp_Run
    .msg MSG
  enter  
    lea ebx,[.msg]
    xor esi,esi
    .repeat
      invoke DispatchMessage,ebx
    .until. <icall GetMessage,ebx,esi,esi,esi>,e,0
    return
  endp

4.we get map.txt:
  flat assembler  version 1.60
  00401000 CALL  Sub_null
  ...
  00401298 CALL  TApp_Run
  004012A1 <.repeat>
  004012A1 <INVOKE DispatchMessage>
  004012A9 <ICALL GetMessage>
  004012B4 <.until>
  ...
  7 passes, 1.6 seconds, 2048 bytes.

5.use some plugins(p.s. Labelmaster.dll) in olldbg,import Labels and Comments from "map.txt". 
  so we can see source code in olldbg:
00401298 >/$  C8 200000       ENTER   20,0                    ;  CALL  TApp_Run
0040129C  |.  8D5D E0         LEA     EBX,[LOCAL.8]
0040129F  |.  31F6            XOR     ESI,ESI
004012A1 >|>  90              NOP                             ;  <INVOKE DispatchMessage>
004012A2  |.  53              PUSH    EBX                     ; /pMsg
004012A3  |.  FF15 FE204000   CALL    [4020FE]                ; \DispatchMessageA
004012A9 >|.  90              NOP                             ;  <ICALL GetMessage>
004012AA  |.  56              PUSH    ESI                     ; /MsgFilterMax
004012AB  |.  56              PUSH    ESI                     ; |MsgFilterMin
004012AC  |.  56              PUSH    ESI                     ; |hWnd
004012AD  |.  53              PUSH    EBX                     ; |pMsg
004012AE  |.  FF15 06214000   CALL    [402106]                ; \GetMessageA
004012B4 >|.  85C0            TEST    EAX,EAX                 ;  <.until>
004012B6  |.^ 75 E9           JNZ     SHORT 004012A1          ;  <<INVOKE DispatchMessage>>
004012B8  |.  E8 43FDFFFF     CALL    00401000                ;  <CALL  Sub_null>
004012BD  |.  C9              LEAVE
004012BE  \.  C3              RETN
    
Post 10 May 2005, 16:16
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.

Powered by rwasa.