flat assembler
Message board for the users of flat assembler.

Index > Windows > 32bit readfile access invalid.

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20454
Location: In your JS exploiting you and your system
revolution 08 Mar 2024, 22:01
Furs wrote:
revolution wrote:
Tomasz can't help you here, even if Tomasz wanted to make changes to do what you wanted, it isn't possible. The PE format doesn't support setting arbitrary address for each section.
I'm obviously missing the context, because I'm pretty sure they have a start address...?
Only works for the entire exe base adress. Each section has no individual setting.
Post 08 Mar 2024, 22:01
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1850
Roman 09 Mar 2024, 08:50
Because I thinked org set Start address for all section.
But org valid only to Start code.
This is confused!

And in documentation not sayed about org and any section.
And User thinked org work for all section the same.


Last edited by Roman on 09 Mar 2024, 11:53; edited 1 time in total
Post 09 Mar 2024, 08:50
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1850
Roman 09 Mar 2024, 09:00
Code:
section '.bss' readable writeable
org 0x2349340 
 Guff    rb 37_000_000
section '. bss' readable writeable
gltf_names = 60000
;size from gltfMapKeyNamesOfst  to gltflvlDataEnd 36 080 008 bytes as file size
gltfMapKeyNamesOfst      rd 1
gltfMapKeyNames          rb 64*gltf_names  
gltflvlData              rd 8000000 
gltflvlDataCountrOfst    rd 1
gltflvlDataCountr        rd 1*gltf_names
gltflvlDataEnd:
        Status           rd      51200
    

This code work good for readfile(to gltfMapKeyNamesOfst ) normal load file size 36 080 008

Second bss section data start at 274D000h
First bss section start at 0x2349340

Guff Start address 0x2349340

I try readfile in Guff and now file load normal without errors !
Now this code work as i expected.

If this code:
Code:
section '.bss' readable writeable
org 0x500000 
 Guff    rb 35_000_000
section '. bss' readable writeable
gltf_names = 60000
;size from gltfMapKeyNamesOfst  to gltflvlDataEnd 36 080 008 bytes as file size
gltfMapKeyNamesOfst      rd 1
gltfMapKeyNames          rb 64*gltf_names  
gltflvlData              rd 8000000 
gltflvlDataCountrOfst    rd 1
gltflvlDataCountr        rd 1*gltf_names
gltflvlDataEnd:
        Status           rd      51200
    

Second bss section data start at 404000h
First bss section start at 500000h

Guff Start address 500000h and Guff cross data from second bss section.
Readfile load normal file to Guff without errors.
Post 09 Mar 2024, 09:00
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4075
Location: vpcmpistri
bitRAKE 09 Mar 2024, 17:23
I understand the confusion earlier assemblers did use ORG that way, but fasm is too complex. Try this example:
Code:
db 0
org $-1
db 1    
fasm does not assemble at the address of ORG.

What your trying to do is very fragile. If it did work, it would break in obscure ways that are difficult to debug.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 09 Mar 2024, 17:23
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20454
Location: In your JS exploiting you and your system
revolution 09 Mar 2024, 17:55
bitRAKE wrote:
What your trying to do is very fragile.
It is more than just fragile, it is completely wrong.

Roman:
The code doesn't work. It merely "works" due to coincidence and luck. To prove this try changing the values used in org. Using other values makes it crash. Which means the org there is useless and harmful. Don't use it.
Post 09 Mar 2024, 17:55
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2568
Furs 09 Mar 2024, 20:27
revolution wrote:
Furs wrote:
revolution wrote:
Tomasz can't help you here, even if Tomasz wanted to make changes to do what you wanted, it isn't possible. The PE format doesn't support setting arbitrary address for each section.
I'm obviously missing the context, because I'm pretty sure they have a start address...?
Only works for the entire exe base adress. Each section has no individual setting.
What do you mean? Sections have the VirtualAddress field in the PE format.

https://learn.microsoft.com/en-us/windows/win32/debug/pe-format
Post 09 Mar 2024, 20:27
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1043
Location: Russia
macomics 09 Mar 2024, 21:03
Furs wrote:
What do you mean?

https://learn.microsoft.com/en-us/windows/win32/debug/pe-format wrote:
For executable images, the address of the first byte of the section relative to the image base when the section is loaded into memory.
This means that you can control the position of the section only relative to the beginning of the image. Whereas org sets an absolute address, which also depends on ImageBase. But ImageBase is also not a constant value.
Post 09 Mar 2024, 21:03
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 09 Mar 2024, 21:22
A more relevant detail in PE specification is this one:
https://learn.microsoft.com/en-us/windows/win32/debug/pe-format wrote:
In an image file, the VAs for sections must be assigned by the linker so that they are in ascending order and adjacent, and they must be a multiple of the SectionAlignment value in the optional header.
There really isn't much freedom there.
Post 09 Mar 2024, 21:22
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20454
Location: In your JS exploiting you and your system
revolution 10 Mar 2024, 02:29
And just in case anyone was still doubtful that using org has any effect on the exe output.
Code:
~ cat orgtest.asm 
format pe gui

section '1' data readable
org MY_ORG
db 0
~ for ORG in 10 20 30 ; do fasm orgtest.asm -d MY_ORG=$ORG orgtest.$ORG ; done
flat assembler  version 1.73.31  (16384 kilobytes memory)
1 passes, 1024 bytes.
flat assembler  version 1.73.31  (16384 kilobytes memory)
1 passes, 1024 bytes.
flat assembler  version 1.73.31  (16384 kilobytes memory)
1 passes, 1024 bytes.
~ diff <(hd orgtest.10) <(hd orgtest.20)
~ diff <(hd orgtest.10) <(hd orgtest.30)
~     
No change in the output. Using org makes no difference to the exe generation. The only thing that changes is the internal addresses that fasm uses when referencing labels defined in the sections.
Post 10 Mar 2024, 02:29
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:  
Goto page Previous  1, 2

< 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.