News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

How to create a section from compiler/Linker?

Started by x64Core, September 28, 2012, 12:22:20 PM

Previous topic - Next topic

x64Core

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

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.
MREAL macros - when you need floating point arithmetic while assembling!

hutch--

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.

japheth

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



johnparker29

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.