flat assembler
Message board for the users of flat assembler.

Index > Windows > Idiomatic setup for win32 application

Author
Thread Post new topic Reply to topic
drobole



Joined: 03 Nov 2010
Posts: 67
Location: Norway
drobole 14 Nov 2010, 18:20
After looking at WIN32AX.INC I got the impression that a idiomatic win32 application would look something like this:

Code:
format PE console 4.0

include 'WIN32AX.INC'

all_api

.data

    ; ...
       
.code

main:

    ; ...

.end main
    


Is this how its supposed to be done?
Also, what happened to
section '.reloc' fixups data readable discardable
I cant see that line being added by the macros, still it seems to work without it
Post 14 Nov 2010, 18:20
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 14 Nov 2010, 18:24
drobole wrote:
Also, what happened to
section '.reloc' fixups data readable discardable
I cant see that line being added by the macros, still it seems to work without it
You don't really need relocs for win32 apps, since each process is given it's own virtual address space; if you stick with a sane load address, your app is guaranteed to load fine without relocs.

You might want to keep relocs, though, to take advantage of ASLR on newer windows versions.
Post 14 Nov 2010, 18:24
View user's profile Send private message Visit poster's website Reply with quote
drobole



Joined: 03 Nov 2010
Posts: 67
Location: Norway
drobole 14 Nov 2010, 18:29
f0dder wrote:
drobole wrote:
Also, what happened to
section '.reloc' fixups data readable discardable
I cant see that line being added by the macros, still it seems to work without it
You don't really need relocs for win32 apps, since each process is given it's own virtual address space; if you stick with a sane load address, your app is guaranteed to load fine without relocs.

You might want to keep relocs, though, to take advantage of ASLR on newer windows versions.


Is that to say that the process is guaranteed to reside entirely on a single virtual memory page (given a sane load address), so no relocation will be done either way?

edit:
After all that cleaning up of the framework it would be nice with a .reloc macro to get rid of that last section declaration. Not a big thing maybe, just seems intuitive
Post 14 Nov 2010, 18:29
View user's profile Send private message Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2341
Location: Usono (aka, USA)
rugxulo 15 Nov 2010, 18:12
Relocs are (I think) a relic of the past. Not sure about Win16 proper, but at least Win32s ["subset" for Win16] required 'em. So almost no PE .EXEs nowadays include 'em.
Post 15 Nov 2010, 18:12
View user's profile Send private message Visit poster's website Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 15 Nov 2010, 18:24
rugxulo wrote:
Relocs are (I think) a relic of the past. Not sure about Win16 proper, but at least Win32s ["subset" for Win16] required 'em. So almost no PE .EXEs nowadays include 'em.
They're pretty much required for DLLs, and as I mentioned you need them for ASLR as well - so definitely not a thing of the past.

_________________
Image - carpe noctem
Post 15 Nov 2010, 18:24
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 15 Nov 2010, 19:05
PE is compiled (or linked) to be loaded at appropriate virtual address (IMAGE_OPTIONAL_HEADER.ImageBase). When it can't (for main .Exe this rarely wil be the case, yet one can produce 0-based PE), base relocations are needed to adjust image so it can be loaded at different base virtual address. Consider two DLLs with the same base being loaded into the same process' VAS: first will probably load fine, second should be relocated, as its base address is already occupied.
Post 15 Nov 2010, 19:05
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.