接下来的内容来源于对该博客文章http://www.pediy.com/kssd/pediy06/pediy7006.htm的解析。

一、打印Sections信息。下面的程序打印出Windows_Graphics_Programming 1.1中第三个程序“Hello World Version 3:Create a Full-Screen Window"生成的可执行文件的Sections结构字节的信息

 #include<stdio.h>
#include<windows.h> char *strPath="C:/c1_hwv3/Debug/c1_hwv3.exe"; int main()
{
IMAGE_DOS_HEADER myDosHeader;
LONG e_lfanew;
FILE *pFile;
pFile=fopen(strPath,"rb+"); fread(&myDosHeader,sizeof(IMAGE_DOS_HEADER),,pFile);
e_lfanew=myDosHeader.e_lfanew; IMAGE_FILE_HEADER myFileHeader;
int nSectionCount; fseek(pFile,(e_lfanew+sizeof(DWORD)),SEEK_SET);
fread(&myFileHeader,sizeof(IMAGE_FILE_HEADER),,pFile);
nSectionCount=myFileHeader.NumberOfSections; IMAGE_SECTION_HEADER *pmySectionHeader=
(IMAGE_SECTION_HEADER *)calloc(nSectionCount,sizeof(IMAGE_SECTION_HEADER));
fseek(pFile,(e_lfanew+sizeof(IMAGE_NT_HEADERS)),SEEK_SET);
fread(pmySectionHeader,sizeof(IMAGE_SECTION_HEADER),nSectionCount,pFile); for(int i=;i<nSectionCount;i++,pmySectionHeader++)
{
printf("Name: %s\n", pmySectionHeader->Name);
printf("union_PhysicalAddress: %08x\n", pmySectionHeader->Misc.PhysicalAddress);
printf("union_VirtualSize: %04x\n", pmySectionHeader->Misc.VirtualSize);
printf("VirtualAddress: %08x\n", pmySectionHeader->VirtualAddress);
printf("SizeOfRawData: %08x\n", pmySectionHeader->SizeOfRawData);
printf("PointerToRawData: %04x\n", pmySectionHeader->PointerToRawData);
printf("PointerToRelocations: %04x\n", pmySectionHeader->PointerToRelocations);
printf("PointerToLinenumbers: %04x\n", pmySectionHeader->PointerToLinenumbers);
printf("NumberOfRelocations: %04x\n", pmySectionHeader->NumberOfRelocations);
printf("NumberOfLinenumbers: %04x\n", pmySectionHeader->NumberOfLinenumbers);
printf("Charateristics: %04x\n", pmySectionHeader->Characteristics);
}
// pmySectionHeader-=m_nSectionCount; if(pmySectionHeader!=NULL)
{
free(pmySectionHeader);
pmySectionHeader=NULL;
} fclose(pFile);
return ;
}

运行程序打印出如下信息

Name: .text

union_PhysicalAddress: 00022350

union_VirtualSize: 22350

VirtualAddress: 00001000

SizeOfRawData: 00023000

PointerToRawData: 1000

PointerToRelocations: 0000

PointerToLinenumbers: 0000

NumberOfRelocations: 0000

NumberOfLinenumbers: 0000

Charateristics: 60000020

Name: .rdata

union_PhysicalAddress: 00001615

union_VirtualSize: 1615

VirtualAddress: 00024000

SizeOfRawData: 00002000

PointerToRawData: 24000

PointerToRelocations: 0000

PointerToLinenumbers: 0000

NumberOfRelocations: 0000

NumberOfLinenumbers: 0000

Charateristics: 40000040

Name: .data

union_PhysicalAddress: 00005650

union_VirtualSize: 5650

VirtualAddress: 00026000

SizeOfRawData: 00004000

PointerToRawData: 26000

PointerToRelocations: 0000

PointerToLinenumbers: 0000

NumberOfRelocations: 0000

NumberOfLinenumbers: 0000

Charateristics: c0000040

Name: .idata

union_PhysicalAddress: 00000b23

union_VirtualSize: 0b23

VirtualAddress: 0002c000

SizeOfRawData: 00001000

PointerToRawData: 2a000

PointerToRelocations: 0000

PointerToLinenumbers: 0000

NumberOfRelocations: 0000

NumberOfLinenumbers: 0000

Charateristics: c0000040

Name: .reloc

union_PhysicalAddress: 00000f00

union_VirtualSize: 0f00

VirtualAddress: 0002d000

SizeOfRawData: 00001000

PointerToRawData: 2b000

PointerToRelocations: 0000

PointerToLinenumbers: 0000

