flat assembler
Message board for the users of flat assembler.

Index > Main > Local struc on stack

Author
Thread Post new topic Reply to topic
donn



Joined: 05 Mar 2010
Posts: 321
donn 10 Aug 2016, 15:34
Hi, is there an equivalent to:

Code:
label .localValue dword at ebp-4
    


for strucs? I tried some variations but will keep trying. Instead of placing a new struc on the heap, was aiming to place a disposable one on the stack. With each call to the same function, it could then use the same struc layout, but on its own stack. This sounds preferable to using a single global struc address.

Was referencing vid's post here: http://board.flatassembler.net/topic.php?t=12066&postdays=0&postorder=asc&start=20

Thanks a bunch.
Post 10 Aug 2016, 15:34
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20344
Location: In your JS exploiting you and your system
revolution 10 Aug 2016, 15:38
The short answer is, yes. But it depends upon what you are doing. Are you using the Windows "struct" macros? Or something else. Post some code snippets of your function definitions to give us something to work with.
Post 10 Aug 2016, 15:38
View user's profile Send private message Visit poster's website Reply with quote
donn



Joined: 05 Mar 2010
Posts: 321
donn 10 Aug 2016, 15:55
Unfortunately, I do not have an up to date version of the function I was working on here. It was something like this:

Code:
        struc ListItem{
                .item dd 0
                .previous dd 0
                .next dd 0
                .itemSize dd 0
                .endListItemAddress dd 0
        }

        ; Used with address offsets
        virtual at 0
                ListItem ListItem
        end virtual
    



Code:
;------------
;   Inserts item at the current position index.
;   Updates list item count, item previous and next addresses, etc.
;   Takes List address, item address as parameters
;------------
newNextItem:
        push ebp
        mov ebp, esp
        ;Need to sub esp locals at some point...?

        mov ecx, [ebp+8]
        mov edx, [ebp+12]
        label .listAddress dword at ebp-4
        label .newItemAddress dword at ebp-8
        label .afterNewItemAddress dword at ebp-12
        label .hHeap dword at ebp-16
        label .hAllocatedMemory dword at ebp-20
        label .newListItem ListItem at ebp-24 ;?

        
        push ebx esi edi

        mov [newNextItem.listAddress], ecx
        mov [newNextItem.newItemAddress], edx
    


So I have been using the non-Windows strucs so far. They seem to work for what I have needed.

Appreciated!
Post 10 Aug 2016, 15:55
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20344
Location: In your JS exploiting you and your system
revolution 10 Aug 2016, 16:14
Okay, so in that case within your function you can use:
Code:
virtual at ebp-stackSize
  .localStruc1 MyStruc1
  .localStruc2 MyStruc2
end virtual    
Post 10 Aug 2016, 16:14
View user's profile Send private message Visit poster's website Reply with quote
donn



Joined: 05 Mar 2010
Posts: 321
donn 10 Aug 2016, 18:48
OK, I think this needs a little more testing but the function results I am currently seeing are correct. Here's how I started it based on what you said:

Code:
;------------
;   Inserts item at the current position index.
;   Updates list item count, item previous and next addresses, etc.
;   Takes List address, item address as parameters
;------------
newNextItem:
        push ebp 
        mov ebp, esp 
        sub esp, ((4*6)+(4*5))

        mov ecx, [ebp+8] 
        mov edx, [ebp+12] 
        label .listAddress dword at ebp-4 
        label .newItemAddress dword at ebp-8 
        label .afterNewItemAddress dword at ebp-12
        label .beforeNewItemAddress dword at ebp-16 
        label .hHeap dword at ebp-20 
        label .hAllocatedMemory dword at ebp-24 
        virtual at ebp-44
                .newListItem ListItem
        end virtual



        push ebx esi edi

        mov [newNextItem.listAddress], ecx
        mov [newNextItem.newItemAddress], edx
    


It was working yesterday with one function call (inserting one List Item), but a second call wiped out the original List contents. Have other functions which append items to the end and an untested remove function, but they use the global strucs when HeapAlloc is not needed.

Will eventually convert the globals to this new stack-local style soon and maybe eventually go the multithreading route.

Thank you for the help!
Post 10 Aug 2016, 18:48
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20344
Location: In your JS exploiting you and your system
revolution 10 Aug 2016, 18:58
You can define all your variables inside the virtual block:
Code:
virtual at ebp-something
        .listAddress            dd ?
        .newItemAddress         dd ?
        .afterNewItemAddress    dd ?
        .beforeNewItemAddress   dd ?
        .hHeap                  dd ?
        .hAllocatedMemory       dd ?
        .newListItem            ListItem
end virtual    
Post 10 Aug 2016, 18:58
View user's profile Send private message Visit poster's website Reply with quote
donn



Joined: 05 Mar 2010
Posts: 321
donn 10 Aug 2016, 20:01
That would remove the need to calculate some ebp offsets manually, good idea!
Post 10 Aug 2016, 20:01
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20344
Location: In your JS exploiting you and your system
revolution 10 Aug 2016, 20:07
You can also compute the size automatically (I didn't test this yet):
Code:
sub esp,.theSize
virtual at ebp-.theSize
        .listAddress            dd ?
        .newItemAddress         dd ?
        .afterNewItemAddress    dd ?
        .beforeNewItemAddress   dd ?
        .hHeap                  dd ?
        .hAllocatedMemory       dd ?
        .newListItem            ListItem
        .theSize = $-$$
end virtual    
Post 10 Aug 2016, 20:07
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.