flat assembler
Message board for the users of flat assembler.

Index > Main > The problem of Struct

Author
Thread Post new topic Reply to topic
mzabcdefgchina



Joined: 14 Jan 2015
Posts: 10
mzabcdefgchina
I define the following structure:(我定义了以下的结构:)
Code:
OVERRIDE struct
        lpszParam               dd ?
        lpszRetType             dd ?
OVERRIDE ends
TOOLTIP struct
        lpszType                dd ?
        lpszLine                dd ?
        lpszApi                 dd ?
        nPos                    dd ?
        novr                    dd ?
        ovr                             OVERRIDE 32 dup(<>)
TOOLTIP ends
    


In the process of compiling the following tips:(在编译的过程中出现了以下提示:)

fasm "代码测试.asm"
flat assembler version 1.71.24 (1391975 KB 内存)
结构.inc [37]:
TOOLTIP ends
O:\Fasm\Include/macro\MASM.INC [9] ends [0]:
{ match =.,name@struct \{ ends \} }
O:\Fasm\Include/macro\MASM.INC [9] match [0]:
{ match =.,name@struct \{ ends \} }
O:\Fasm\Include/macro\struct.inc [68] ends [12]:
make@struct name,fields
O:\Fasm\Include/macro\struct.inc [68] match [12]:
make@struct name,fields
O:\Fasm\Include/macro\struct.inc [68] match [1]:
make@struct name,fields
O:\Fasm\Include/macro\struct.inc [86] make@struct [9]:
match fields, define \{ define@struct fields \} }
O:\Fasm\Include/macro\struct.inc [86] match [0]:
match fields, define \{ define@struct fields \} }
O:\Fasm\Include/macro\struct.inc [103] define@struct [14]:
sizeof.#name#field = $ - name#field
error: undefined symbol(未定义符号) 'TOOLTIP.ovr'.

发生错误。

I know that there is a problem,(我知道是以下这一句出的问题,)
Code:
        ovr                             OVERRIDE 32 dup(<>)
    

how to write macro to identify this expression?(怎样来编写macro来识别这一句?)
Post 11 Jan 2016, 02:15
View user's profile Send private message Reply with quote
mzabcdefgchina



Joined: 14 Jan 2015
Posts: 10
mzabcdefgchina
我想把喜欢Fasm编程的中国朋友都约到一起,大家共同讨论,共同研究,共同进步,QQ群:328681673(我爱编程)
Post 11 Jan 2016, 06:39
View user's profile Send private message Reply with quote
fasmnewbie



Joined: 01 Mar 2011
Posts: 553
fasmnewbie
mzabcdefgchina wrote:
我想把喜欢Fasm编程的中国朋友都约到一起,大家共同讨论,共同研究,共同进步,QQ群:328681673(我爱编程)


I don't know what to say. hehehe xD
Post 11 Jan 2016, 07:38
View user's profile Send private message Visit poster's website Reply with quote
jiangfasm



Joined: 08 Mar 2015
Posts: 58
jiangfasm
mzabcdefgchina wrote:
I define the following structure:(我定义了以下的结构:)
Code:
OVERRIDE struct
        lpszParam               dd ?
        lpszRetType             dd ?
OVERRIDE ends
TOOLTIP struct
        lpszType                dd ?
        lpszLine                dd ?
        lpszApi                 dd ?
        nPos                    dd ?
        novr                    dd ?
        ovr                             OVERRIDE 32 dup(<>)
TOOLTIP ends
    


In the process of compiling the following tips:(在编译的过程中出现了以下提示:)

fasm "代码测试.asm"
flat assembler version 1.71.24 (1391975 KB 内存)
结构.inc [37]:
TOOLTIP ends
O:\Fasm\Include/macro\MASM.INC [9] ends [0]:
{ match =.,name@struct \{ ends \} }
O:\Fasm\Include/macro\MASM.INC [9] match [0]:
{ match =.,name@struct \{ ends \} }
O:\Fasm\Include/macro\struct.inc [68] ends [12]:
make@struct name,fields
O:\Fasm\Include/macro\struct.inc [68] match [12]:
make@struct name,fields
O:\Fasm\Include/macro\struct.inc [68] match [1]:
make@struct name,fields
O:\Fasm\Include/macro\struct.inc [86] make@struct [9]:
match fields, define \{ define@struct fields \} }
O:\Fasm\Include/macro\struct.inc [86] match [0]:
match fields, define \{ define@struct fields \} }
O:\Fasm\Include/macro\struct.inc [103] define@struct [14]:
sizeof.#name#field = $ - name#field
error: undefined symbol(未定义符号) 'TOOLTIP.ovr'.

发生错误。

I know that there is a problem,(我知道是以下这一句出的问题,)
Code:
        ovr                             OVERRIDE 32 dup(<>)
    

how to write macro to identify this expression?(怎样来编写macro来识别这一句?)


你应该这样写:
Code:
struct OVERRIDE
        lpszParam   dd ?
        lpszRetType dd ?
