读书笔记,关于pe file的section及pragma命令
来源:互联网 发布:我知女人心免费阅读 编辑:程序博客网 时间:2024/05/29 11:37
The following table shows some of the more common section names and explains each section's purpose.
In addition to the standard sections created by the compiler and the linker, you can create your own sections when you compile using the following directive:
#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, if I had removed the initialization from the previous code fragment (as shown in the following code), the compiler would have put this variable in a section other than the Shared section:
#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 sectionint a = 0; // Uninitialized, not in Shared sectionint 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 sectionint e = 0; // Uninitialized, not in Shared sectionint f;
--摘自<programming application for Microsoft Windows>
#pragma directives -- 摘自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:
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 preprocessing tokens. The argument to #pragma is subject to macro expansion.
If the compiler finds a pragma it does not recognize, it issues 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 /Zp8, you can override this compiler setting for specific portions of the code with pack:
cl /Zp8 ...<file> - packing is 8// ...#pragma pack(push, 1) - packing is now 1// ...#pragma pack(pop) - packing is 8</file>
- 读书笔记,关于pe file的section及pragma命令
- PE section 的标志位
- #pragma section
- PE File中取Section,用RVA还是用PointerToRawData?
- data section .data/.rdata of PE file(.sys)
- PE File中取Section,用RVA还是用PointerToRawData?
- PE File中取Section,用RVA还是用PointerToRawData?
- C++的global data的位置 及PE 文件中的section的内容
- STVD环境下的#pragma section 用法
- PE文件中各种Section的含义
- 关于#pragma once编译命令
- #pragma section( "section-name" [, attributes] )
- 关于#pragma warning 及warning4786
- 关于pragma的延续
- 关于#pragma的使用
- #pragma arm section说明
- #pragma arm section
- 在ARM平台上的C使用#pragma arm section
- 一个未完成的MYSQL管理程序
- [转]Asp.net中基于Forms验证的角色验证授权
- 哈哈哈哈
- 如何在jbuider2005中配置oracle数据库连接
- 引自Xinsoft的一小段话!
- 读书笔记,关于pe file的section及pragma命令
- 05年读书学习计划
- Encrypted Chat Room 1_System description and requirements
- Encrypted Chat Room 2_Use Cases
- Encrypted Chat Room 3_Design Documentation
- Encrypted Chat Room 4_Class Specifications(1)
- Encrypted Chat Room 4_Class Specifications(2)
- Encrypted Chat Room 4_Class Specifications(3)
- Encrypted Chat Room 4_Class Specifications(4)