Log in

View Full Version : How to force data into a specific PE section?


Clandestiny
April 7th, 2005, 09:11
Hi,

I'm not quite sure which forum this question belongs on, but as its more of a programming related question I posted it here: Admins feel free to move it if its off topic.

Ok, here goes:
I want to force some global data into a specific section in the PE file I'm compiling. By default, it is allocated inline in the .text section which is not what I need. I have examined both the linker and compiler flags but have been unable to find exactly what I'm looking for. Maybe I'm overlooking something?

Thanks,
Clandestiny

Clandestiny
April 7th, 2005, 09:45
Well, I guess I answered my own question with a bit more research. In case anyone else is curious about the answer too, it is to use the #pragma directive.

#pragma data_seg(".special"

//all data delcarations down here go into the "special" section.

Cheers,
Clandestiny

PS. Admins feel free to delete this thread.

blabberer
April 7th, 2005, 11:12
what is the language you are using ?? with masm i can say how to create a section
with some specified name and give it specific charecteristics

all you have to do is make another .code section and give it your name like

.code bullshit
db "hello you are my new crap ",0

then with link you specify an option like this

\masm32\bin\Link /section:bullshit,ERW

and assemble it that is all

your new section will be created like this

Memory map, item 14
Address=00402000
Size=00001000 (4096.)
Owner=v8 00400000
Section=bullshit
Type=Imag 01001002
Access=R
Initial access=RWE



00402000 68 65 6C 6C 6F 20 79 6F 75 20 61 72 65 20 6D 79 hello you are my
00402010 20 6E 65 77 20 63 72 61 70 20 00 00 00 00 00 00 new crap ......

oops you answerd your q before me anyway may be it is usefull may be not let admins decide
Quote:

004001D0 62 75 6C 6C>ASCII "bullshit" ; SECTION
004001D8 1B000000 DD 0000001B ; VirtualSize = 1B (27.)
004001DC 00200000 DD 00002000 ; VirtualAddress = 2000
004001E0 00020000 DD 00000200 ; SizeOfRawData = 200 (512.)
004001E4 00080000 DD 00000800 ; PointerToRawData = 800
004001E8 00000000 DD 00000000 ; PointerToRelocations = 0
004001EC 00000000 DD 00000000 ; PointerToLineNumbers = 0
004001F0 0000 DW 0000 ; NumberOfRelocations = 0
004001F2 0000 DW 0000 ; NumberOfLineNumbers = 0
004001F4 200000E0 DD E0000020 ; Characteristics = CODE|EXECUTE|READ|WRITE

Clandestiny
April 7th, 2005, 13:06
Hi blabberer,

I'm writing this in C, but I occasionally use MASM as well. Its good to know how to do in both languages. Thanks for the information.

Cheers,
Clandestiny

doug
April 7th, 2005, 15:36
check this thread for more info:
http://www.woodmann.com/forum/showthread.php?t=6175&highlight=.org

bilbo
April 8th, 2005, 03:31
Quote:
[Originally Posted by Clandestiny]By default, it is allocated inline in the .text section which is not what I need.

Global data in the .text section ??

Quote:
[Originally Posted by Clandestiny]all data delcarations down here go into the "special" section.

As far as you assign them (e.g. "int aaa = 0;" and not just "int aaa;"

I'm talking about M$VC
Regards, bilbo

Clandestiny
April 8th, 2005, 09:32
Hi all and thanks for the informative replies...

To Bilbo: This is a driver and I'm using the DDK build utility to compile it. Maybe I wasn't real clear, but there are some strings that get allocated in the .text section and I need to make sure they stay in the .data section (ie. I need to keep data out of the code section). The #pragma seems to be doing exactly what I need although I've filed the MASM and other info away for future reference

Cheers,
Clandestiny