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

#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;
}

 

posted @ 2015-06-16 14:01  破冰Lab-Cookun  阅读(503)  评论(0编辑  收藏  举报