?? lion-petut-c01.htm
字號:
<!-- saved from url=(0043)http://203.157.250.93/win32asm/pe-tut1.html -->
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=gb_2312-80">
<meta name="GENERATOR" content="Microsoft FrontPage Express 2.0">
<title>PE教程1: PE文件格式一覽</title>
</head>
<body bgcolor="#000066" text="#FFFFFF" link="#FFFFCC"
vlink="#FFCCCC" alink="#CCFFCC">
<h1 align="center"><font color="#FFFFCC"
face="Arial, Helvetica, sans-serif">PE</font><font
color="#FFFFCC">教程1</font><font color="#FFFFCC"
face="Arial, Helvetica, sans-serif">: PE</font><font
color="#FFFFCC">文件格式一覽</font></h1>
<p><font size="2">考慮到早期寫的</font><font size="2"
face="MS Sans Serif">PE</font><font size="2">教程</font><font
size="2" face="MS Sans Serif">1</font><font size="2">是自己所有教程中最糟糕的一篇,此番決心徹底重寫一篇以饗讀者。</font></p>
<p><font size="2" face="MS Sans Serif">PE </font><font size="2">的意思就是
</font><font size="2" face="MS Sans Serif">Portable Executable</font><font
size="2">(可移植的執(zhí)行體)。它是 </font><font
size="2" face="MS Sans Serif">Win32</font><font size="2">環(huán)境自身所帶的執(zhí)行體文件格式。它的一些特性繼承自
</font><font size="2" face="MS Sans Serif">Unix</font><font
size="2">的 </font><font size="2" face="MS Sans Serif">Coff
(common object file format)</font><font size="2">文件格式。</font><font
size="2" face="MS Sans Serif">"portable executable"</font><font
size="2">(可移植的執(zhí)行體)意味著此文件格式是跨</font><font
size="2" face="MS Sans Serif">win32</font><font size="2">平臺的
</font><font size="2" face="MS Sans Serif">: </font><font
size="2">即使</font><font size="2" face="MS Sans Serif">Windows</font><font
size="2">運行在非</font><font size="2" face="MS Sans Serif">Intel</font><font
size="2">的</font><font size="2" face="MS Sans Serif">CPU</font><font
size="2">上,任何</font><font size="2" face="MS Sans Serif">win32</font><font
size="2">平臺的</font><font size="2" face="MS Sans Serif">PE</font><font
size="2">裝載器都能識別和使用該文件格式。當然,移植到不同的</font><font
size="2" face="MS Sans Serif">CPU</font><font size="2">上</font><font
size="2" face="MS Sans Serif">PE</font><font size="2">執(zhí)行體必然得有一些改變。所有
</font><font size="2" face="MS Sans Serif">win32</font><font
size="2">執(zhí)行體 </font><font size="2" face="MS Sans Serif">(</font><font
size="2">除了</font><font size="2" face="MS Sans Serif">VxD</font><font
size="2">和</font><font size="2" face="MS Sans Serif">16</font><font
size="2">位的</font><font size="2" face="MS Sans Serif">Dll)</font><font
size="2">都使用</font><font size="2" face="MS Sans Serif">PE</font><font
size="2">文件格式,包括</font><font size="2"
face="MS Sans Serif">NT</font><font size="2">的內(nèi)核模式驅(qū)動程序(</font><font
size="2" face="MS Sans Serif">kernel mode drivers</font><font
size="2">)。因而研究</font><font size="2"
face="MS Sans Serif">PE</font><font size="2">文件格式給了我們洞悉</font><font
size="2" face="MS Sans Serif">Windows</font><font size="2">結(jié)構(gòu)的良機。</font></p>
<p><font size="2">本教程就讓我們?yōu)g覽一下 </font><font
size="2" face="MS Sans Serif">PE</font><font size="2">文件格式的概要。</font></p>
<table border="1" cellpadding="2">
<TBODY> <tr>
<td align="center" bgcolor="#0033CC"><font size="2"
face="MS Sans Serif"><b>DOS MZ header</b></font></td>
</tr>
<tr>
<td align="center" bgcolor="#990000" height="28"><font
size="2" face="MS Sans Serif"><b>DOS stub</b></font></td>
</tr>
<tr>
<td align="center" bgcolor="#006600" height="36"><font
size="2" face="MS Sans Serif"><b>PE header</b></font></td>
</tr>
<tr>
<td align="center" bgcolor="#333399"><font size="2"
face="MS Sans Serif"><b>Section table</b></font></td>
</tr>
<tr>
<td align="center" bgcolor="#660066" height="52"><font
size="2" face="MS Sans Serif"><b>Section 1</b></font></td>
</tr>
<tr>
<td align="center" bgcolor="#660066" height="55"><font
size="2" face="MS Sans Serif"><b>Section 2</b></font></td>
</tr>
<tr>
<td align="center" bgcolor="#660066" height="53"><font
size="2" face="MS Sans Serif"><b>Section ...</b></font></td>
</tr>
<tr>
<td align="center" bgcolor="#660066" height="50"><font
size="2" face="MS Sans Serif"><b>Section n</b></font></td>
</tr>
</TBODY></table>
<p><font size="2">上圖是 </font><font size="2"
face="MS Sans Serif">PE</font><font size="2">文件結(jié)構(gòu)的總體層次分布。
所有 </font><font size="2" face="MS Sans Serif">PE</font><font
size="2">文件</font><font size="2" face="MS Sans Serif">(</font><font
size="2">甚至</font><font size="2" face="MS Sans Serif">32</font><font
size="2">位的 </font><font size="2" face="MS Sans Serif">DLLs) </font><font
size="2">必須以一個簡單的 </font><font size="2"
face="MS Sans Serif">DOS MZ header </font><font size="2">開始。
我們通常對此結(jié)構(gòu)沒有太大興趣。有了它,一旦程序在</font><font
size="2" face="MS Sans Serif">DOS</font><font size="2">下執(zhí)行,</font><font
size="2" face="MS Sans Serif">DOS</font><font size="2">就能識別出這是有效的執(zhí)行體,然后運行緊隨
</font><font size="2" face="MS Sans Serif">MZ header </font><font
size="2">之后的 </font><font size="2" face="MS Sans Serif">DOS
stub</font><font size="2">。</font><font size="2"
face="MS Sans Serif">DOS stub</font><font size="2">實際上是個有效的
</font><font size="2" face="MS Sans Serif">EXE</font><font
size="2">,在不支持 </font><font size="2"
face="MS Sans Serif">PE</font><font size="2">文件格式的操作系統(tǒng)中,它將簡單顯示一個錯誤提示,類似于字符串
</font><font size="2" face="MS Sans Serif">"This program
requires Windows" </font><font size="2">或者程序員可根據(jù)自己的意圖實現(xiàn)完整的
</font><font size="2" face="MS Sans Serif">DOS</font><font
size="2">代碼。通常我們也不對 </font><font size="2"
face="MS Sans Serif">DOS stub </font><font size="2">太感興趣</font><font
size="2" face="MS Sans Serif">: </font><font size="2">因為大多數(shù)情況下它是由匯編器</font><font
size="2" face="MS Sans Serif">/</font><font size="2">編譯器自動生成。通常,它簡單調(diào)用中斷</font><font
size="2" face="MS Sans Serif">21h</font><font size="2">服務</font><font
size="2" face="MS Sans Serif">9</font><font size="2">來顯示字符串</font><font
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -