#include <stdio.h>#include<malloc.h>#include<stdlib.h>#include<string.h>#defineStreambuffer 1024#defineFilepathsize 256/** Read a file to memory return successful first address failed 0*/void* GETADRR (CharFilepath[filepathsize]) { Char*Filep; Char*temp; FILE*FINP; FILE*FOUTP; LongFilelen,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);//move the pointer to the end of the fileFileLen = Ftell (FINP);//calculates the distance from the head of the file to the current pointerRewind (FINP);//Place The file pointer on the topTemp= 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); returnFilep;}voidAnalysispe (void*FP) {}intMain () {CharFilepath[filepathsize]; strcpy (FilePath,"E:\\notepad.exe"); GETADRR (FilePath); return 0;}
Read files to memory, print PE structure