NumberOfRelocations: 0000

NumberOfLinenumbers: 0000

Charateristics: 42000040

pe文件结构图:

C语言读取PE文件信息(一)的更多相关文章

  1. c# .Net :Excel NPOI导入导出操作教程之读取Excel文件信息及输出

    c# .Net :Excel NPOI导入导出操作教程之读取Excel文件信息及输出 using NPOI.HSSF.UserModel;using NPOI.SS.UserModel;using S ...

  2. Java读取txt文件信息并操作。

    一.java读取txt文件内容 import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.Fi ...

  3. C/C++语言读取SEGY文件(二)

    SEGY IO (2D) 本文档将介绍SEGY的读取与写入过程,即SEGY文件的复制,并且在实现过程采用采样点×道数二维数组的形式读写. 新建头文件SegyDataIO2D.h与C++文件SegyDa ...

  4. R语言读取excel文件的3种方法

    R读取excel文件中数据的方法: 电脑有一个excel文件,原始的文件路径是:E:\R workshop\mydata\biom excel数据为5乘2阶矩阵,元素为                ...

  5. Python读取PE文件(exe/dll)中的时间戳

    代码原文地址: https://www.snip2code.com/Snippet/144008/Read-the-PE-Timestamp-from-a-Windows-Exe https://gi ...

  6. Configutation读取properties文件信息

    commons configuration可以很方便的访问配置文件和xml文件中的的内容.Commons Configuration 是为了提供对属性文件.XML文件.JNDI资源.来自JDBC Da ...

  7. springboot配置文件读取pom文件信息

    解决的问题 springboot(当然别的也可以)多环境切换需要该配置文件,打包时不够方便. 解决: 配置文件能读取pom文件中的配置,根据命令选择不同配置注入springboot的配置文件中 pom ...

  8. C/C++语言读取SEGY文件笔记(一)

    SEGY IO 推荐采用的IDE为Visual studio(VS),本文档将介绍SEGY文件的读取与写入过程,即SEGY文件的复制. 因此,新建头文件ReadSeismic.h与C++文件ReadS ...

  9. PE文件信息获取工具-PEINFO

    能实现基本的信息获取 区段信息 数据目录信息 导入表函数分析 导出表函数分析,能同时解析只序号导出和以函数名序号同时导出的函数 FLC计算 需要源码的可以留邮箱.

随机推荐

  1. 在Oracle中使用Entity Framework 6 CodeFirst

    项目中需要将系统从SQLServer数据库迁移到Oracle上.由于原大部分数据访问操作都是通过包装了Entity Framework的统一访问入口实现的,所以需要研究Entity Framework ...

  2. IOS开发 - TextField 控件详细

    //初始化textfield并设置位置及大小 UITextField *text = [[UITextField alloc]initWithFrame:CGRectMake(20, 20, 130, ...

  3. uva 213 Message Decoding

    思路来自紫书...开始时的思路估计100行+,果断放弃!关键:1.正确提取出函数!   initmap():初始化字母与整数的映射.   returnint(x):向后读取x位,并转换为十进制数返回. ...

  4. Struts2配置文件详解

    解决在断网环境下,配置文件无提示的问题我们可以看到Struts.xml在断网的情况下,前面有一个叹号,这时,我们按alt+/ 没有提示,这是因为” http://struts.apache.org/d ...

  5. 一个简单的游戏开发框架(四.舞台Stage)

    首先是StageManager类: class StageManager : public Singleton<StageManager> { friend class Singleton ...

  6. JSP内置对象---request对象(用户登录页面(setAttribute))

    在上节 request.jsp 中 添加脚本语句: <% request.setAttribute("password", "123456"); %> ...

  7. HPL/SQL与CDH5.4.7集成

    1.下载hplsql-0.3.13到本地并解压 2.修改plsql,为如下内容 #!/bin/bash export "HADOOP_CLASSPATH=/opt/cloudera/parc ...

  8. 事件(event),正则

    1.事件(event):事件是可以被 JavaScript 侦测到的行为.网页中的每个元素都可以产生某些可以触发 JavaScript 函数的事件.2.事件源: 触发事件的元素 事件: 被 JavaS ...

  9. 如何让UIView中的Button点击之后跳转到另一个ViewController上去,ViewController上也有一个按钮 可以返回

    第一种方法:如果使用导航第一个按钮方法:[self.navigationController pushViewController:secondVC animated:YES];第二个按钮方法:[se ...

  10. css 中content内容特殊形状

    用到的一些特殊字符和图标html代码<div class="cross"></div>css代码.cross{    width: 20px;    hei ...