読書メモ/「APIで学ぶWindows徹底理解」/Part11-Part15
読書メモ / 「APIで学ぶWindows徹底理解」 / Part11-Part15
id: 655 所有者: msakamoto-sf
作成日: 2010-05-22 14:06:26
カテゴリ: C言語 Windows 読書
"APIで学ぶWindows徹底理解"のPart11 - Part15までの読書メモです。
この読書メモのスタンス、およびサンプルコードの入手については以下を参照して下さい。
読書メモ/「APIで学ぶWindows徹底理解」
【Part 11】実行ファイルの構造を理解する
- PEファイル解析用のサポート機能について詳しく知りたい
- "MSDN Library" > "Windows Development" > "Diagnostics" > "Debugging and Error Handling" > "Debug Help Library" > "DbgHelp Reference" > "Image Help Library"
他、"MSDN Magazine"内の記事や、外部の詳しい解説記事を載せておく。
- Microsoft Portable Executable and Common Object File Format Specification
- Matt Pietrek 氏によるMSDN記事
- Peering Inside the PE: A Tour of the Win32 Portable Executable File Format (1994)
- Inside Windows: An In-Depth Look into the Win32 Portable Executable File Format, Part1 (2002)
- Inside Windows: An In-Depth Look into the Win32 Portable Executable File Format, Part2 (2002)
- PE(Portable Executable)ファイルフォーマット その1 ファイルの基本構造
- Inject your code to a Portable Executable file - CodeProject
- Dependency Walker
※サンプルコードは無し
【Part 12】Windowsのアクセス制御の仕組みを理解する
- セキュリティディスクリプタについて詳しく知りたい
- "MSDN Library" > "Windows Development" > "Security" > "Authorization"
※ちなみに "Authentication" が「認証」でいわゆるログイン時の処理。 "Authorization" が「認可」で権限を付与することを認める処理。
サンプル解説("Part12_Security\"フォルダ)
- 12_01.cpp
-
本書128p, リスト1のVC++移植版。
コンパイル方法:
cl 12_01.cpp user32.lib advapi32.lib
ユーザーID/グループIDに対するSIDを文字列として表示する。
- 12_02.cpp
-
本書132p, リスト2のVC++移植版。
コンパイル方法:
cl 12_02.cpp user32.lib advapi32.lib ..\PrintErrorMsg.obj
プロセスのアクセストークンに設定されているデフォルトDACLを表示する。
runas /noprofile /user:(適当なユーザーID) cmd
で別ユーザーとして開いたコマンドプロンプト上から実行するなどして比べてみると、面白い。
【Part 13】「サービス」を作るのは意外に簡単
- サービス(Service)アプリケーションの作成について詳しく知りたい
- "MSDN Library" > "Windows Development" > "System Services" > "DLLs, Processes, and Threads" > "Services"
- "CreateEvent"など、同期の為の"Event"オブジェクトについて復習したい
- "MSDN Library" > "Windows Development" > "System Services" > "DLLs, Processes, and Threads" > "Synchronization" > "About Synchronization" > "Synchronization Objects" > "Event Objects"
※OutputDebugString()についてはPart15にて解説有り。
サンプル解説("Part13_Services\"フォルダ)
- 13_01_main.cpp, 13_02_install.cpp, 13_03_uninstall.cpp
-
本書137p - 142p, リスト1, 2, 4, 6のVC++移植版。
コンパイル方法:
cl 13_01_main.cpp user32.lib advapi32.lib
cl 13_02_install.cpp user32.lib advapi32.lib ..\PrintErrorMsg.obj
cl 13_03_uninstall.cpp user32.lib advapi32.lib ..\PrintErrorMsg.obj
動かし方:
- 13_01_main.exe を "C:" ドライブの直下に置く。
- 13_02_install.exe を実行し、SCMに"BeepServices"として13_01_main.exeを登録する。
- SCMからBeepServicesを動かしてみて、確認する。
- 13_03_uninstall.exe を実行し、SCMから"BeepServices"の登録を削除する。
- 13_04_start.cpp, 13_05_stop.cpp
-
本書142p, リスト7のVC++移植版。
コンパイル方法:
cl 13_04_start.cpp user32.lib advapi32.lib ..\PrintErrorMsg.obj
cl 13_05_stop.cpp user32.lib advapi32.lib ..\PrintErrorMsg.obj
動かし方:
- 13_02_install.exe を実行し、SCMに"BeepServices"として13_01_main.exeを登録する。
- 13_04_start.exe を実行し、BeepServiceが開始するのを確認する。
- 13_05_stop.exe を実行し、BeepServiceが停止するのを確認する。
- 13_03_uninstall.exe を実行し、SCMから"BeepServices"の登録を削除する。
【Part 14】プロセス間通信を使ってデータを受け渡す
- 名前付パイプ・名前無しパイプについて詳しく知りたい
- "MSDN Library" > "Windows Development" > "System Services" > "Interprocess Communications" > "Pipes"
- クリップボードについて詳しく知りたい
- "MSDN Library" > "Windows Development" > "Windows Application UI Development" > "Windows User Interface" > "Data Exchange" > "Clipboard"
サンプル解説("Part14_IPC_Pipe_Clipboard\"フォルダ)
- 14_01系
- 本書には出てこない「名前付パイプ」によるプロセス間通信のサンプル。MSDNにあるので、そちらを参照:"MSDN Library" > "Windows Development" > "System Services" > "Interprocess Communications" > "Pipes" > "Using Pipes"
- 14_02_anonymousp_parent.cpp, 14_02_anonymousp_child.cpp
-
本書148p, リスト4, 5のVC++移植版。
コンパイル方法:
cl 14_02_anonymousp_parent.cpp ..\PrintErrorMsg.obj
cl 14_02_anonymousp_child.cpp ..\PrintErrorMsg.obj
14_02_anonymousp_parent.exe を起動すると名前無しパイプを作成し、子プロセスである14_02_anonymousp_child.exeに引き継ぎ、プロセス間でデータ通信を行う。
- 14_03.cpp
-
本書150p, リスト6のVC++移植版+簡略化版。
コンパイル方法:
cl 14_03.cpp user32.lib
14_03.exeを実行すると空のウインドウが表示される。左クリックで固定文字列がクリップボードにコピーされ、右クリックでクリップボードにコピーされた文字列をメッセージボックスで表示する。
【Part 15】デバッガはなぜデバッグできるのか
- Windows標準のデバッグ機能について詳しく知りたい
- "MSDN Library" > "Windows Development" > "Diagnostics" > "Debugging and Error Handling" > "Basic Debugging"
- システムの"snapshot"を作成して、プロセス・スレッド・モジュール・ヒープの一覧を取得する機能について詳しく知りたい
- "MSDN Library" > "Windows Development" > "System Services" > "DLLs, Processes, and Threads" > "Tool Help Library"
- "Process Status API"(PSAPI)を使ってプロセス・モジュール・メモリ状況を取得する機能について詳しく知りたい
- "MSDN Library" > "Windows Development" > "System Services" > "DLLs, Processes, and Threads" > "Process Status API (PSAPI)"
CodeProjectより参考ページ:
- Writing a basic Windows debugger - CodeProject
- An Anti-Reverse Engineering Guide - CodeProject
- Using the Debugger API to get trace messages from an executing application. - CodeProject
- Writing a Debugger - Part 2: The Debug Loop - CodeProject
サンプル解説("Part15_Debug\"フォルダ)
- 15_01_debuggee.cpp, 15_01_debugger.cpp
-
本書157p-158p, リスト5, 7のVC++移植版。
コンパイル方法:
cl 15_01_debuggee.cpp user32.lib
cl 15_01_debugger.cpp ..\PrintErrorMsg.obj
15_01_debuggee.exeが「デバッグ対象」で、OutputDebugString()とDebugBreak()を呼ぶサンプル。コマンドプロンプトから
15_01_debugger.exe 15_01_debuggee.exe
とすることで、15_01_debuggerがデバッガとして15_01_debuggeeをデバッグする。デバッグループで発生したイベントをコンソールに逐次表示し、OutputDebugString()ではReadProcessMemory()でデバッグ対象のプロセスのメモリ空間から、メッセージ文字列をコピーして表示する。
- 15_02_processlist.cpp
-
本書159p, リスト9のVC++移植版。
コンパイル方法:
cl 15_02_processlist.cpp ..\PrintErrorMsg.obj
ToolHelp32でシステムのスナップショットを取得し、プロセスの一覧を表示するサンプル。
プレーンテキスト形式でダウンロード
現在のバージョン : 3
更新者: msakamoto-sf
更新日: 2010-05-24 12:08:59
md5:20e1fa2f16d9fd113292704699885d99
sha1:994d530631066338b375f968694878587cb2273b
コメント