flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Fasm 1 macro fill data.

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 815
Roman
I want macro Fill.
Code:
Fill buf1, 1,7,3,44
Fill buf2, 4,5
    


Fill gen asm code:
Code:
Mov eax, buf1
Mov [eax], 1
Mov [eax+4], 7
Mov [eax+8], 3
Mov [eax+12], 44

    
Post 20 Dec 2019, 10:39
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17660
Location: In your JS exploiting you and your system
revolution
Perhaps something like this:
Code:
macro Fill address,[value] {
 common
  local i
  i = 0
  Mov eax, address
 forward
  Mov dword[eax + i], value
  i = i + 4
}    
Untested, so see if it works for you.
Post 20 Dec 2019, 11:16
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 815
Roman
Super puper Smile
Thanks.
Post 20 Dec 2019, 11:26
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 574
Location: Russian Federation, Sochi
ProMiNick
above variant not able to fill values from memory (only imm or reg) because of absence mov mem to mem instruction.
but push memory exists

macro FillByPush address, size, [value] {
common
mov eax, address
add eax,size-4
xchg eax, esp
reverse
push value
common
xchg esp, eax ; if restoring eax significant| or just mov esp, eax
add eax, 4 ; if restoring eax significant
}

but it require to precede its values by size
in large structures my variant is significantly shorter & faster, and structures size is something predefined.
Post 20 Dec 2019, 13:58
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17660
Location: In your JS exploiting you and your system
revolution
ProMiNick wrote:
above variant not able to fill values from memory (only imm or reg) because of absence mov mem to mem instruction.
but push memory exists

macro FillByPush address, size, [value] {
common
mov eax, address
add eax,size-4
xchg eax, esp
reverse
push value
common
xchg esp, eax ; if restoring eax significant| or just mov esp, eax
add eax, 4 ; if restoring eax significant
}

but it require to precede its values by size
in large structures my variant is significantly shorter & faster, and structures size is something predefined.
You can also use:
Code:
mov eax, address + size - 4    
But also note that this code is only suitable for an OS running in protected mode with multiple stacks implemented, or if you know interrupts are already disabled. Otherwise an intervening interrupt will get a bad stack.
Post 20 Dec 2019, 14:13
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 821
Location: Belarus
DimonSoft
Changing ESP to point to arbitrary places gets program into trouble almost definitely: Why do we even need to define a red zone? Can’t I just use my stack for anything?
Post 20 Dec 2019, 18:47
View user's profile Send private message Visit poster's website Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 574
Location: Russian Federation, Sochi
ProMiNick
Using stack for struct initialization (taken by me from reversing OOPs hardcoded internals) is always simpler, shorter and faster, but yes it is applicable only for protected mode with multiple stacks implemented.
But I test it even more limited - OOP use pushes to initialize object located in heap, not in stack. I test this technic only in heap too!
Post 20 Dec 2019, 22:18
View user's profile Send private message Send e-mail 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 GitHub, YouTube, Twitter.

Website powered by rwasa.