判斷應用程式是32位還是64位

2021-07-02 07:02:39 字數 3856 閱讀 4508

1.首先介紹pe結構

windows系統下的可執行檔案,是基於microsoft設計的一種新的檔案結構,此結構被稱之為pe結構。pe的意思是portable executable(可移植的執行體),所有win32執行體都是用pe檔案格式,其中包括sys、dll、exe、com、ocx等。(不管是學習逆向、破解還是安全,了解pe檔案格式都是非常必要的。)

pe檔案的第乙個部分是image_dos_header,大小為64b,這裡面有兩個重要的資料成員。第乙個為e_magic,這個必須為mz,即0x5a4d。當然,0x5a4d這是典型的小端格式(little endian);另乙個重要的資料成員是最後乙個成員e_lfanew,這個成員的值為image_nt_headers的偏移。在image_dos_header和image_nt_headers之間乙個dos stub,這段程式用於在dos環境中顯示乙個字串,「this program cannot be run in dos mode」,現在dos早已滅絕,這段資料由編譯器生成,可以用0填充或者刪除(刪除的話要移動很多資料)。

image_dos_header的定義如下:

image_dos_header struct

image_dos_header ends

用c32asm檢視乙個exe程式的結構:

pe header 是pe相關結構nt映像頭(image_nt_header)的簡稱,裡邊包含著許多pe裝載器用到的重要字段。image_nt_headers 結構的定義: 

image_nt_headers struct  

image_nt_headers ends 

signature 字段:在乙個有效的 pe 檔案裡,signature 欄位被設定為00004550h,ascii 碼字元是「pe00」。標誌這 pe 檔案頭的開始。「pe00」 字串是 pe 檔案頭的開始,dos 頭部的 e_lfanew 字段正是指向這裡,如上圖所示。 

image_file_header 結構定義: 

typedef struct _image_file_header  

image_file_header,  *pimage_file_header;

(1)machine:可執行檔案的目標cpu型別。

image_file_machine_i386 0x014c  x86 

image_file_machine_ia64 0x0200  intel itanium 

image_file_machine_amd64 0x8664 x64 

(2)numberofsection: 區塊的數目。(注:區塊表是緊跟在 image_nt_headers 後邊的)

(3)timedatastamp: 表明檔案是何時被建立的。

這個值是自2023年1月1日以來用格林威治時間(gmt)計算的秒數,這個值是比檔案系統(filesystem)的日期時間更加精確的指示器。

(4)pointertosymboltable: coff 符號表的檔案偏移位置,現在基本沒用了。

(5)numberofsymbols: 如果有coff 符號表,它代表其中的符號數目,coff符號是乙個大小固定的結構,如果想找到coff 符號表的結束位置,則需要這個變數。

(6)sizeofoptionalheader: 緊跟著image_file_header 後邊的資料結構(image_optional_header)的大小。(對於32位pe檔案,這個值通常是00e0h;對於64位pe32+檔案,這個值是00f0h )。

(7)characteristics: 檔案屬性,有選擇的通過幾個值可以運算得到。( 這些標誌的有效值是定義於 winnt.h 內的 image_file_** 的值,具體含義見下表。普通的exe檔案這個欄位的值一般是 0100h,dll檔案這個欄位的值一般是 210eh。)

2.然後我們通過讀取pe檔案的執行平台字段判斷是32位還是64位:(這裡我寫的vc++6.0是win32控制台應用程式)

#include 

#include

int crngetimagefilemachine(char* lpfilename);

int main()

int crngetimagefilemachine(char* lpfilename)

如何判斷乙個執行的程式是64位的還是32位的

有些程式是32位的,有些是64位的, 怎麼用程式判斷? 判斷的目的是注入對應的dll, 64位程式注入64位dll, 32位程式注入32位dll.

開啟目標程序 ->獲取程序pbi -> pbi中找peb ->peb中找loaderdata ->loaderdata 裡面有個inloadordermodulelist ,

這個是本程序中按次序進入記憶體的模組資訊的鍊錶,第乙個就是當前exe ,這個模組資訊中 有個baseaddress ,就是exe虛擬記憶體基址-> 通過這個基址找dos_header -> dos_header中找 pe_header -> pe_header.optionalheader.magic 就是要判斷的 image_nt_optional_hdr32_magic or image_nt_optional_hdr64_magic

帖個**

typedef long (winapi *procntqsip)(handle,uint,pvoid,ulon

請問:cisco交換機的埠資訊都說明什麼

g,pulong);

procntqsip ntqueryinformationprocess;

ntqueryinformationprocess = (procntqsip)getprocaddress(getmodulehandle("ntdll"),"ntqueryinformationprocess");

handle hprocess = openprocess(process_all_access, false, 3580);

process_basic_information pbi;

peb buf;

dword readnum;

peb_ldr_data ldrdata;

ntqueryinformationprocess(hprocess,0,(pvoid)&pbi,sizeof(process_basic_information),null);

readprocessmemory(hprocess,pbi.pebbaseaddress,&buf,sizeof(peb),&readnum);

readprocessmemory(hprocess,buf.loaderdata,&ldrdata,sizeof(peb_ldr_data),&readnum);

ldr_module ldrmodule;

list_entry* plistentry=ldrdata.inloadordermodulelist.flink;

readprocessmemory(hprocess,plistentry,&ldrmodule,sizeof(ldr_module),&readnum);

lpvoid pbase=ldrmodule.baseaddress;

image_dos_header dos_header;

readprocessmemory(hprocess,pbase,&dos_header,sizeof(image_dos_header),&readnum);

image_nt_headers pe_header;

readprocessmemory(hprocess,(lpvoid)((long)pbase + dos_header.e_lfanew),&pe_header,sizeof(image_nt_headers),&readnum);

cout<

判斷機器 程式是32位還是64位

一 linux上如何知道自己的作業系統 計算機 是32位還是 64位的?linux users should type the uname command.depending on the platform,you may see linux gaylord.stata.com 2.6.11 1.2...

python 判斷Dll是32位還是64位

coding gb2312 writer write by lhsbqb date 2012 07 16 import sys class getdllbit def init self,dll name if len sys.argv 2 獲取 軟體名 print sys.argv 1 decod...

如何判斷Linux是32位還是64位

方法一 getconf long bit 在linux終端輸入getconf long bit命令 如果是32位機器,則結果為32 linux root localhost getconf long bit 32 如果是64位機器,則結果為64 linux root localhost getcon...