The MASM Forum

General => The Campus => Topic started by: x64Core on September 28, 2012, 12:22:20 PM

Title: How to create a section from compiler/Linker?
Post by: x64Core 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!
Title: Re: How to create a section from compiler/Linker?
Post by: qWord on September 28, 2012, 01:46:56 PM
You can use MASM's SEGEMNT/ENDS directives. Place the following snippet somewhere in your program:
_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.
Title: Re: How to create a section from compiler/Linker?
Post by: hutch-- 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.
Title: Re: How to create a section from compiler/Linker?
Post by: japheth on September 28, 2012, 05:05:05 PM
Quote from: RHL on September 28, 2012, 12:22:20 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:


.386
.model flat
_TEST segment alias("test")
db 200h dup (?)
_TEST ends

Title: Re: How to create a section from compiler/Linker?
Post by: x64Core on September 29, 2012, 02:54:08 PM
thanks guys, resolved  :biggrin:
Title: Re: How to create a section from compiler/Linker?
Post by: johnparker29 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.