flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > One more interface syntax for fasm1

Author
Thread Post new topic Reply to topic
ProMiNick



Joined: 24 Mar 2012
Posts: 728
Location: Russian Federation, Sochi
ProMiNick 16 Jan 2019, 14:34
Syntax applicable not only for using interfaces but for their designing too.

for example x32bit (helper part):
Code:
sizeof.PTR =4
struc PTR [value:?] { common . dd value }
macro PTR [value:?] { common dd value }    


for test we also needed to include original GUID macro (but in form of struc not macro):
Code:
struc GUID data {
    .:
    local ?s
    match d1-d2-d3-d4-d5,data \{
        dd 0x\#d1
        dw 0x\#d2,0x\#d3
        db 0x\#d4 shr 8,0x\#d4 and 0FFh
        db 0x\#d5 shr 40,0x\#d5 shr 32 and 0FFh,0x\#d5 shr 24 and 0FFh,0x\#d5 shr 16 and 0FFh,0x\#d5 shr 8 and 0FFh,0x\#d5 and 0FFh
      ?s equ \}
    match =?s,?s \{ error GUID incorrect syntax \} }    


interface macros itself (architecture & bitness independent):
(Idea donor for that macro was struct macro but not original interface macro)
Code:
macro interface name
 { virtual at 0
   define @vtbl
   method@vtbl equ name
   match child =extends parent, name \{ restore method@vtbl
                               method@vtbl equ child,methods@\#parent \}

   struc stdmethod args& \{ define method@vtbl . \}

   macro GUID ID& \{ define @guid ID
                     purge GUID \} }

macro endi
 { restruc stdmethod
   irpv methods,method@vtbl \{ restore method@vtbl
                                \common define methods@vtbl methods \}
   match name tail,methods@vtbl, \{ if $
                                      display 'Error: definition of ',\`name,' contains illegal instructions.',0Dh,0Ah
                                      err
                                      end if \}
   match name=,methods,methods@vtbl \{ match =@guid,@guid \\{
                                         display 'Error: missing GUID in definition of ',\`name,0Dh,0Ah
                                         err \\}
                                        define IID_\#name @guid
                                        restore @vtbl, @guid
                                        define@vtbl name,methods
                                        define methods@\#name methods \}
   end virtual }

macro define@vtbl name,[method]
 { common
    virtual
    db `name
    load initial@vtbl byte from 0
    if initial@vtbl <> 'I'
    display 'Error: name of interface should begin with a "I".',0Dh,0Ah
    err
    end if
    end virtual
   forward
    name#.#method PTR ?
    local value
   common
    name#.com.interface = $ / sizeof.PTR

    restruc name
    struc name vtbl:? \{
      common
        . PTR vtbl
        virtual at 0
      forward
          .\#method PTR ?
      common
          .\#\.com.object = name#.com.interface
        end virtual

      \}

    restruc name#vtbl
    struc name#vtbl value \{ \local \..base
        label \..base
      forward
        .\#method PTR value
      common
        label . at \..base
      \}
 }    


and test it:
Code:
interface IUnknown
  GUID           00000000-0000-0000-C000-000000000046

  QueryInterface stdmethod(IUnknown *This, const IID *const riid, void **ppvObject)
  AddRef         stdmethod(IUnknown *This)
  Release        stdmethod(IUnknown *This)
endi

interface IClassFactory extends IUnknown
  GUID           00000001-0000-0000-C000-000000000046
  CreateInstance stdmethod(IClassFactory *THIS, IUnknown *pUnkOuter, const IID *const riid, void **ppvObject)
  LockServer     stdmethod(IClassFactory *THIS, BOOL fLock)
endi

A  IUnknown             vt
B  IClassFactory        vt
vt IClassFactoryvtbl    My.QueryInterface,My.AddRef,My.Release,My.CreateInstance,My.LockServer

lpIID_IUnknown      GUID IID_IUnknown                           ; struc GUID required here, dosn`t required for testing rest
lpIID_IClassFactory GUID 00000001-0000-0000-C000-000000000046   ; struc GUID required here, dosn`t required for testing rest

NOT_IMPLEMENTED = $80400000

My.QueryInterface:
        mov     eax,NOT_IMPLEMENTED
        ret     12

My.AddRef:
        mov     eax,NOT_IMPLEMENTED
        ret     4

My.Release:
        mov     eax,NOT_IMPLEMENTED
        ret     4

My.CreateInstance:
        mov     eax,NOT_IMPLEMENTED
        ret     16

My.LockServer:
        mov     eax,NOT_IMPLEMENTED
        ret     8                          

_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.
Post 16 Jan 2019, 14:34
View user's profile Send private message Send e-mail Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 728
Location: Russian Federation, Sochi
ProMiNick 17 Jan 2019, 09:40
offtopic: for defining signextended constants in crossbit form:
Code:
_x64 equ (-$80000000) or
NOT_IMPLEMENTED = _x64($80400000)
dd NOT_IMPLEMENTED ; $80400000 no error
dq NOT_IMPLEMENTED  ; $FFFFFFFF80400000

;or that could be even more readable
_$FFFFFFFF equ (-$80000000) or
NOT_IMPLEMENTED = _$FFFFFFFF($80400000) ; looks very beauty for eye no comment needed)
dd NOT_IMPLEMENTED ; $80400000 no error
dq NOT_IMPLEMENTED  ; $FFFFFFFF80400000
    
Post 17 Jan 2019, 09:40
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19254
Location: In your JS exploiting you and your system
revolution 17 Jan 2019, 09:50
If we remove the unneeded brackets and rename it to something more descriptive, then it looks nicer to me. And it is easier to type.
Code:
high_bits = -0x80000000
NOT_IMPLEMENTED = high_bits or 0x80400000    
Post 17 Jan 2019, 09:50
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 728
Location: Russian Federation, Sochi
ProMiNick 17 Jan 2019, 10:06
revolution, things that looks ABSOLUTELY nicer - not perfect: nobody cancel operation order - without brackets you got -(0x80000000 or 0x80400000) = $7FC00000 - that isn`t that value that you needed.
my variant is compromise of as much as possible of readability and workability.
Post 17 Jan 2019, 10:06
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 19254
Location: In your JS exploiting you and your system
revolution 17 Jan 2019, 10:30
ProMiNick wrote:
nobody cancel operation order - without brackets you got -(0x80000000 or 0x80400000) = $7FC00000 - that isn`t that value that you needed.
I used "=" not "equ" so the negative value is baked into the variable and doesn't affect the operation order.
Post 17 Jan 2019, 10:30
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-2023, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.