首页 > 其他分享 >输出所有的PE头信息(notepad)

输出所有的PE头信息(notepad)

时间:2023-03-16 15:35:23浏览次数:37  
标签:输出 pFile pFileBuffer notepad printf PIMAGE NULL PE

#include "stdafx.h"
#include<windows.h>
#include<malloc.h>
#include<stdio.h>
#include<winnt.h>


LPVOID ReadPEfile(LPSTR file)
{
    FILE *pFile =NULL;
    DWORD fileSize=0;
    LPVOID pFileBuffer=NULL;
    //open file

    pFile=fopen(file,"rb");

    if(!pFile)
    {
        printf("wu fa da kai EXE");
        return NULL;
    }

    //file size

    fseek(pFile,0,SEEK_END);

    fileSize=ftell(pFile);

    fseek(pFile,0,SEEK_SET);

    //malloc 

    pFileBuffer=malloc(fileSize);

    if(!pFileBuffer)
    {
        printf("molloc error");
        fclose(pFile);
        return NULL;
    }

    //rewirte

    size_t n=fread(pFileBuffer,fileSize,1,pFile);

    if(!n)
    {
        printf("read error");
        free(pFileBuffer);
        fclose(pFile);
        return NULL;
    }

    //close file

    fclose(pFile);
    return pFileBuffer;


}



int main(int argc, char* argv[])
{
    LPVOID pFileBuffer = NULL;
    PIMAGE_DOS_HEADER pDosHeader=NULL;
    PIMAGE_NT_HEADERS pNTHeader= NULL;
    PIMAGE_FILE_HEADER pPEHeader=NULL;
    PIMAGE_OPTIONAL_HEADER pOptionHeader=NULL;
    PIMAGE_SECTION_HEADER pSectionHeader=NULL;

    pFileBuffer=ReadPEfile("C://WINDOWS//system32/notepad.exe");

    if(!pFileBuffer)
    {
        
        printf("du qu error!");
        return 0;
    }

    if(*((PWORD)pFileBuffer)!=IMAGE_DOS_SIGNATURE)
    {
        printf("不是有效的MZ标志\n");
        free(pFileBuffer);
        return 0 ;
    }

    pDosHeader=(PIMAGE_DOS_HEADER)pFileBuffer;

    //打印DOC头

    printf("********************DOC头********************\n");

    printf("MZ标志:%x \n",pDosHeader->e_magic);
    printf("PE偏移:%x\n",pDosHeader->e_lfanew);

    ////判断是否是有效的PE标志

    if(*((PDWORD)((DWORD)pFileBuffer+pDosHeader->e_lfanew))!=IMAGE_NT_SIGNATURE)
    {
        printf("不是有效的PE标志\n");
        free(pFileBuffer);
        return 0 ;
    }
    pNTHeader=(PIMAGE_NT_HEADERS)((DWORD)pFileBuffer+pDosHeader->e_lfanew);
    //打印NT头

    printf("********************NT头********************\n");

    printf("NT:%x\n",pNTHeader->Signature);

    pPEHeader=(PIMAGE_FILE_HEADER)(((DWORD)pNTHeader)+4);

    printf("********************标准PE头********************\n");

    printf("PE: %x\n",pPEHeader->Machine);

    printf("节的数量:%x\n",pPEHeader->NumberOfSections);

    printf("可选PE头的大小:%x\n",pPEHeader->SizeOfOptionalHeader);

    //可选PE头    

    pOptionHeader= (PIMAGE_OPTIONAL_HEADER32)((DWORD)pPEHeader+IMAGE_SIZEOF_FILE_HEADER);


    printf("********************OPTIOIN_PE头********************\n");

    printf("OPTION_PE:%x\n",pOptionHeader->Magic);

    //释放内存

    free(pFileBuffer);

    int a;
    scanf("%d",&a);


}

 

标签:输出,pFile,pFileBuffer,notepad,printf,PIMAGE,NULL,PE
From: https://www.cnblogs.com/cspecialr/p/17222749.html

相关文章

  • ruoyi-vue启动报错error:03000086:digital envelope routines::initialization error
    原因分析可能是因为node是最新版本导致ERR_OSSL_EVP_UNSUPPORTED错误SSL数字信封不支持解决措施(ps:网上找的)setNODE_OPTIONS=--openssl-legacy-provider亲测并......
  • 【JavaScript】用Object.definePropety()对对象的属性实现监听和修改_TA远方的博客
    本文中会讲到对象函数Object.defineProperty(),也许你对这个函数比较陌生,要知道这个函数用途可大了,等自己想到它的时候,就知道它的重要性。文章目录举个栗子赋值其它......
  • Oracle SQL Developer 提示无法安装某些模块错误
    如果博友遇到启动时弹出警告--无法安装某些模块(Warning-couldnotinstallsomemodules):之后是一大堆的包解决方法:把C:\Users\${你自己的用户名}\AppData\Roaming\S......
  • 【YOLOv5】LabVIEW+OpenVINO让你的YOLOv5在CPU上飞起来
    (文章目录)前言上一篇博客给大家介绍了使用opencv加载YOLOv5的onnx模型,但我们发现使用CPU进行推理检测确实有些慢,那难道在CPU上就不能愉快地进行物体识别了吗?当然可以啦,......
  • PebbleTemplates 模版引擎使用
    PebbleTemplates是一个类似jinja的java模版引擎(受twig启发)支持的能力还是很多的,而且扩展性很不错,比如模版资源加载,模版缓存自定义扩展。。。。,是一个值得使用的模版引......
  • 什么是OpenStack?
    最近有人问我,现在这个时代基本上算是一个云计算的时代,传统的网络工程师还有出路吗?有!肯定有!虽然现在是云计算的时代,但是我们发展还远没有预想的那么快。2002年亚马逊(Amazon)提......
  • Object.prototype.toString判断类型的原理
    项目中,我们经常会直接使用Object.prototype.toString用来做类型判断。他基本是几种方法里可以开箱即用、且判断类型最完善了。现在我们来扒皮一下他。具体原理在toString......
  • Expectation-Maximization algorithm
    1.IntroductionTheExpectation-Maximization(EM)algorithmisawidelyusedstatisticalalgorithmformaximumlikelihoodestimationincaseswherethereismi......
  • Grasshopper - Personalized Message
    InstructionsCreateafunctionthatgivesapersonalizedgreeting.Thisfunctiontakestwoparameters:nameandowner.Useconditionalstoreturntheproperme......
  • nginx 配置 https 时找不到 pem 证书问题
    问题:在使用nginxdocker时的挂载卷为-v/root/ssl/letsencrypt/live/xxxxxxx:/etc/nginx/cert然后再nginx的default.conf中的证书位置为/etc/nginx/cert/fullchain.......