📄 01_9_17_5.asp.html
字号:
<html><head><meta http-equiv='Content-Type' content='text/html; charset=gb2312'>
<TITLE>计算机世界网-WINDOWS95 及WINDOWS98 的 后 台 进 程</TITLE></HEAD>
<style>
.a14{font-size:14px;text-indent:25px;line-height:20px}
.f{font-size:18px;color=#0f3ccd}
img{border:0px;}
td,p,input{font-fammily:verdana,宋体;font-size:12px;}
A:link {text-decoration:none;color:black}
A:visited {text-decoration:none;color:#80006f}
A:hover {text-decoration:underline;color:black}
</style>
<center>
<BODY topmargin=2 leftmargin=0>
<style>
.v12{font-size:10pt;color:"#ffffff";FONT-WEIGHT: bold}
.v14{font-size:14px;text-indent:25px;line-height:20px}
img{border:0px;}
td,p,input,select{font-fammily:verdana,宋体;font-size:12px;}
A:link {text-decoration:none;color:black}
A:visited {text-decoration:none;color:#80006f}
A:hover {text-decoration:underline;color:black}
</style>
<style>
.v13{font-size:10pt;color:"#ffffff";FONT-WEIGHT: bold}
.v12{font-size:13px;color:"#4C029C";FONT-WEIGHT: bold}
.v14{font-size:14px;text-indent:25px;line-height:20px}
img{border:0px;}
td,p,input,select{font-fammily:verdana,宋体;font-size:12px;}
A:link {text-decoration:none;color:black}
A:visited {text-decoration:none;color:#80006f}
A:hover {text-decoration:underline;color:black}
</style>
<!--头-->
<table align=center cellpadding="0" cellspacing="0" border="0" width="767">
<tr><td valign=bottom>
<table cellpadding="0" cellspacing="0" border=0>
<tr><td valign=top><img src="../../../../../center/image/ccwlogo.gif"></td></tr>
<tr><td height="27" valign=top><img src="../../../../../center/image/knowledge.gif" width="207" height="27"></td></tr>
</table></td>
<td valign=bottom width=556 bgcolor="#4c029c" height=96>
<table cellpadding="0" cellspacing="0" border=0 width=556 bgcolor="#4c029c" height=96>
<tr><td height=25 valign=bottom bgcolor="#ffffff" colspan=2 ><img src="../../../../../image2002/top.gif" usemap="#F"></td></tr>
<tr valign=middle >
<td align=center valign=middle height="60" align=center>
<!-- <a href="http://www.ccw.com.cn/search/" target=_blank><img src="../../../../../img2/esearch.GIF" border=0 width=468 height=60></a> --><a href="http://www.ccw.com.cn/html/search/thememail/" target=_blank><img src="../../../../../img2/topbanner_thememail.GIF" border=0 width=468 height=60></a>
</td>
<td align=center width=15%>
<table width=95%>
<tr><td><a href="mailto:center@ccw.com.cn?subject=我要投稿:" target=_blank><font class=v13>我要投稿</a><br><a href="mailto:center@ccw.com.cn?subject=编读往来"><font class=v13>编读往来</a><br><a href="javascript:AddBookMark('计算机世界网首页')"><font class=v13>加入收藏</a></font></td></tr>
</table>
</td>
</tr>
<tr><td bgcolor="#ffffff" height=1 colspan=2 ></td></tr>
<tr><td bgcolor="#b4aafc" height=2 colspan=2 ></td></tr></table>
<map name="F">
<area href="http://www.ccw.com.cn/" shape="rect" coords="29, 3, 61, 18" target=_blank>
<area href="http://www.ccw.com.cn/news1/" shape="rect" coords="72, 3, 143, 18" target=_blank>
<area href="http://www.ccw.com.cn/center/" shape="rect" coords="155, 2, 216, 18" target=_blank>
<area href="http://www.ccw.com.cn/work/" shape="rect" coords="225, 2, 299, 18" target=_blank>
<area href="http://www.ccw.com.cn/search/" shape="rect" coords="310, 3, 364, 19" target=_blank>
<area href="http://www3.ccw.com.cn/" shape="rect" coords="372, 2, 412, 19" target=_blank>
<area href="http://www2.ccw.com.cn/" shape="rect" coords="424, 2, 550, 18" target=_blank></map>
</td></tr>
<tr><td colspan=2 bgcolor="#b4aafc">
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr>
<td width=26% align=center><font class=v12>【2003年6月24日】 </font></td>
<td CLASS=V12> <a href="http://www.ccw.com.cn/center/topic.asp">专 题</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/tech.asp">技 术</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/prod.asp">产 品</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/app.asp">应 用</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/net.asp">网 络</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/prog.asp">编 程</a> /</td>
<td CLASS=V12><a href="http://www.ccw.com.cn/center/skill.asp">技 巧</a> </td>
</tr>
</table>
</td></tr>
</table>
<table align=center width=728>
<tr><td align=center><br>
<h2><font color='#0f3ccd'>WINDOWS95及WINDOWS98的后台进程</font></h2>
<br><b>黄 飞</b>
</td></tr><tr><td align=right>01-9-17 上午 10:22:00<br><hr size=1 width=718 color=#f46240></td></tr></table><br>
<table align=center width=728><tr><td valign=top width=600>
<table width=100% ><tr>
<td class=a14><b>后 台 进 程</b></td>
</tr></table><table width=100% ><tr><td class=a14>
在WINDOWS NT 中 有 一 个 功 能 强 大 的SERVICE 管 理 器, 它 管 理 着 一 部 分 实 现 重 要 功 能 的 后 台 进 程, 例 如FTP.HTTP.RAS. 网 络Message 等 等, 这 些 后 台 进 程 被 称 之 为Service, 他 们 可 以 在 系 统 启 动 时 就 加 载, 可 以 运 行 在 较 高 的 优 先 级, 可 以 说 是 非 常 靠 近 系 统 核 心 的 设 备 驱 动 程 序 中 的 一 种. 在WINDOWS95 下,Microsoft 没 有 提 供 这 样 一 个 高 度 集 中 化 了 的 管 理 器, 不 过 我 们 通 过VC 自 带 的PVIEW 可 以 看 到, 在 桌 面 背 后 同 样 有 秘 密 的 后 台 进 程 存 在, 例 如:SysTray, 电 源 管 理 等. 其 实, 这 些 就 是WINDOWS95 管 理 的 后 台 进 程,WINDOWS95 没 有 提 供SERVICE 管 理 器, 取 而 代 之 的 是 一 个 简 单 的 登 记 接 口, 可 以 类 似 的 称 之 为WINDOWS95 下 的Service( 不 过 严 格 的 讲,WINDOWS95 下 是 没 有Service 的), 同 样 的, 通 过 这 个 登 记 接 口, 我 们 可 以 使 自 己 的 程 序 随 系 统 启 动 而 最 先 运 行, 随 系 统 关 闭 而 最 后 停 止, 和 操 作 系 统 结 合 在 一 起, 实 现 许 多 独 特 的 功 能. 我 在 实 际 工 作 中, 仔 细 的 分 析 了 这 个Windows95 的 接 口, 并 且 测 试 后 发 现, 在WINDOWS97 和 最 新 的WINDOWS98 中 它 一 样 有 效. 并 通 过 这 个 机 制, 成 功 的 实 现 了WINDOWS95.98 下 的 无 人 职 守 监 控. 下 面 是 关 于 这 个 接 口 的 分 析 结 果 和 一 些 准 备 知 识. </td></tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr>
<td class=a14> <b>进 程 数 据 库(PDB) 介 绍</b></td>
</tr></table><table width=100% ><tr><td class=a14>
在Windows 的 核 心 数 据 结 构 中, 有 一 个 重 要 的 进 程 管 理 结 构 叫 进 程 数 据 库, 它 位 于Kernel32 的 公 用 内 存 堆 中, 可 以 通 过GetCurrentProcessID(...) 得 到 指 向 该 结 构 的 指 针, 以 下 是 部 分PDB 的 组 成, 与 本 文 直 接 相 关 的 是PDB 偏 移21h 处 的Service 标 志 字 节, 通 过 后 面 的 伪 码 分 析, 我 们 可 以 清 楚 的 看 到 所 谓 登 记 为Windows95 或Windows98 下 的Service 进 程, 只 不 过 是 把 它 相 应 的PDB 中 该 标 志 字 节 置 为1 而 已. </td></tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr>
<td class=a14> <b>偏 移 量 长 度 说 明</b></td>
</tr></table><table width=100% ><tr><td class=a14>
============================================</td></tr></table><table width=100% ><tr><td class=a14>
+00h DWORD Type // Kernel32 对 象 的 类 型</td></tr></table><table width=100% ><tr><td class=a14>
+04h DWORD CReference // 参 考 计 数</td></tr></table><table width=100% ><tr><td class=a14>
+08h DWORD Un1 // 未 知</td></tr></table><table width=100% ><tr><td class=a14>
+0ch DWORD pSomeEvent // 指 向K32OBJ_EVENT 指 针</td></tr></table><table width=100% ><tr><td class=a14>
+10h DWORD TerminationStatus // 活 动 标 志 或 返 回 值</td></tr></table><table width=100% ><tr><td class=a14>
+14h DWORD Un2 // 未 知</td></tr></table><table width=100% ><tr><td class=a14>
...</td></tr></table><table width=100% ><tr><td class=a14>
+21h BYTE Flags1 // Service 标 记,</td></tr></table><table width=100% ><tr><td class=a14>
// "1" 是Service 进 程,</td></tr></table><table width=100% ><tr><td class=a14>
// "0" 普 通 进 程</td></tr></table><table width=100% ><tr><td class=a14>
...</td></tr></table><table width=100% ><tr><td class=a14>
+24h DWORD pPSP // DOS PSP 指 针</td></tr></table><table width=100% ><tr><td class=a14>
...</td></tr></table><table width=100% ><tr><td class=a14>
============================================</td></tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr>
<td class=a14> <b>实 现 接 口</b></td>
</tr></table><table width=100% ><tr><td class=a14>
(1) Windows95 中 提 供 的 简 单 的Service 接 口 是 一 个32 位 的API: RegisterServiceProcess, 由 于 在VC++ 的Online help 中 得 不 到 关 于 这 个API 的 确 切 解 释, 笔 者 不 得 不 针 对 此API 进 行 了 逆 向 分 析, 以 下 是 在Windows95 的Kernel32.dll 中 该API 的 伪 码. 我 们 可 以 清 楚 的 看 到Window95 内 部 到 底 是 怎 样 做 的, 其 实 处 理 的 非 常 简 单. </td></tr></table><table width=100% ><tr><td class=a14>
</td></tr></table><table width=100% ><tr><td class=a14>
BOOL RegisterServiceProcess( DWORD dwProcessID, DWORD dwType )</td></tr></table><table width=100% ><tr><td class=a14>
{</td></tr></table><table width=100% ><tr><td class=a14>
HANDLE dwPID;</td></tr></table><table width=100% ><tr><td class=a14>
if( dwProcessID == NULL )</td></tr></table><table width=100% ><tr><td class=a14>
dwPID = dwCurrentProcessID; // Get global kernel32 variable</td></tr></table><table width=100% ><tr><td class=a14>
else</td></tr></table><table width=100% ><tr><td class=a14>
// Call some kernel functions</td></tr></table><table width=100% ><tr><td class=a14>
if( ( dwPID = CheckPID( dwProcessID ) == NULL )</td></tr></table><table width=100% ><tr><td class=a14>
return FALSE;</td></tr></table><table width=100% ><tr><td class=a14>
if( dwType == 1 )</td></tr></table><table width=100% ><tr><td class=a14>
{</td></tr></table><table width=100% ><tr><td class=a14>
*(BYTE *)( dwPID + 0x21 ) | = 0x01;</td></tr></table><table width=100% ><tr><td class=a14>
return TRUE;</td></tr></table><table width=100% ><tr><td class=a14>
}</td></tr></table><table width=100% ><tr><td class=a14>
if( dwType == 0 )</td></tr></table><table width=100% ><tr><td class=a14>
{</td></tr></table><table width=100% ><tr><td class=a14>
*(BYTE *)( dwPID + 0x21 ) & = 0xFE;</td></tr></table><table width=100% ><tr><td class=a14>
return TRUE;</td></tr></table><table width=100% ><tr><td class=a14>
}</td></tr></table><table width=100% ><tr><td class=a14>
return FALSE;</td></tr></table><table width=100% ><tr><td class=a14>
}</td></tr></table><table width=100% ><tr><td class=a14>
以 下 为 函 数 原 形:</td></tr></table><table width=100% ><tr><td class=a14>
BOOL RegisterServiceProcess( DWORD dwPID, DWORD dwType )</td></tr></table><table width=100% ><tr><td class=a14>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -