Author Topic: Sections  (Read 3363 times)

0 Members and 1 Guest are viewing this topic.

Offline staticgerbil

  • Atari ST
  • ***
  • Posts: 113
  • Karma: 8
    • View Profile
Sections
« on: February 25, 2011 »
Time for my first stupid question :D

After reading a bunch of FASM examples and some of their docs, the first thing that jumps out at me is the "section" command.

I'm seeing a lot of different sections like .flat .code .data .data? .rdata .text but I've found nothing about sections in any of the FASM docs and searching for anything with "sections" in it on the net is pretty useless.

Previously I think I've just taken some example code, gutted it and added my code to it so I've just kind of made my own meanings up for the sections that I started with.

So finally to the questions...

Are there specific sections that have specific meanings and usages?  If so do some have dependancies on other sections?  Do you have a list of them and what they are for?

Are these sections purely up to the user to create with whatever name and permissions they want?  Eg. could I just have section 'staticgerbilsstuff' and give it read / write / execute permissions and plonk the whole program in?

I've noticed that some examples didn't appear to have a section at all.  Is there a default section that you are in until you specify otherwise?

Offline va!n

  • Pentium
  • *****
  • Posts: 1432
  • Karma: 109
    • View Profile
    • http://www.secretly.de
Re: Sections
« Reply #1 on: February 25, 2011 »
@staticgerbil:
Any windows exe has x numbers of sections! The type of sections is very important, due fact we dont want mix code with data, so we have sections! There are ways to merge sections but that is another topic.

Sections are part of each windows PE header! Just google for Win32 PE headers and filealignments to get deeper into what sections are and how they are working.

Maybe this is a first start and helps a bit:

http://marcoramilli.blogspot.com/2010/12/windows-pe-header.html

http://www.deinmeister.de/w32asm5.htm Website by T$ (german)

http://board.flatassembler.net/topic.php?p=38190

At least just check out the great fasm forum where you will find a lot of informations and examples.


[Edited - Added:]
http://www.daniweb.com/code/snippet216722.html


http://win32assembly.online.fr/pe-tut1.html
http://win32assembly.online.fr/pe-tut2.html
http://win32assembly.online.fr/pe-tut3.html
http://win32assembly.online.fr/pe-tut4.html
http://win32assembly.online.fr/pe-tut5.html
http://win32assembly.online.fr/pe-tut6.html
http://win32assembly.online.fr/pe-tut7.html
« Last Edit: February 25, 2011 by va!n »
- hp EliteBook 8540p, 4 GB RAM, Windows 8.1 x64
- Asus P5Q, Intel Q8200, 6 GB DDR2, Radeon 4870, Windows 8.1 x64
http://www.secretly.de
Challenge Trophies Won:

Offline rain_storm

  • Here comes the Rain
  • DBF Aficionado
  • ******
  • Posts: 3088
  • Karma: 182
  • Rain never hurt nobody
    • View Profile
    • org_100h
Re: Sections
« Reply #2 on: February 25, 2011 »
sections are used by the OS to map the executable into memory sections can be read, write, executable or any combination of them. some sections can contain import/export data but dont let the ".idata" section names fool you, any section that is read/write (even if it's also executable) can be used to store the import table. export tables require only that the section they are placed in be readable. obviously code must be placed in an executable section. the ".flat" section is the default in FASM it is a single section which has all priveledges enabled. it can be used for data, code, import tables, export tables etc.

One nice advantage of sections is that if the section is very large but mostly filled up with uninitialized arrays. Those zeros do not need to be written to file, The section only needs to span the size of the initialized data. When the OS loads the file into RAM it allocates enough memory to store the section and the memory is initialized to zero. This is excellent news for size coding.

As Va!n pointed out sections are specific to the Portable Executable file format.

Challenge Trophies Won:

Offline staticgerbil

  • Atari ST
  • ***
  • Posts: 113
  • Karma: 8
    • View Profile
Re: Sections
« Reply #3 on: February 25, 2011 »
Thanks for the links and info guys :)

I'll get some reading done over the weekend and see if I can get a window with some GDI going on!