コード例 #1
0
ファイル: PEhandler.cs プロジェクト: jrfl/exeopt
 public PEfile(string path)
 {
     if(!File.Exists(path)) throw new Exception("File does not exist");
     file=new FileInfo(path);
     stream=new BinaryReader(file.OpenRead());
     dosHeader=new DosHeader(stream);
     if(dosHeader.Magic!="MZ") throw new Exception("File does not appear to be executable");
     imageHeader=new ImageHeader(stream,dosHeader.ImageHeaderAddress);
     if(imageHeader.Magic!="PE\0\0") throw new Exception("File does not appear to be a WIN32 exe");
     imageOptionalHeader=new ImageOptionalHeader(stream);
     imageSectionHeaders=new ImageSectionHeader[imageHeader.NumberOfSections];
     for(int x=0;x<imageHeader.NumberOfSections;x++) {
         imageSectionHeaders[x] = new ImageSectionHeader(stream);
     }
     CodeOffset=imageOptionalHeader.BaseOfCode;
     CodeSize=imageOptionalHeader.SizeOfCode;
     stream.Close();
 }