Results 1 to 7 of 7

Thread: How to force data into a specific PE section?

  1. #1

    Post How to force data into a specific PE section?


    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?


  2. #2
    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.


    PS. Admins feel free to delete this thread.

  3. #3
    Super Moderator
    Join Date
    Dec 2004
    Blog Entries
    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
    Size=00001000 (4096.)
    Owner=v8 00400000
    Type=Imag 01001002
    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
    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
    Last edited by blabberer; April 7th, 2005 at 11:17.

  4. #4
    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.


  5. #5

  6. #6
    son of Bungo & Belladonna bilbo's Avatar
    Join Date
    Mar 2004
    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
    Non quia difficilia sunt, non audemus, sed quia non audemus, difficilia sunt.[Seneca, Epistulae Morales 104, 26]

  7. #7
    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


Similar Threads

  1. how to force ollydbg to load a specific udd file ?
    By Roko in forum OllyDbg Support Forums
    Replies: 5
    Last Post: February 20th, 2010, 12:47
  2. using filestreams to store data..or code as data?
    By BanMe in forum The Newbie Forum
    Replies: 7
    Last Post: August 8th, 2009, 21:58
  3. make olly treat stuff in data section as data
    By gtype in forum OllyDbg Support Forums
    Replies: 0
    Last Post: March 4th, 2009, 15:29
  4. ida misinterpreted data section as code
    By The Keeper in forum Tools of Our Trade (TOT) Messageboard
    Replies: 6
    Last Post: May 14th, 2004, 23:27
  5. How to create one section EXE from a multi section exe
    By new_age in forum The Newbie Forum
    Replies: 4
    Last Post: January 27th, 2003, 20:27


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts