flat assembler
Message board for the users of flat assembler.

Index > Main > accessing structure fields

Author
Thread Post new topic Reply to topic
Teehee



Joined: 05 Aug 2009
Posts: 568
Location: Brazil
Teehee
im a bit confuse trying to get the value of a struct.

Code:
ONE:
  dd TWO1
  dd TWO2

TWO1:
  .type dd 1 
  .str  dd str_three
TWO2:
  .type dd 2
  .str  dd str_four

str_three db 'three',0
str_four  db 'four',0    


I need to get ONE.TWO1.str to make a string comparation, but im not reaching there! Sad i tried alot of mov/lea combinations lol but .. Sad

_________________
Sorry if bad english.
Post 28 Sep 2011, 23:47
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Code:
cld
lea esi ,[ONE]  
lodsd           
lodsd  ;esi + 4
                  ;eax = &TWO2
lea esi,[eax] ; haha, eax = TWO2
lodsd
lodsd           ;esi + 4, EAX = ONE.TWO2.str         
    


Anyone correct me if I missed something.
Post 29 Sep 2011, 00:52
View user's profile Send private message Reply with quote
Enko



Joined: 03 Apr 2007
Posts: 678
Location: Mar del Plata
Enko
you are making wrong the structures I think. You should do it upside down.

Code:
struc TWO1 flag, lpstr
{
    .type dd flag
    .str dd lpstr
}

struc TWO2 flag, lpstr
{
   .type dd flag
       .str dd lpstr
}

struc ONE t1, lpstr1, t2, lpstr2 {
      .TWO1 TWO1 t1, lpstr1
       .TWO2 TWO2 t2, lpstr2
}
     
     
str4 db 'string 4',0
str3 db 'string 3',0
szstr '%s',0

_ONE ONE 1,str3, 2, str4 ;<<<<<<<

    
section '.code' code readable executable 
start: 
     
    cinvoke printf, szstr, [_ONE.TWO1.str]
    


if you want to define an empty ONE:

Code:
theTWO ONE 0,0,0,0

section '.code' code readable executable 
start: 
        mov [theTWO.TWO1.str], str4

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

or using struct


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
struct _TWO1
        type dd ?
   str dd ?
ends

struct _TWO2
        type dd ?
   str dd ?
ends

struct ONE
  TWO1 _TWO1
  TWO2 _TWO2
ends

      
     
str4 db 'string 4',0
str3 db 'string 3',0

theTWO ONE

    
section '.code' code readable executable 
start: 
           mov [theTWO.TWO1.str], str4
        cinvoke printf, szstr, [theTWO.TWO1.str]
    
Post 29 Sep 2011, 04:09
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
Not tested but this should work:
Code:
struct MYENTRY
        type    dd ?
        str     dd ?
ends

mov eax,1                       ; Index of element to get
mov esi,dword [ONE+eax*4]       ; Pointer to element
mov esi,dword [esi+MYENTRY.str] ; Get the pointer "str" in element
; Compare esi with some other string    
Post 29 Sep 2011, 07:42
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.