码迷,mamicode.com
首页 > 其他好文 > 详细

将文件读取到内存、打印pe结构

时间:2015-06-16 16:08:18      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:

#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>

#define STREAMBUFFER 1024
#define FILEPATHSIZE 256

/**
    将一个文件读到内存
return
        成功    首地址
        失败    0
*/
void* getAdrr(char filePath[FILEPATHSIZE])
{
    char* fileP;
    char* temp;
    FILE* finp;
    FILE* foutp;
    long fileLen,readLen;
    finp = fopen( filePath, "rb" );
    foutp= fopen("e:\\notepad_cpy.exe", "wb"); 
    if(finp == NULL || foutp == NULL)
    {
        printf("fopen error !");
        return 0;
    }
    fseek(finp , 0, SEEK_END);//指针移到文件尾
    fileLen = ftell(finp);//计算文件头到当前指针的距离
    rewind(finp);//将文件指针置首

    temp = fileP = (char*)malloc(sizeof(char)*fileLen + 1);
    if(fileP)
    {
        return 0;
    }
    memset(fileP,0,sizeof(char)*fileLen + 1);
    while( (readLen = fread( temp, sizeof( char ), STREAMBUFFER, finp )) != 0)
    {
        fwrite( temp, sizeof( char ), readLen, foutp );
        temp = temp+readLen;
    }
    fclose(finp);
    fclose(foutp);
    return fileP;
}

void analysisPE(void* fp)
{

}
int main()
{
    char filePath[FILEPATHSIZE];
    strcpy(filePath,"e:\\notepad.exe");
    getAdrr(filePath);
    return 0;
}

 

将文件读取到内存、打印pe结构

标签:

原文地址:http://www.cnblogs.com/zheh/p/4580614.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!