3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PEファイルのバイナリ構造(2) IMAGE_DOS_HEADER

Posted at

IMAGE_DOS_HEADER

PEファイルの先頭には「IMAGE_DOS_HEADER」構造体が格納されています。
細かい定義はヘッダファイルを検索して貰うとして、重要なメンバ変数は以下の2つになります。

メンバ
e_magic 固定の値「MZ」が指定されている。IMAGE_DOS_SIGNATUREとして定義。
e_lfanew 拡張ヘッダへのオフセット値(バイト単位)

まずはe_magicをチェックして正しいファイルであるかどうかを確認、e_lfanewで次の構造体へのアクセス位置を確認します。
この段階ではまだアドレスとファイルポインタの値は一致しているので、そのままアクセスできます。

IMAGE_DOS_HEADER& tDOS = (*(IMAGE_DOS_HEADER*)pFile);
if( tDOS.e_magic != IMAGE_DOS_SIGNATURE ){ return false;}

次はIMAGE_NT_HEADERSの解析に入りますが、この辺りから少し面倒な処理が入ってきます。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?