Windows Pe 第三章 PE头文件-EX-相关编程-1(PE头内容获取)
2023-09-11 14:14:00 时间
获取pE头相关的内容,就是类似如下内容
原理:比较简单,直接读取PE到内存,然后直接强转就行了。
#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#pragma warning(disable:4996)
void viewImageFileCharacteristics(WORD);
int _tmain(int argc, TCHAR *argv[])
{
PIMAGE_DOS_HEADER pImageDosHeader;
PIMAGE_NT_HEADERS pImageNtHeaders;
PIMAGE_FILE_HEADER pImageFileHeader;
HANDLE hFile;
HANDLE hMapObject;
PUCHAR uFileMap;
//if(argc<2)
//return -1;
if(!(hFile=CreateFile(/*argv[1]*/L"c:\\hello.exe",GENERIC_READ,0,NULL,OPEN_EXISTING,0,0)))
return -1;
if (!(hMapObject=CreateFileMapping(hFile,NULL,PAGE_READONLY,0,0,NULL)))
return -1;
if(!(uFileMap=(PUCHAR)MapViewOfFile(hMapObject,FILE_MAP_READ,0,0,0)))
return -1;
pImageDosHeader=(PIMAGE_DOS_HEADER)uFileMap;
if (pImageDosHeader->e_magic != IMAGE_DOS_SIGNATURE)
return -1;
pImageNtHeaders=(PIMAGE_NT_HEADERS)((PUCHAR)uFileMap+pImageDosHeader->e_lfanew);
if (pImageNtHeaders->Signature!=IMAGE_NT_SIGNATURE)
return -1;
pImageFileHeader=(PIMAGE_FILE_HEADER) &(pImageNtHeaders->FileHeader);
printf("Machine: 0x%04X",pImageFileHeader->Machine);
((pImageFileHeader->Machine == IMAGE_FILE_MACHINE_I386)
?printf("(I386) \n")
:printf(" (?) \n"));
printf("NumberOfSections: 0x%04X\n",pImageFileHeader->NumberOfSections);
printf("TimeDateStamp: 0x%08X\n",pImageFileHeader->TimeDateStamp);
printf("PointerToSymbolTable: 0x08X\n",pImageFileHeader->PointerToSymbolTable);
printf("NumberOfSymbols: 0x%08X\n",pImageFileHeader->NumberOfSymbols);
printf("SizeOfOptionalHeader: 0x%04X\n",pImageFileHeader->SizeOfOptionalHeader);
printf("Characteristics: 0x%04X\n",pImageFileHeader->Characteristics);
viewImageFileCharacteristics(pImageFileHeader->Characteristics);
UnmapViewOfFile(uFileMap);
CloseHandle(hMapObject);
CloseHandle(hFile);
return 0;
}
void viewImageFileCharacteristics(WORD wCharacteristics)
{
char szCharacteristics[100];
memset(szCharacteristics,0,100);
szCharacteristics[0]='(';
if (wCharacteristics & 0x0001)
strcat(szCharacteristics,"RELOCS_STRIPPED|");
if (wCharacteristics & 0x0002)
strcat(szCharacteristics,"EXECUTABLE_IMAGE|");
if (wCharacteristics & 0x0004)
strcat(szCharacteristics,"LINE_NUMS_STRIPPED|");
if (wCharacteristics & 0x0100)
strcat(szCharacteristics,"32BIT_MACHINE|");
if (wCharacteristics & 0x0200)
strcat(szCharacteristics,"DEBUG_STRIPPED|");
if (wCharacteristics & 0x1000)
strcat(szCharacteristics,"FILE_SYSTEM|");
if (wCharacteristics & 0x2000)
strcat(szCharacteristics,"FILE_DLL|");
szCharacteristics[strlen(szCharacteristics)-1]=')';
szCharacteristics[strlen(szCharacteristics)]='\0';
printf(" %s\n",szCharacteristics);
}
执行结果:
相关文章
- Windows核心编程 第二十章 DLL的高级操作技术
- Windows核心编程 第十九章 DLL基础
- Windows核心编程 第十七章 -内存映射文件(下)
- Windows核心编程 第十五章 在应用程序中使用虚拟内存
- Windows PE资源表编程(枚举资源树)
- Windows PE导出表编程4(重构导出表实现私有函数导出)
- Windows核心编程 第六章 线程基础知识 (下)
- Windows核心编程 第六章 线程基础知识 (上)
- Windows核心编程 第九章 线程与内核对象的同步(上)
- Windows核心编程 第四章 进程(中)
- Windows核心编程 第三章 内核对象
- Windows核心编程 第三章 内核对象
- 使用同步或异步的方式完成 I/O 访问和操作(Windows核心编程)
- Windows核心编程笔记之作业
- Windows核心编程笔记之处理字符串
- HOW TO: Configure Internet Information Services Web Authentication in Windows Server 2003
- windows python web flask 编写 Hello World
- clover 引导无法扫描 找到windows系统解决办法
- 网络安全应急响应----2、Windows入侵排查
- 《Python数据可视化编程实战》——1.5 在Windows上安装matplotlib
- 使用 Intel Arc GPU 进行Stable Diffusion,在 Windows 上使用 PyTorch 和 Docker
- Windows上安装配置SSH教程(4)——WinSCP+OpenSSH 使用公钥自动登陆
- windows下编译firefox
- Windows server 2016无法使用RDO远程连接,win10无法用RDO远程连接
- Send email alert from Performance Monitor using PowerShell script (检测windows服务器的cpu 硬盘 服务等性能,发email的方法) -摘自网络
- C/C++ Windows API——文件/文件夹创建、删除、移动及查看时间