flat assembler
Message board for the users of flat assembler.

Index > Projects and Ideas > model for structured data rendering

Author
Thread Post new topic Reply to topic
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 19 Nov 2024, 11:57
a test to get a model convenient for structrured data render and edition at runtime/debug/binary analysis and so on.

Code:
macro _type length,name {
        dd length
        db name,0
}

macro _field type,name {
        dd type
        db name,0
}

_int equ 0x0
_float equ 0x1000
_strz equ 0x2000        ;null ending string
_strs equ 0x4000        ;sized string
_ptr equ 0x8000         ;pointers
_fooltype equ 0xF0000000;fool model type


_null:  _type 0,'null'
_bit:   _type 1,'bit'
_nibble:_type 4,'nibble'
_byte:  _type 8,'byte'
_word:  _type 16,'word'
_dword: _type 32,'dword'
_qword: _type 64,'qword'
_tword: _type 80,'tword'
_dqword:_type 128,'dqword'
_f16:   _type _float+16,'f16'
_f32:   _type _float+32,'f32'
_f64:   _type _float+64,'f64'
_f80:   _type _float+80,'f80'

_ptr1:    _type _ptr+1,'ptr1'
_ptr4:    _type _ptr+4,'ptr4'
_ptr8:    _type _ptr+8,'ptr8'
_ptr16:   _type _ptr+16,'ptr16'
_ptr32:   _type _ptr+32,'ptr32'
_ptr64:   _type _ptr+64,'ptr64'
_ptr128:  _type _ptr+128,'ptr128'
_ptrf16:  _type _ptr+_float+16,'ptrf16'
_ptrf32:  _type _ptr+_float+32,'ptrf32'
_ptrf64:  _type _ptr+_float+64,'ptrf64'
_ptrf80:  _type _ptr+_float+80,'ptrf80'


_string:_type _strz+8,'string'
_bits:  _type _strs+1,'bitfield'
_ustr:  _type _strz+16,'ustring'
_list:  _type _strs+32,'list'

_0 equ _null
_1 equ _bit
_4 equ _nibble
_8 equ _byte
_16 equ _word
_32 equ _dword
_64 equ _qword
_128 equ _dqword

macro _model name,[field] {
common
 local .a,.n
.n:
       db name,0
.a:
forward
       dd field
       dd $-.a
       dd .n
common
}

_f:     _field _ptr32,'func'
_x:     _field _dword,'x'
_y:     _field _dword,'y'
_xl:    _field _dword,'xl'
_yl:    _field _dword,'yl'
_color8:_field _byte,'color8'
_color16:_field _word,'color16'
_color32:_field _dword,'color32'
_size:  _field _dword,'size'
_data:  _field _dword,'data'
_txtptr: _field _ptr8,'txtptr'
_bmptr: _field _ptr8,'bmptr'
_bmptr32: _field _ptr32,'bmptr32'

_2d equ _x,_y,_xl,_yl
_graphix equ _2d,_color32

_model 'node',_f,_list
_model 'gnode',_f,_2d,_list
_model 'box',_f,_graphix
_model 'frame',_f,_graphix
_model 'circle',_f,_graphix
_model 'border',_f,_graphix
_model 'folder',_f,_txtptr,_list
_model 'bmptr32',_f,_graphix,_ptr32
    


not mature at all, but may be used also for any structure (not only fool), stack frames, etc...
Post 19 Nov 2024, 11:57
View user's profile Send private message Visit poster's website Reply with quote
edfed



Joined: 20 Feb 2006
Posts: 4353
Location: Now
edfed 09 Dec 2024, 13:15
Code:
CRLF equ 13,10

return equ

virtual as 'log'
  LOG::
end virtual

macro log str& {
  virtual LOG
   db str
  end virtual
}

macro log.bit b{
}

macro log.nibble n{
d='0'+n and 0fh
if d>'9'
d=d+7
end if
log d
}

macro log.byte b{
log.nibble ((b shr 4) and 0fh)
log.nibble (b and 0fh)
}

macro log.word w{
log.byte ((w shr 8) and 0ffh)
log.byte (w and 0ffh)
}

macro log.dword d{
log.word ((d shr 16) and 0ffffh)
log.word (d and 0ffffh)
}


macro _type length,name {
        log.dword $
        log ':'
        dd length
        db name,0
        log name,' '
        log.dword length
        log CRLF
}

macro _field type,name {
        log.dword $
        log ':'
        dd type
        db name,0
        log name,' '
        log.dword type
        log CRLF
}

macro _model name,[field] {
common
        log.dword $
        log ':'
 local .a,.n,.s
.n:
        db name,0
        log name,' '
.a:
forward
        dd field
common
.s = $-.a
        dd .s
        dd .n
repeat (.s)/4
load a dword from .a+(%-1)*4
        log.dword a
        log ' '
end repeat

        log.dword .s

        log CRLF
}

_int    equ 0x0
_float  equ 0x1000
_strz   equ 0x2000        ;null ending string
_strs   equ 0x4000        ;sized string
_ptr equ 0x8000         ;pointers
_fooltype equ 0xF0000000;fool model type

