Reading notes, section of Pe File and Pragma Command

xiaoxiao2021-03-06  20

The Following Table Shows Some of The More Common Section Names and Explains Each Section's Purpose.

Section NamePurpose.bssUninitialized data.CRTRead-only C run-time data.dataInitialized data.debugDebugging information.didataDelay imported names table.edataExported names table.idataImported names table.rdataRead-only run-time data.relocRelocation table information.rsrcResources.text. Exe's or dll's code.tlsthread-local storage.xdataException Handling Table

In addition to the standard sections create by the compiler and the linker

#pragma data_seg ("Sectionname")

So, For Example, I Can Create a Section Called "Shared" That Contains a Single Long Value, As Follows:

#pragma data_seg ("Shared")

Long g_linstancecount = 0;

#pragma data_seg ()

When the compiler compiles this code, it creates a new section called Shared and places all the initialized data variables that it sees after the pragma in this new section. In the example above, the variable is placed in the Shared section. Following the variable, the #pragma dataseg () line tells the compiler to stop putting initialized variables in the Shared section and to start putting them back in the default data section. It is extremely important to remember that the compiler will store only initialized variables in the new section. For Example, I Had Removed The Initialization from The Previous Code Fragment (As Shown In The Following Code)

#pragma data_seg ("Shared")

Long g_linstancecount;

#pragma data_seg ()

The Microsoft Visual C 6.0 compiler offers an allocate declaration specifier, however, that does allow you to place uninitialized data in any section you desire Take a look at the following code:. ************** *********************************************************** *********** // CREATE Shared Section & Have Compiler Place Initialized Data IN IT.

#pragma data_seg ("Shared")

// Initialized, in Shared Section

INT A = 0;

// uninitialized, not in shared section

INT B;

// Have Compiler Stop Placing Initialized Data In Shared Section.

#pragma data_seg ()

// Initialized, in Shared Section

_Declspec (allocate ("shared")) INT C = 0;

// uninitialized, in shared section

_Declspec (Allocate ("Shared")) INT D;

// Initialized, Not in Shared Section

INT E = 0;

// uninitialized, not in shared section

INT f; ***************************************************** *********************************************************** ***********

- From

#pragma Directives - Excerpt from MSDN LIBRARY

Each implementation of C and C supports some features unique to its host machine or operating system. Some programs, for instance, need to exercise precise control over the memory areas where data is placed or to control the way certain functions receive parameters. The #pragma directives offer a way for each compiler to offer machine- and operating system-specific features while retaining overall compatibility with the C and C languages. Pragmas are machine- or operating system-specific by definition, and are usually different for every compiler.

Pragmas can be used in conditional statements, to provide new preprocessor functionality, or to provide implementation-defined information to the compiler The Microsoft C and C compilers recognize the following pragmas:. Alloc_textauto_inlinebss_segcheck_stackcode_segcommentcomponentconform1const_segdata_segdeprecatedfunctionhdrstopinclude_aliasinit_seg1inline_depthinline_recursionintrinsicmanagedmessageonceoptimizepackpointers_to_members1pop_macropush_macroruntime_checkssectionsetlocaleunmanagedvtordisp1warning

1. Supported Only by the C Compiler.

#pragma token-string

The token-string is a series of characters that gives a specific compiler instruction and arguments, if any The number sign (#) must be the first non-white-space character on the line containing the pragma;. White-space characters can separate The Number Sign and The Word Pragma. Following #pragma, Write Any Text That The Translator CAN Parse As PrePragma Is Subject To Macro Expansion.

IF The Compiler Finds a Pragma It Does Not Recognize, ItsSues A Warning, But CompiLation Continues.

Some pragmas provide the same functionality as compiler options. When a pragma is encountered in source code, it overrides the behavior specified by the compiler option. For example, if you specified tabindex = "0" keywords = "_ core_.2f.Zp"> / ZP8, You Can Override this Compiler Setting for Specific Portions of the code with pack:

CL / ZP8 ...

- Packing IS 8

// ...

#pragma Pack (Push, 1) - Packing is now 1

// ...

#pragma pack (POP) - Packing IS 8

转载请注明原文地址:https://www.9cbs.com/read-43880.html

New Post(0)