flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > value out of range with load/store

Author
Thread Post new topic Reply to topic
macomics



Joined: 26 Jan 2021
Posts: 1108
Location: Russia
macomics 15 Apr 2025, 15:09
I'm reserving space for the data.
Code:
virtual at 0
    target_data_buffer::
end virtual
target_label: db target_data_size dup 0xFF    

Then a virtual is generated in my postpone macro. After that, I want to copy the block from virtual to my data buffer.
Code:
postpone { virtual target_data_buffer
        db 'Some text strings', 0
        target_data_size = $ - $$
    end virtual
    repeat target_data_size
        load a byte from target_data_buffer : ( % - 1 )
        store byte a at target_label + % - 1
    end repeat
}    
But I get the error
Code:
$ fasm MAIN.ASM
flat assembler  version 1.73.32  (16384 kilobytes memory, x64)
MAIN.ASM [20]:

MAIN.ASM [13] postpone [6]:
        store byte a at target_label + % - 1
processed: store byte a at target_label+%-1
error: value out of range.    

And now I don't understand where I went beyond. The value in a is a byte and should definitely not go out. The position for copying data must be exactly in the buffer.

Full source
Code:
format PE64 GUI 6.0
section '.data' data readable writeable
virtual at 0
    target_data_buffer::
end virtual
target_label: db target_data_size dup 0xFF
postpone { virtual target_data_buffer
        db 'Some text strings', 0
        target_data_size = $ - $$
    end virtual
    repeat target_data_size
        load a byte from target_data_buffer : ( % - 1 )
        store byte a at target_label + % - 1
    end repeat
}

section '.text' code readable executable
entry $
        retn
    
Post 15 Apr 2025, 15:09
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20582
Location: In your JS exploiting you and your system
revolution 15 Apr 2025, 15:15
The postpone is compiled within the last section of the code But the target_label is in the first section.

load and store can't access bytes in another section.

BTW: I turned off smileys in the post to avoid the corruption of the code.
Post 15 Apr 2025, 15:15
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1108
Location: Russia
macomics 15 Apr 2025, 15:21
Thanks

Code:
format PE64 GUI 6.0
section '.data' data readable writeable
virtual at 0
    target_data_buffer::
end virtual
target_label: db target_data_size dup 0xFF
macro display_hex@digit digit { if (digit) and 15 < 10
        display (digit) and 15 + '0'
    else
        display (digit) and 15 - 10 + 'A'
    end if
}
macro display_hex [val] { forward match v=:h, val \{ rept h n:1 \\{ display_hex@digit (v) shr (4 * ( h - n )) \\} \}
        display ' ' }
postpone { virtual target_data_buffer
        db 'Some text strings', 0
        target_data_size = $ - $$
    end virtual
    repeat target_data_size
        load a byte from target_data_bufferSad % - 1 )
        display_hex target_label+%-1:8, a:2
        display a, 13, 10
        store byte a at target_label + % - 1
    end repeat
}

section '.text' code readable executable
entry $
        retn
    

Code:
$ fasm MAIN.ASM
flat assembler  version 1.73.32  (16384 kilobytes memory, x64)
00401000 53 S
00401001 6F o
00401002 6D m
00401003 65 e
00401004 20  
00401005 74 t
00401006 65 e
00401007 78 x
00401008 74 t
00401009 20  
0040100A 73 s
0040100B 74 t
0040100C 72 r
0040100D 69 i
0040100E 6E n
0040100F 67 g
00401010 73 s
00401011 00 
MAIN.ASM [30]:

MAIN.ASM [23] postpone [8]:
        store byte a at target_label + % - 1
processed: store byte a at target_label+%-1
error: value out of range.    


That's what confused me a bit. It's strange that he typed everything and got an error. If the error had appeared after the first iteration, then everything would have been much clearer.


Last edited by macomics on 15 Apr 2025, 15:24; edited 1 time in total
Post 15 Apr 2025, 15:21
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20582
Location: In your JS exploiting you and your system
revolution 15 Apr 2025, 15:23
Simplified code:
Code:
format PE64 GUI 6.0
section '.data' data readable writeable
v: db 0
load a byte from v      ; okay
section '.text' code readable executable
load b byte from v      ; fails    
Post 15 Apr 2025, 15:23
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1108
Location: Russia
macomics 15 Apr 2025, 15:35
Then it might be worth replacing the error message in this case with "Outside the section". Just thinking out loud. I'll think about such a patch.
Post 15 Apr 2025, 15:35
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.