首页
社区
课程
招聘
[旧帖] [求助]exe文件判断是否为安装文件还是自解压文件 0.00雪花
发表于: 2010-5-31 15:47 1349

[旧帖] [求助]exe文件判断是否为安装文件还是自解压文件 0.00雪花

2010-5-31 15:47
1349
收藏
免费 0
支持
分享
最新回复 (2)
雪    币: 14
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
可以从 PE 头部获取信息计算出 EXE 未被附加外部数据前的真实长度。
如果你得到的文件长度比这个值大很多。。那么肯定是自解压文件了。

/*

    This code demostrates how to get the size of the
    real executable. No matter whether you've added
    extra data to the exe, the value should be the
    original size.

*/

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    FILE *fp;
    IMAGE_DOS_HEADER stDos;
    IMAGE_NT_HEADERS stNT;
    IMAGE_SECTION_HEADER stSection;
    int nSize;
    int i;
    char szFile[MAX_PATH];

    GetModuleFileNameA(0, szFile, MAX_PATH);

    fp = fopen(szFile, "rb");
    if(!fp)
    {
        printf("Can't open file for reading.\n");
        return 1;
    }

    fread(&stDos, 1, sizeof(stDos), fp);
    fseek(fp, stDos.e_lfanew, SEEK_SET);
    fread(&stNT, 1, sizeof(stNT), fp);

    nSize = stNT.OptionalHeader.SizeOfHeaders;
    for(i = 0; i < stNT.FileHeader.NumberOfSections; i++)
    {
        fread(&stSection, 1, sizeof(stSection), fp);
        nSize += stSection.SizeOfRawData;
    }

    fclose(fp);
    printf("My size is %d bytes.\n", nSize);

    return 0;
}


http://topic.csdn.net/u/20100519/13/205ec33e-ce08-4c98-8b9c-ae1c075abab0.html
2010-5-31 16:11
0
雪    币: 32
活跃值: (16)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
PE文件结构还在学习中...研究研究
2010-5-31 18:01
0
游客
登录 | 注册 方可回帖
返回
//