ends
struct TOOLTIP
        lpszType    dd ?
        lpszLine    dd ?
        lpszApi     dd ?
        nPos        dd ?
        novr        dd ?
        union
            ovr     OVERRIDE
            rb      sizeof.OVERRIDE*32
        ends
ends
    


用的时候
Code:
tooltip TOOLTIP
mov eax,[tooltip.ovr.lpszParam + sizeof.OVERRIDE*???]
    
Post 11 Jan 2016, 12:58
View user's profile Send private message Visit poster's website Reply with quote
jiangfasm



Joined: 08 Mar 2015
Posts: 58
jiangfasm
fasmnewbie wrote:
mzabcdefgchina wrote:
我想把喜欢Fasm编程的中国朋友都约到一起,大家共同讨论,共同研究,共同进步,QQ群:328681673(我爱编程)


I don't know what to say. hehehe xD


We come from China, he is a Chinese friend! QQ is a social software in China, equivalent to Facebook
Post 11 Jan 2016, 13:10
View user's profile Send private message Visit poster's website Reply with quote
jiangfasm



Joined: 08 Mar 2015
Posts: 58
jiangfasm
To compile the following statement
ovr OVERRIDE 32 dup(<>)

Code:
macro define@struct name,[field,type,def]
 { common
    virtual
     db `name
     load initial@struct byte from 0
     if initial@struct = '.'
      display 'Error: name of structure should not begin with a dot.',0Dh,0Ah
      err
     end if
    end virtual
    local list
    list equ
   forward
    if ~ field eq .
     name#field type def
     sizeof.#name#field = $ - name#field
    else
     label name#.#type
     rb sizeof.#type
    end if
    local value
    match any, list \{ list equ list, \}
    list equ list <value>
   common
    local count@struc,dup@struc
    sizeof.#name = $
    restruc name
    match values, list \{
     struc name value \\{ \\local \\..base
       match , @struct \\\{ define field@struct .,name,<values> \\\}
       match no, @struct \\\{ label \\..base
        define dup@struc
        match cnt=dup, value \\\\{
         restore dup@struc
         define dup@struc TRUE
         count@struc = cnt \\\\}
        match cnt=dup any, value \\\\{
         restore dup@struc
         define dup@struc TRUE
         count@struc = cnt \\\\}
        match =TRUE, dup@struc \\\\{ rb sizeof.#name*count@struc \\\\}
        match , dup@struc \\\\{
   forward
         match , value \\\\\{ field type def \\\\\}
         match any, value \\\\\{ field type value
          if ~ field eq .
           rb sizeof.#name#field - ($-field)
          end if \\\\\}
   common \\\\} restore dup@struc
      label . at \\..base \\\}\\}
     macro name value \\{
     match , @struct \\\{ \\\local anonymous
                                  define field@struct anonymous,name,<values> \\\}
     match no, @struct \\\{
      define dup@struc
      match cnt=dup, value \\\\{
       restore dup@struc
       define dup@struc TRUE
       count@struc = cnt \\\\}
      match cnt=dup any, value \\\\{
       restore dup@struc
       define dup@struc TRUE
       count@struc = cnt \\\\}
      match =TRUE, dup@struc \\\\{ rb sizeof.#name*count@struc \\\\}
      match , dup@struc \\\\{
   forward
       match , value \\\\\{ type def \\\\\}
       match any, value \\\\\{ \\\\\local ..field
        ..field = $
        type value
        if ~ field eq .
         rb sizeof.#name#field - ($-..field)
        end if \\\\\}
   common \\\\} restore dup@struc \\\} \\} irpv lists,list \{ restore list \} \} }
    


Description:
Download
Filename: struct.inc
Filesize: 8.19 KB
Downloaded: 259 Time(s)



Last edited by jiangfasm on 19 Jan 2016, 14:56; edited 3 times in total
Post 19 Jan 2016, 14:10
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: 17272
Location: In your JS exploiting you and your system
revolution
Your diff shows no changes except for some indenting differences and the addition of the last six lines. Is that deliberate?
Post 19 Jan 2016, 14:21
View user's profile Send private message Visit poster's website Reply with quote
jiangfasm



Joined: 08 Mar 2015
Posts: 58
jiangfasm
revolution wrote:
Your diff shows no changes except for some indenting differences and the addition of the last six lines. Is that deliberate?


No, I'm sorry, command me wrong, I was too careless
Post 19 Jan 2016, 14:47
View user's profile Send private message Visit poster's website Reply with quote
jiangfasm



Joined: 08 Mar 2015
Posts: 58
jiangfasm
jiangfasm wrote:
To compile the following statement
ovr OVERRIDE 32 dup(<>)

Code:
macro define@struct name,[field,type,def]
 { common
    virtual
     db `name
     load initial@struct byte from 0
     if initial@struct = '.'
      display 'Error: name of structure should not begin with a dot.',0Dh,0Ah
      err
     end if
    end virtual
    local list
    list equ
   forward
    if ~ field eq .
     name#field type def
     sizeof.#name#field = $ - name#field
    else
     label name#.#type
     rb sizeof.#type
    end if
    local value
    match any, list \{ list equ list, \}
    list equ list <value>
   common
    local count@struc,dup@struc
    sizeof.#name = $
    restruc name
    match values, list \{
     struc name value \\{ \\local \\..base
       match , @struct \\\{ define field@struct .,name,<values> \\\}
       match no, @struct \\\{ label \\..base
        define dup@struc
        match cnt=dup, value \\\\{
         restore dup@struc
         define dup@struc TRUE
         count@struc = cnt \\\\}
        match cnt=dup any, value \\\\{
         restore dup@struc
         define dup@struc TRUE
         count@struc = cnt \\\\}
        match =TRUE, dup@struc \\\\{ rb sizeof.#name*count@struc \\\\}
        match , dup@struc \\\\{
   forward
         match , value \\\\\{ field type def \\\\\}
         match any, value \\\\\{ field type value
          if ~ field eq .
           rb sizeof.#name#field - ($-field)
          end if \\\\\}
   common \\\\} restore dup@struc
      label . at \\..base \\\}\\}
     macro name value \\{
     match , @struct \\\{ \\\local anonymous
                                  define field@struct anonymous,name,<values> \\\}
     match no, @struct \\\{
      define dup@struc
      match cnt=dup, value \\\\{
       restore dup@struc
       define dup@struc TRUE
       count@struc = cnt \\\\}
      match cnt=dup any, value \\\\{
       restore dup@struc
       define dup@struc TRUE
       count@struc = cnt \\\\}
      match =TRUE, dup@struc \\\\{ rb sizeof.#name*count@struc \\\\}
      match , dup@struc \\\\{
   forward
       match , value \\\\\{ type def \\\\\}
       match any, value \\\\\{ \\\\\local ..field
        ..field = $
        type value
        if ~ field eq .
         rb sizeof.#name#field - ($-..field)
        end if \\\\\}
   common \\\\} restore dup@struc \\\} \\} irpv lists,list \{ restore list \} \} }
    


Fixed some bug

Code:
--------------------------- include/macro/struct.inc ---------------------------
index 31350a8..f36eafe 100644
@@ -125,7 +125,9 @@ macro define@struct name,[field,type,def]
          restore dup@struc
          define dup@struc TRUE
          count@struc = cnt \\\\}
-        match =TRUE, dup@struc \\\\{ rb sizeof.#name*count@struc \\\\}
+        match =TRUE, dup@struc \\\\{
+   forward field type def
+   common rb sizeof.#name*(count@struc-1) \\\\}
         match , dup@struc \\\\{
    forward
          match , value \\\\\{ field type def \\\\\}
@@ -134,7 +136,7 @@ macro define@struct name,[field,type,def]
            rb sizeof.#name#field - ($-field)
           end if \\\\\}
    common \\\\} restore dup@struc
-      label . at \\..base \\\}\\}
+     label . at \\..base \\\}\\}
      macro name value \\{
      match , @struct \\\{ \\\local anonymous
                                  define field@struct anonymous,name,<values> \\\}
    


test!!!

Code:
include 'macro/struct.inc'

struct AAA
x db ?
y db ?
ends

struct AAA1
x db ?
y AAA ?
AAA ?
y1 AAA 2 dup
ends

pint1 AAA 66,67
db 3
pint2 AAA 2 dup ()
db 3
db pint1.x
db pint2.x
db 3
db AAA.y
db 3
AAA 4,5
AAA 2 dup ()
db 3

pint3 AAA1 67,68
db 4
AAA1 67,68
db 4
AAA1 2 dup
db 4
db pint3.y.y
db 4
    


output:
Quote:

jiang@jiang:~/tst$ fasm hello.asm
flat assembler version 1.71.49 (2097152 kilobytes memory)
1 passes, 61 bytes.
jiang@jiang:~/tst$ hexdump -C hello.bin
00000000 42 43 03 00 00 00 00 03 00 03 03 01 03 04 05 00 |BC..............|
00000010 00 00 00 03 43 44 00 00 00 00 00 00 00 04 43 44 |....CD........CD|
00000020 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 00 |................|
00000030 00 00 00 00 00 00 00 00 00 00 04 16 04 |.............|
0000003d
jiang@jiang:~/tst$


There should be no problem!


Description:
Download
Filename: struct.inc
Filesize: 8.23 KB
Downloaded: 267 Time(s)

Post 20 Jan 2016, 12:32
View user's profile Send private message Visit poster's website Reply with quote
mzabcdefgchina



Joined: 14 Jan 2015
Posts: 10
mzabcdefgchina
Thank you very much!
Post 23 Jan 2016, 01:43
View user's profile Send private message Reply with quote
l4m2



Joined: 15 Jan 2015
Posts: 648
l4m2
mzabcdefgchina wrote:
我想把喜欢Fasm编程的中国朋友都约到一起,大家共同讨论,共同研究,共同进步,QQ群:328681673(我爱编程)
Post the number in the Heap as a new topic so it will be more easily found instead of being found only when go into a question
Post 25 Aug 2016, 10:38
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.