Author Topic: How to create a section from compiler/Linker?  (Read 2756 times)

x64Core

  • Member
  • **
  • Posts: 80
How to create a section from compiler/Linker?
« on: September 28, 2012, 12:22:20 PM »
hey guys :D
anyone know how to create a section from the compiler/linker?
I would like to create a section with 200 bytes called "test", normally the compiler/linker creates two or three section ( text,data,imports)
but if want to create a "empty section" ( filled with zero bytes )... it's possible? thanks!

qWord

  • Member
  • *****
  • Posts: 1454
  • The base type of a type is the type itself
    • SmplMath macros
Re: How to create a section from compiler/Linker?
« Reply #1 on: September 28, 2012, 01:46:56 PM »
You can use MASM's SEGEMNT/ENDS directives. Place the following snippet somewhere in your program:
Code: [Select]
_test SEGMENT
db 200 dup (?)
_test ENDS
For more details, see MASM’s Programmer's Guide and MSDN.

Be warned, MASM sometimes get crazy, when nesting segments.
MREAL macros - when you need floating point arithmetic while assembling!

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 4812
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: How to create a section from compiler/Linker?
« Reply #2 on: September 28, 2012, 01:55:04 PM »
It also may be wise if you want to run the EXE on later OS versions to set the new section to the attribute you require, read, write, execute because if you try and execute code that is written to a section that is not marked as executable, the OS will close it down.

You can also try something like this if its code to execute,


.code
  myspace db 200 dup (0)
  start:                                ; the actual start label
  ; more code etc ....


With this you need to know the address of the "myspace" buffer. I gather you want to post patch the executable.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :biggrin:

japheth

  • Guest
Re: How to create a section from compiler/Linker?
« Reply #3 on: September 28, 2012, 05:05:05 PM »
I would like to create a section with 200 bytes called "test", normally the compiler/linker creates two or three section (

"test" is a reserved word inside the assembler. To define a section with this name you'll have to use the ALIAS attribute:

Code: [Select]
.386
.model flat
_TEST segment alias("test")
db 200h dup (?)
_TEST ends

x64Core

  • Member
  • **
  • Posts: 80
Re: How to create a section from compiler/Linker?
« Reply #4 on: September 29, 2012, 02:54:08 PM »
thanks guys, resolved  :biggrin:

johnparker29

  • Guest
Re: How to create a section from compiler/Linker?
« Reply #5 on: September 30, 2012, 11:37:19 PM »
It also may be sensible if you want to run the EXE on later OS variations to set the new area to the feature you need, study, create, perform because if you try and perform value that is published to a area that is not noticeable as exe, the OS will near it down.