_null:  _type 0,'null'
_bit:   _type 1,'bit'
_nibble:_type 4,'nibble'
_byte:  _type 8,'byte'
_word:  _type 16,'word'
_dword: _type 32,'dword'
_qword: _type 64,'qword'
_tword: _type 80,'tword'
_dqword:_type 128,'dqword'

_f16:   _type _float+16,'f16'
_f32:   _type _float+32,'f32'
_f64:   _type _float+64,'f64'
_f80:   _type _float+80,'f80'

_ptr1:    _type _ptr+1,'ptr1'
_ptr4:    _type _ptr+4,'ptr4'
_ptr8:    _type _ptr+8,'ptr8'
_ptr16:   _type _ptr+16,'ptr16'
_ptr32:   _type _ptr+32,'ptr32'
_ptr64:   _type _ptr+64,'ptr64'
_ptr128:  _type _ptr+128,'ptr128'
_ptrf16:  _type _ptr+_float+16,'ptrf16'
_ptrf32:  _type _ptr+_float+32,'ptrf32'
_ptrf64:  _type _ptr+_float+64,'ptrf64'
_ptrf80:  _type _ptr+_float+80,'ptrf80'

_string:_type _strz+8,'string'
_bits:  _type _strs+1,'bitfield'
_ustr:  _type _strz+16,'ustring'
_list:  _type _strs+32,'list'

_0 equ _null
_1 equ _bit
_4 equ _nibble
_8 equ _byte
_16 equ _word
_32 equ _dword
_64 equ _qword
_128 equ _dqword

_f:     _field _ptr32,'func'
_x:     _field _dword,'x'
_y:     _field _dword,'y'
_xl:    _field _dword,'xl'
_yl:    _field _dword,'yl'
_color8:_field _byte,'color8'
_color16:_field _word,'color16'
_color24:_field _dword,'color24'
_color32:_field _dword,'color32'
_size:  _field _dword,'size'
_data:  _field _dword,'data'
_txtptr: _field _ptr8,'txtptr'
_bmptr: _field _ptr8,'bmptr'
_bmptr32: _field _ptr32,'bmptr32'

_2d equ _x,_y,_xl,_yl
_list32 equ _size,_data
_graphix equ _2d,_color32


_node:    _model 'node',_f,_list32
_gnode:   _model 'gnode',_f,_2d,_list32
_box:     _model 'box',_f,_2d,_color32
_frame:   _model 'frame',_f,_2d,_color32
_circle:  _model 'circle',_f,_2d,_color32
_border:  _model 'border',_f,_2d,_color32
_older:   _model 'folder',_f,_txtptr,_list32
_bmptr_32:_model 'bmptr32',_f,_graphix,_bmptr32


render.model:
.call=0
.model=4

        ret

render.field:

    

much better, it generates this log:

Code:
00000000:null 00000000
00000009:bit 00000001
00000011:nibble 00000004
0000001C:byte 00000008
00000025:word 00000010
0000002E:dword 00000020
00000038:qword 00000040
00000042:tword 00000050
0000004C:dqword 00000080
00000057:f16 10001010
0000005F:f32 10001020
00000067:f64 10001040
0000006F:f80 10001050
00000077:ptr1 80008001
00000080:ptr4 80008004
00000089:ptr8 80008008
00000092:ptr16 80008010
0000009C:ptr32 80008020
000000A6:ptr64 80008040
000000B0:ptr128 80008080
000000BB:ptrf16 90009010
000000C6:ptrf32 90009020
000000D1:ptrf64 90009040
000000DC:ptrf80 90009050
000000E7:string 20002008
000000F2:bitfield 40004001
000000FF:ustring 20002010
0000010B:list 40004020
00000114:func 0000009C
0000011D:x 0000002E
00000123:y 0000002E
00000129:xl 0000002E
00000130:yl 0000002E
00000137:color8 0000001C
00000142:color16 00000025
0000014E:color24 0000002E
0000015A:color32 0000002E
00000166:size 0000002E
0000016F:data 0000002E
00000178:txtptr 00000089
00000183:bmptr 00000089
0000018D:bmptr32 0000009C
00000199:node 00000114 00000166 0000016F 0000000C
000001B2:gnode 00000114 0000011D 00000123 00000129 00000130 00000166 0000016F 0000001C
000001DC:box 00000114 0000011D 00000123 00000129 00000130 0000015A 00000018
00000200:frame 00000114 0000011D 00000123 00000129 00000130 0000015A 00000018
00000226:circle 00000114 0000011D 00000123 00000129 00000130 0000015A 00000018
0000024D:border 00000114 0000011D 00000123 00000129 00000130 0000015A 00000018
00000274:folder 00000114 00000178 00000166 0000016F 00000010
00000293:bmptr32 00000114 0000011D 00000123 00000129 00000130 0000015A 0000018D 0000001C
    


next step, render this as editable forms, when in edit mode. Smile
Post 09 Dec 2024, 13:15
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.