判斷是不是PE檔案

2021-06-22 16:21:41 字數 2028 閱讀 8473

#include #include "assert.h"

#include #include "tchar.h"

#ifdef unicode

#define ispefile ispefilew

#define isdigisig isdigisigw

#else

#define ispefile ispefilea

#define isdigisig isdigisiga

#endif // !unicode

//獲得dos頭

lpvoid getdosheader(lpvoid lpfile)

//獲得nt頭

lpvoid getntheader(lpvoid lpfile,bool& bx64)

return pntheader32;

}//獲得可選頭

lpvoid getoptionheader(lpvoid lpfile,bool& bx64)

else

return poptionheader;}/*

* 獲取字段

*/bool isdigisigex(handle hfile)

if (lpfile==null) //檔案檢視物件

image_data_directory secdata = ;

lpvoid poptionheader = null;

bool bx64opheader = false;

poptionheader = (lpvoid)getoptionheader( lpfile,bx64opheader );

if(poptionheader != null && bx64opheader)

else if(poptionheader != null)

unmapviewoffile(lpfile);

closehandle(hfile);

if ( ( secdata.virtualaddress != 0 ) && ( secdata.size != 0 ) )

return true;

return false;

}//a版函式

bool isdigisiga(lpcstr ppath)

//w版函式

bool isdigisigw(lpcwstr ppath)

//實際判斷pe檔案操作

bool ispefileex(handle hfile,bool &bissucceed)

if (lpfile==null) //檔案檢視物件

pimage_dos_header pdosheader=null;

pimage_nt_headers32 pntheader32 = null;

//取得dos頭部

pdosheader = (pimage_dos_header)lpfile;

if (pdosheader->e_magic != image_dos_signature)

//獲取nt頭

pntheader32 = (pimage_nt_headers32)((dword)pdosheader + pdosheader->e_lfanew);

//判斷是不是pe檔案

if (pntheader32->signature != image_nt_signature)

unmapviewoffile(lpfile);

closehandle(hfile);

bissucceed = true;

return true;}/*

* 函式執行成功返回true,失敗返回false,a版

* 第二個引數為true表示是pe檔案,false表示非pe檔案

*/bool ispefilea(lpcstr ppath,bool &bissucceed)

//w版

bool ispefilew(lpcwstr ppath,bool &bissucceed)

int main()

判斷是不是樹

判斷是否為樹的的依據可以簡化為一句話 是否有且僅有乙個入度為0的節點。上只用對映就可以解決,但是要排除自環的情況。include using namespace std map int,int indegree bool istree return rootcount 迴圈結束後,若根節點數非0,則...

如何判斷序列是不是堆 如何判斷墨鏡是不是偏光的

開車的都比較喜歡配戴偏光太陽鏡,因為偏光鏡除了能阻擋紫外線外,還能最大限度的減少和過濾掉反射的強光眩光。譬如開車時對面車的強光燈,或行駛在前面的車因後窗貼的反光阻隔uv的窗貼膜被太陽照射而形成的強眩光,使佩戴者能清楚的開清前面的事物。購買的偏光眼鏡一般在鏡片上或鏡腿內側都會有polarized 偏光...

怎麼判斷是不是尤拉迴路 怎麼判斷自己是不是甲溝炎

1 急性甲溝炎 初期症狀為指甲區域性紅腫,輕 觸紅腫部分即會產生刺痛。約數天後開始化膿,並可能延伸至指甲下方。2 慢性甲溝炎 如同症名,指甲會緩慢逐漸變成黃褐色,同時變形彎曲凹凸不平後變慘白或黃 色 研究發現慢性甲溝炎也常合併綠膿桿菌感染而使指甲變綠。3 化膿性甲溝炎化 甲溝有輕度紅腫 疼痛 甲小皮...