flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Heap > [SELF SOLVED] New style for interfaces

Author
Thread Post new topic Reply to topic
ProMiNick



Joined: 24 Mar 2012
Posts: 144
Location: Russian Federation, Sochi

[SELF SOLVED] New style for interfaces

early I goes wrong way, so cleanup whole post. And share results:

new syntax for interfaces (not breaching old syntax but extends it in readability way)
however I make little change in old declaration to allow define value pointed to vtbl - it usefull only for PE that are comservers. (Because I still don`t cancelled from idea to write comserver in fasm).

Code:
macro interface name,[proc]
 { common
    struc name vtable\{
    \local vtbl
    match ,vtable \\{ vtbl equ ? \\}
    match any,vtable \\{ vtbl equ vtable \\}
    match , @struct \\{ define field@struct .,name,vtbl \\}
    match no@struct \\{ . dd vtbl
    virtual at 0
   forward
    .#proc dd ?
   common
    .\#\\.com.object = name#.com.interface
    end virtual \\} \}
    virtual at 0
   forward
     name#.#proc dd ?
   common
     name#.com.interface = $ shr 2
    end virtual }

macro decl@interface child,parent {
  child#@stdmethods equ
  match any,parent \{ child#@stdmethods equ parent#@stdmethods \}

  macro GUID data \{
    \local ?s
    match d1-d2-d3-d4-d5,data \\{
      struc IID_#child \\\{
        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 \\} \}

  macro stdmethod name,[args] \{ \common child#@stdmethods equ child#@stdmethods,name \}

  macro endi \{
    if $
      error illegal instruction
    end if
    end virtual
    match =, procs,child#@stdmethods \\{ interface child,procs \\}
    purge endi,stdmethod,GUID
  \}

  virtual at 0
}

macro DeclareInterface definition {
common
  local ?s
  define @interface definition
  match child =extends parent,definition \{ decl@interface child,parent
                                            ?s equ \}
  match =?s ifc?s definition \{ decl@interface definition \}
}



than use of macros:
1) use case in old style (there is unsupported interface extension from ancestor to childs), so I use some ugly name for it

Code:
interface IUnknown2,QueryInterface,AddRef,Release

pUnk IUnknown2 



2) use case in my new style

Code:
DeclareInterface IUnknown
  GUID 00000000-0000-0000-C000-000000000046
  stdmethod QueryInterfaceTHISREFIID riidvoid** ppvObj
  stdmethod AddRefTHIS
  stdmethod ReleaseTHIS
endi

DeclareInterface IClassFactory extends IUnknown
  GUID 00000001-0000-0000-C000-000000000046
  stdmethod CreateInstanceTHISIUnknown *pUnkOuterREFIID riidvoid** ppvObj
  stdmethod LockServerTHISBOOL fLock
endi

pCF IClassFactory 22



3) use case in my 2nd new style (my 2nd style is a bit ugly than my 1st, but it is a bit faster, I dislike that one, but you free to use any of them)


Code:
decl@interface IClassFactory2,IClassFactory
  GUID B196B28F-BAB4-101A-B69C-00AA00341D07
  stdmethod CreateInstanceLicTHISIUnknown *pUnkOuterIUnknown *pUnkReservedREFIID riidBSTR bstrKeyPVOID *ppvObj
  stdmethod GetLicInfoTHISLICINFO *pLicInfo
  stdmethod RequestLicKeyTHISDWORD dwReservedBSTR  *pBstrKey
endi



And you free to mix all styles (I have all upper parts of code in a single file).
NOTE: After name of stdmethod can be almost anything (params are ignored in my version of stdmethod - you can extend it). You can skip params to decrease file size, or you can use count of params instead of params, or declare params in any syntax.
NOTE: There is only one limit: Interface declared in old style cause error if it used as ancestor for other interfaces. Interface declared in old style can`t be used as descendant because of absence descending in it.

_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.


Last edited by ProMiNick on 25 Jan 2018, 23:11; edited 2 times in total
Post 25 Jan 2018, 00:21
View user's profile Send private message Send e-mail Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 144
Location: Russian Federation, Sochi

I got some strange behavior: if I split code between different includes it stop working.

I mean not all of tests passed.

test3 should fail because using interface without methods it is ubnormal behavior, but all other tests normally should be passed.

Is it a bug of my macros? or fasm bug?


Description:
Filesize: 62.7 KB
Viewed: 177 Time(s)

Безымянный.jpg


Description:
Download
Filename: test.zip
Filesize: 8.98 KB
Downloaded: 12 Time(s)


_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.
Post 25 Jan 2018, 14:25
View user's profile Send private message Send e-mail 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 can attach files in this forum
You can download files in this forum


Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2018, Tomasz Grysztar.
Powered by rwasa.