-
Notifications
You must be signed in to change notification settings - Fork 0
/
executable_file.rdr
158 lines (125 loc) · 7.84 KB
/
executable_file.rdr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
実行可能ファイル構造とは
+COFFファイルヘッダー:COFFファイルヘッダー構造
+ヘッダー標準フィールド:ヘッダー標準フィールド構造
+WindowsSpecificフィールド:WindowsSpecificフィールド構造
+ヘッダーディレクトリ:ヘッダーデータディレクトリ構造
+セクションテーブル:セクションテーブル構造
+リソースディレクトリテーブル:リソースディレクトリテーブル構造
終わり
実行可能ファイルとは
バイナリリーダーを継承する
-ファイルパス=「」
+実行可能ファイル
はじめの手順
ーー
終わり
-リソーステーブル読込み(位置,あ)手順
終わり
自分が[パス]を開く手順
もし,パスというファイルが存在しないなら
「指定のファイル: [パス] が見つかりません。」というエラーを発生させる
もし終わり
これのファイルパス=パス
読込みファイルというバイナリファイルを作る
読込みファイルへパスを読み取り専用で開く
ーーマジックナンバー: MZ
読込みファイルから2バイトを読込む
ーーもし,それ(1)が0x4Dかつそれ(2)が0x5Aでないなら
もし,(それ(1)が「M」の文字番号かつ,それ(2)が「Z」の文字番号)でないなら
「EXEファイルではないか,解析できない形式です。」というエラーを発生させる
もし終わり
読込みファイルを0x3Cへ移動する
読込みファイルから4バイトを整数として読込む
読込みファイルをそれへ移動する
実行可能ファイルとして実行可能ファイル構造を作る
COFFファイルヘッダー構造(読込みファイル)を作る。それを実行可能ファイルのCOFFファイルヘッダーに代入する
ヘッダー標準フィールド構造(読込みファイル)を作る。それを実行可能ファイルのヘッダー標準フィールドに代入する
実行可能ファイルのヘッダー標準フィールドのマジックについて分岐
0x010Bの場合
WindowsSpecificフィールドPE32構造(読込みファイル)を作る。それを実行可能ファイルのWindowsSpecificフィールドに代入する
0x020Bの場合
WindowsSpecificフィールドPE32プラス構造(読込みファイル)を作る。それを実行可能ファイルのWindowsSpecificフィールドに代入する
分岐終わり
ヘッダーデータディレクトリ構造(読込みファイル)を作る。それを実行可能ファイルのヘッダーディレクトリに代入する
セクションテーブル構造(実行可能ファイルのCOFFファイルヘッダーのセクション数,読込みファイル)を作る。それを実行可能ファイルのセクションテーブルに代入する
もし,実行可能ファイルのセクションテーブルのリソースが存在するかを取得した結果が偽なら
読込みファイルを閉じる
手順から抜ける
もし終わり
リソースデータ位置=実行可能ファイルのセクションテーブルのリソースの生データポインター
読込みファイルをリソースデータ位置へ移動する
リソースディレクトリテーブル構造(読込みファイル)を作る。それをリソースディレクトリテーブルに代入する
リソースディレクトリテーブルの名前項目数回繰り返す
ーーTODO: 実装
繰り返し終わり
リソースディレクトリテーブルの名前項目数を報告
リソースディレクトリテーブルのID項目数を報告
読込みファイルの現在位置をオリジナル読込み位置に代入する
ーー第1階層
リソースディレクトリテーブルのID項目数回繰り返す
読込みファイルをオリジナル読込み位置へ移動する
「現在位置」を報告する
読込みファイルの現在位置の十六進数を報告する
リソースディレクトリテーブル項目構造(読込みファイル)を作る
読込みファイルの現在位置をオリジナル読込み位置に代入する
それをリソースディレクトリテーブルのリソース項目リストへ追加する
ーーそれの名前オフセットを報告
それの名前文字列フラグを報告
もし,それの名前文字列フラグが真なら
「名前エントリー」を報告
それの名前オフセットを報告
それの名前を報告
(リソースデータ位置+それの名前オフセット)の十六進数を報告
読込みファイルをリソースデータ位置+それのディレクトリオフセットへ移動する
リソースディレクトリテーブル構造(読込みファイル)を作る。それをリソースディレクトリテーブルに代入する
それの名前項目数を表示する
それのID項目数を表示する
ーーTODO: 関数化
それの名前項目数回繰り返す
ーーTODO: 実装
繰り返し終わり
それをリソース実体に代入する
それのID項目数回繰り返す
リソースディレクトリテーブル項目構造(読込みファイル)を作る
それをリソースディレクトリテーブルのリソース項目リストへ追加する
「名前→ID→フラグ:」
リソース実体の名前文字列フラグを報告
リソース実体のデータディレクトリフラグを報告
繰り返し終わり
繰り返しを続ける
もし終わり
ーーそれのディレクトリオフセットを報告
それのデータディレクトリフラグを報告
もし,それのデータディレクトリフラグが真なら
「IDエントリー」を報告
それのIDを報告
それのデータオフセットを報告
それのディレクトリオフセットを報告
(リソースデータ位置+それのディレクトリオフセット)の十六進数を報告
ーー第2階層
読込みファイルをリソースデータ位置+それのディレクトリオフセットへ移動する
リソースディレクトリテーブル構造(読込みファイル)を作る。それをリソースディレクトリテーブルに代入する
それの名前項目数を表示する
それのID項目数を表示する
ーーTODO: 関数化
それの名前項目数回繰り返す
ーーTODO: 実装
繰り返し終わり
ーーリソースディレクトリテーブル構造
それをリソースディレクトリ実体に代入する
それのID項目数回繰り返す
リソースディレクトリテーブル項目構造(読込みファイル)を作る
それをリソースディレクトリ実体のリソース項目リストへ追加する
「ID→ID→フラグ:」を報告
リソースディレクトリ実体を報告
リソースディレクトリ実体の名前文字列フラグを報告
リソースディレクトリ実体のデータディレクトリフラグを報告
繰り返し終わり
繰り返しを続ける
もし終わり
繰り返し終わり
読込みファイルを閉じる
終わり
自分が[ファイル]を解析する手順
終わり
終わり