解析PE檔案的附加資料

2021-06-22 06:02:09 字數 2229 閱讀 6727

解析程式自己的附加資料,將附加資料寫入檔案中。

主要是解析pe檔案頭,定位到overlay的地方,寫入檔案。常應用的場景是在crackme中,crackme自身有一段加密過的附加資料,在crackme執行的過程中解析自己的附加資料,然後解密這段資料。。。。

**留存:

//解析自己的pe檔案

tchar szmodulefile[max_path] = ;

::getmodulefilename(null, szmodulefile, max_path);

handle hfile = ::createfile(szmodulefile, 0x80000000, 0x1, null, 0x3, 0x80, null );

if (!hfile)

dword dwfilesize = 0;

dwfilesize = ::getfilesize(hfile, null);

if (!dwfilesize)

tchar *pbuffer = new tchar[dwfilesize+1];

dword dwreadbytes = 0;

bool bsuc = ::readfile(hfile, pbuffer, dwfilesize, &dwreadbytes, null);

if (!bsuc)

image_dos_header *pdoshead =(image_dos_header *)pbuffer;

image_nt_headers *pntheader;

// 得到pe檔案頭.

pntheader = (image_nt_headers*)((char*)pdoshead + pdoshead->e_lfanew);

word wnumofsection = pntheader->fileheader.numberofsections;

//dword dwtemp = wnumofsection * (sizeof(image_section_header)/sizeof(dword));

word wsizeofoptionalheader = pntheader->fileheader.sizeofoptionalheader;

dword *poverlay;

dword *plastsectionvirualaddress;

dword *plastsectionvirualsize;

dword *plastsectionphyaddress, *plastsectionphysize;

plastsectionvirualsize = (dword*) ((char*)pntheader+ sizeof(image_nt_headers) + (wnumofsection-1)*sizeof(image_section_header) + sizeof(byte)*image_sizeof_short_name );

plastsectionvirualaddress = plastsectionvirualsize + 1;

plastsectionphyaddress = plastsectionvirualsize + 2;

plastsectionphysize = plastsectionvirualsize + 3;

dword dw1 = *plastsectionphyaddress;

dword dw2 = *plastsectionphysize;

poverlay = (dword*)(dw1 + dw2 + pbuffer);

dword dwoverlaysize = dwfilesize - (dw1 + dw2);

handle houtfile = ::createfile("c:\\users\\administrator\\desktop\\crackme.exe.overlay", generic_write, file_share_read, null, create_new, null, null);

if (!houtfile)

dword dwwritten = 0;

::writefile(houtfile, poverlay, dwoverlaysize, &dwwritten, null);

::closehandle(houtfile);

if ((char *)poverlay == 0x0)

::free(pbuffer);

::closehandle(hfile);

解析PE檔案的附加資料

解析程式自己的附加資料,將附加資料寫入檔案裡。主要是解析pe檔案頭。定位到overlay的地方。寫入檔案。常應用的場景是在crackme中,crackme自身有一段加密過的附加資料。在crackme執行的過程中解析自己的附加資料,然後解密這段資料。留存 解析自己的pe檔案 tchar szmodul...

附加資料庫 sql

附加資料庫 sp attach db xxaccountsdb6 e 資料庫 xxaccountsdb6.mdf e 資料庫 xxaccountsdb6 log.ldf gosp attach db xxagentsystem e 資料庫 xxagentsystem.mdf e 資料庫 xxagen...

SQLite 附加資料庫

假設這樣一種情況,當在同一時間有多個資料庫可用,你想使用其中的任何乙個。sqlite的attach database語句是用來選擇乙個特定的資料庫,使用該命令後,所有的sqlite語句將在附加的資料庫下執行。語法 sqlite的attach database語句的基本語法如下 attach data...