flat assembler
Message board for the users of flat assembler.

Index > Main > Set offset of members in struct?

Author
Thread Post new topic Reply to topic
MUFOS



Joined: 17 Apr 2016
Posts: 47
MUFOS
Hello there,

I was wondering if it's possible to set the offsets of the members of a struct.

This could be useful when I have an array inside the struct.

For instance:

Code:
struct SomeStruct
SomeArray dd ? (on runtime, it will be allocated 10*4 (10 dwords))
SomeOtherValue dd 0
ends
 ; When accessing the value of SomeOtherValue when it's in a register, I would do something like:

mov edx, [eax + SomeStruct.SomeOtherValue] ;However, it will not work since it is an array. The structure has been created by allocating memory (40 + 4 bytes).

;Would it be possible to do something like:
struct SomeStruct
SomeArray dd ?
offset 40 SomeOtherValue dd 0 ;Set the offset of the value.
ends    
Post 13 May 2016, 14:28
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17331
Location: In your JS exploiting you and your system
revolution
Just use RB:
Code:
struct SomeStruct
SomeArray dd ?
rb 40
SomeOtherValue dd 0
ends    
Or:
Code:
struct SomeStruct
SomeArray rd 11
SomeOtherValue dd 0
ends    
Post 13 May 2016, 14:30
View user's profile Send private message Visit poster's website Reply with quote
MUFOS



Joined: 17 Apr 2016
Posts: 47
MUFOS
I may be picky, but doesn't this mean the program size would be +40 bytes?

You see I never assign struct on compiletime, so is there any way to do it without adding the extra bytes?
Post 13 May 2016, 14:50
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17331
Location: In your JS exploiting you and your system
revolution
It depends upon how you allocate the structure. If you statically add it within your code section, or within the initialised data then it will take up space in the exe file. But you can put it at the end of the data into the uninitialised portion and it won't take up any space in the exe file.
Post 13 May 2016, 15:19
View user's profile Send private message Visit poster's website Reply with quote
MUFOS



Joined: 17 Apr 2016
Posts: 47
MUFOS
revolution wrote:
It depends upon how you allocate the structure. If you statically add it within your code section, or within the initialised data then it will take up space in the exe file. But you can put it at the end of the data into the uninitialised portion and it won't take up any space in the exe file.


I would like to allocate it on runtime using the heap.
Can you show me an example of uninitialized data?
Post 13 May 2016, 15:29
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17331
Location: In your JS exploiting you and your system
revolution
What OS are you using? What file format?
Post 13 May 2016, 23:35
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.