Annotation of mstools/samples/deb/deb.rtf, revision 1.1.1.2

1.1       root        1: {\rtf1\ansi \deff0\deflang1033
                      2: 
                      3: 
                      4: {\fonttbl
                      5: \f0\froman Times New Roman;
                      6: \f1\fmodern Courier;
                      7: \f2\fswiss Arial;}
                      8: 
                      9: 
                     10: {\colortbl;
                     11: \red0\green0\blue0;
                     12: \red0\green0\blue255;
                     13: \red0\green255\blue255;
                     14: \red0\green255\blue0;
                     15: \red255\green0\blue255;
                     16: \red255\green0\blue0;
                     17: \red255\green255\blue0;
                     18: \red255\green255\blue255;
                     19: \red0\green0\blue127;
                     20: \red0\green127\blue127;
                     21: \red0\green127\blue0;
                     22: \red127\green0\blue127;
                     23: \red127\green0\blue0;
                     24: \red127\green127\blue0;
                     25: \red127\green127\blue127;
                     26: \red192\green192\blue192;}
                     27: 
                     28: 
                     29: {\stylesheet
                     30: \fs12 \snext0 Normal;
                     31: \s2\keepn \b\f2\fs28 \sbasedon0\snext2 Title;
                     32: \s3\li720 \sbasedon0\snext3 Body;
                     33: \s4\li270\sb60\tx1440\tx2340 \sbasedon0\snext4 List;
                     34: \s5\fs20 \sbasedon3\snext5 JumpBody;
                     35: \s6\brdrb\brdrs\brdrw30\brsp20\brdrcf2 \b\f2\fs28 \sbasedon0\snext6 PopUpTitle;
                     36: \s7\li180\fs20 \sbasedon5\snext7 PopUpBody;
                     37: \s8\fi-1886\li2160\tx1440\tx2340 \sbasedon4\snext8 GlossaryEntry;
                     38: \s9\li360\keep \f1\fs8\lang1024 \snext0 FixedText;
                     39: \s10\f1\fs20\up6\lang1024 \snext0 ControlCodes;
                     40: \s242\tqc\tx4320\tqr\tx8640 \fs20\lang1024 \sbasedon0\snext242 footer;
                     41: \s244\fs16\up6\lang1024 \sbasedon0\snext0 footnote reference;
                     42: \s245\fs20\lang1024 \sbasedon0\snext245 footnote text;}
                     43: 
                     44: \s10\f1\fs20\up6\lang1024
                     45: #{\footnote {#} Contents}
                     46: ${\footnote {$} Debug Event Browser Contents}
                     47: K{\footnote {K} Contents}
                     48: \s6\brdrb\brdrs\brdrw30\brsp20\brdrcf2 \b\f2\fs28
                     49: \{bmc deb.bmp\} Debug Event Browser Contents\par
                     50: \pard\plain
                     51: \s4\li270\sb60\tx1440\tx2340
                     52: {\b Overviews}\line
                     53: {\uldb General Overview}{\v GenOverview}\line
                     54: {\uldb Programming Overview}{\v ProgOverview}\line
                     55: {\b How to...}\line
                     56: {\uldb Using the Toolbar}{\v Toolbar}\line
                     57: {\b Commands}\line
                     58: {\uldb File Menu}{\v File}\line
                     59: {\uldb Edit Menu}{\v Edit}\line
                     60: {\uldb Options Menu}{\v Options}\line
                     61: {\uldb Help Menu}{\v Help}\line
                     62: {\uldb Keyboard}{\v Keyboard}\par
                     63: \pard\plain
                     64: \page
                     65: 
                     66: 
                     67: \s10\f1\fs20\up6\lang1024
                     68: #{\footnote {#} GenOverview}
                     69: ${\footnote {$} General Overview}
                     70: K{\footnote {K} Overview - General}
                     71: K{\footnote {K} Overviews}
                     72: \s6\brdrb\brdrs\brdrw30\brsp20\brdrcf2 \b\f2\fs28
                     73: Debug Event Browser General Overview\par
                     74: \pard\plain
                     75: \s4\li270\sb60\tx1440\tx2340
                     76: {\b Debug Event Browser} ({\b DEB}) is a Win32 application demonstrating the Win32 debug API.
                     77:   This preliminary version of {\b DEB} only performs the most rudimentary debugging operations.
                     78:   {\b DEB} is not a debugger in the traditional sense but a browser which merely displays the debug events occurring in a debugee.
                     79:   The handling of debug events is restricted only to those actions which are necessary to display event information and continue the debugee.\par
1.1.1.2 ! root       80: \par
        !            81: {\b This Sample is brought to you by:}\par
        !            82: {\b Microsoft Developer Support}\par
        !            83: {\b Microsoft Win32 SDK Support Team}\par
        !            84: {\b Developed by Paul Tissue.}\par
1.1       root       85: \pard\plain
                     86: \page
                     87: 
                     88: 
                     89: \s10\f1\fs20\up6\lang1024
                     90: #{\footnote {#} ProgOverview}
                     91: ${\footnote {$} Programming Overview}
                     92: K{\footnote {K} Programming}
                     93: K{\footnote {K} Overview - Programming}
                     94: K{\footnote {K} Overviews}
                     95: \s6\brdrb\brdrs\brdrw30\brsp20\brdrcf2 \b\f2\fs28
                     96: Debug Event Browser Programming Overview\par
                     97: \pard\plain
                     98: \s4\li270\sb60\tx1440\tx2340
                     99: The {\b Debug Event Browser} ({\b DEB}) sample demonstrates the following Win32 debug API features:\par
                    100: \s4\li270\sb60\tx1440\tx2340
                    101: {\uldb Debug Event Handler}{\v Handler}\line
                    102: {\uldb Modifying a Thread's Context}{\v Context}\line
                    103: {\uldb Reading the Executable's Header}{\v Header}\par
                    104: \pard\plain
                    105: \page
                    106: 
                    107: 
                    108: \s10\f1\fs20\up6\lang1024
                    109: #{\footnote {#} Handler}
                    110: ${\footnote {$} Debug Event Handler}
                    111: K{\footnote {K} Debug Event Handler}
                    112: K{\footnote {K} Debug API}
                    113: K{\footnote {K} WaitForDebugEvent}
                    114: K{\footnote {K} ContinueDebugEvent}
                    115: \s6\brdrb\brdrs\brdrw30\brsp20\brdrcf2 \b\f2\fs28
                    116: Debug Event Handler\par
                    117: \pard\plain
                    118: \s4\li270\sb60\tx1440\tx2340
                    119: The debug event handler is responsible for the processing of the debug events.\par
                    120: \par
                    121: \pard\plain
                    122: \s9\li360\keep \f1\fs20\lang1024
                    123: // ************************************************************************\line
                    124: // FUNCTION : DebugEventThread( DWORD )\line
                    125: // PURPOSE  : Main debug event processing loop\line
                    126: // ************************************************************************\line
                    127: DWORD\line
                    128: DebugEventThread( DWORD UserDefinedValue )\line
                    129: \{\line
                    130:   DEBUG_EVENT  DebugEvent;\line
                    131: \line
                    132:   for(;;) \{\line
                    133:     if( !WaitForDebugEvent( &DebugEvent, (DWORD) -1 ) ) \line
                    134:       continue;\line
                    135: \line
                    136:     switch( DebugEvent.dwDebugEventCode ) \{\line
                    137: \line
                    138:       case EXCEPTION_DEBUG_EVENT:\line
                    139:         // ...\line
                    140: \line
                    141:         switch( DebugEvent.u.Exception.ExceptionRecord.ExceptionCode \line
                    142: \line
                    143:           case EXCEPTION_ACCESS_VIOLATION:\line
                    144:             // ...\line
                    145:             break;\line
                    146: \line
                    147:           case EXCEPTION_BREAKPOINT:\line
                    148:             // ...\line
                    149:             break;\line
                    150: \line
                    151:           //...\line
                    152: \line
                    153:           default:  // An unknown exception occurred\line
                    154:             // ...\line
                    155:             break;\line
                    156:         \}\line
                    157: \line
                    158:       case CREATE_THREAD_DEBUG_EVENT:\line
                    159:         // ...\line
                    160:         break;\line
                    161: \line
                    162:       case CREATE_PROCESS_DEBUG_EVENT:\line
                    163:         // ...\line
                    164:         break;\line
                    165: \line
                    166:       // ...\line
                    167: \line
                    168:       default:\line
                    169:         // ...\line
                    170:     \}\line
                    171: \line
                    172:     //-- default action - just continue\line
                    173:     ContinueDebugEvent( DebugEvent.dwProcessId, DebugEvent.dwThreadId,\line
                    174:       DBG_CONTINUE );\line
                    175:   \}\line
                    176: \line
                    177:   return( NULL );\line
                    178: \}\par
                    179: \pard\plain
                    180: \page
                    181: 
                    182: 
                    183: \s10\f1\fs20\up6\lang1024
                    184: #{\footnote {#} Header}
                    185: ${\footnote {$} Reading the Executable's Header}
                    186: K{\footnote {K} Executable Header}
                    187: K{\footnote {K} Image Header}
                    188: K{\footnote {K} Debug API}
                    189: K{\footnote {K} ReadProcessMemory}
                    190: \s6\brdrb\brdrs\brdrw30\brsp20\brdrcf2 \b\f2\fs28
                    191: Reading the Executable's Header\par
                    192: \pard\plain
                    193: \s4\li270\sb60\tx1440\tx2340
                    194: Reading the information stored in the executable's headers is important for obtaining such things as symbolic information and details about the object.\par
                    195: \par
                    196: \pard\plain
                    197: \s9\li360\keep \f1\fs20\lang1024
                    198: // ************************************************************************\line
                    199: // FUNCTION : GetModuleFileNameFromHeader( HANDLE, HANDLE, LPTSTR, DWORD )\line
                    200: // PURPOSE  : returns the DLL module name for a given file handle of a\line
                    201: //            the module.  Reads the module name from the EXE header.\line
                    202: // COMMENTS : returns only the module name and not the pathname\line
                    203: // ************************************************************************\line
                    204: DWORD APIENTRY\line
                    205: GetModuleFileNameFromHeader( HANDLE hProcess, HANDLE hFile, LPTSTR lpszPath, \line
                    206:   DWORD bPath )\line
                    207: \{\line
                    208:   #define IMAGE_DOS_SIGNATURE     0x5A4D      // MZ\line
                    209:   #define IMAGE_OS2_SIGNATURE     0x454E      // NE\line
                    210:   #define IMAGE_NT_SIGNATURE      0x00004550  // PE00\line
                    211: \line
                    212:   #define IMAGE_SECOND_HEADER_OFFSET     (15 * sizeof(ULONG)) \line
                    213:   #define IMAGE_BASE_OFFSET              (13 * sizeof(DWORD)) \line
                    214:   #define IMAGE_EXPORT_TABLE_RVA_OFFSET  (30 * sizeof(DWORD)) \line
                    215:   #define IMAGE_NAME_RVA_OFFSET           (3 * sizeof(DWORD)) \line
                    216: \line
                    217:   WORD   DosSignature;\line
                    218:   DWORD  NtSignature;\line
                    219:   DWORD  NumberOfBytesRead;\line
                    220: \line
                    221:   DWORD  PeHeader, ImageBase, ExportTableRVA, NameRVA;\line
                    222: \line
                    223:   //-- Extract the filename from the EXE header\line
                    224:   ReadFile( hFile, &DosSignature, sizeof(DosSignature), &NumberOfBytesRead,\line
                    225:     (LPOVERLAPPED) NULL);\line
                    226: \line
                    227:   if( DosSignature == IMAGE_DOS_SIGNATURE ) \{\line
                    228: \line
                    229:     SetFilePointer( hFile, IMAGE_SECOND_HEADER_OFFSET, (LPLONG) NULL,\line
                    230:       FILE_BEGIN );\line
                    231:     ReadFile( hFile, &PeHeader, sizeof(PeHeader),\line
                    232:       &NumberOfBytesRead, (LPOVERLAPPED) NULL );\line
                    233: \line
                    234:     SetFilePointer( hFile, PeHeader, (LPLONG) NULL,\line
                    235:       FILE_BEGIN );\line
                    236:     ReadFile( hFile, &NtSignature, sizeof(NtSignature),\line
                    237:       &NumberOfBytesRead, (LPOVERLAPPED) NULL);\line
                    238: \line
                    239:     if( NtSignature == IMAGE_NT_SIGNATURE ) \{\line
                    240: \line
                    241:       SetFilePointer( hFile, PeHeader+IMAGE_BASE_OFFSET,\line
                    242:          (LPLONG) NULL, FILE_BEGIN );\line
                    243:       ReadFile( hFile, &ImageBase, sizeof(ImageBase),\line
                    244:         &NumberOfBytesRead, (LPOVERLAPPED) NULL);\line
                    245: \line
                    246:       SetFilePointer( hFile, PeHeader + IMAGE_EXPORT_TABLE_RVA_OFFSET,\line
                    247:          (LPLONG) NULL, FILE_BEGIN );\line
                    248:       ReadFile( hFile, &ExportTableRVA, sizeof(ExportTableRVA),\line
                    249:         &NumberOfBytesRead, (LPOVERLAPPED) NULL);\line
                    250: \line
                    251:       //-- now read from the virtual address space in the process\line
                    252:       ReadProcessMemory( hProcess,\line
                    253:         (LPVOID) (ImageBase + ExportTableRVA + IMAGE_NAME_RVA_OFFSET),\line
                    254:         &NameRVA, sizeof(NameRVA), &NumberOfBytesRead );\line
                    255: \line
                    256:       ReadProcessMemory( hProcess,\line
                    257:          (LPVOID) (ImageBase+NameRVA),\line
                    258:          lpszPath, cbPath, &NumberOfBytesRead );\line
                    259: \line
                    260:       return( NumberOfBytesRead );\line
                    261:     \}\line
                    262:   \}\line
                    263:   return( 0 );\line
                    264: \}\par
                    265: \pard\plain
                    266: \page
                    267: 
                    268: 
                    269: \s10\f1\fs20\up6\lang1024
                    270: #{\footnote {#} Context}
                    271: ${\footnote {$} Modifying a Thread's Context}
                    272: K{\footnote {K} Thread Context}
                    273: K{\footnote {K} Context}
                    274: K{\footnote {K} Debug API}
                    275: K{\footnote {K} GetThreadContext}
                    276: K{\footnote {K} SetThreadContext}
                    277: \s6\brdrb\brdrs\brdrw30\brsp20\brdrcf2 \b\f2\fs28
                    278: Modifying a Thread's Context\par
                    279: \pard\plain
                    280: \s4\li270\sb60\tx1440\tx2340
                    281: The ability to query and modify a thread's context is one of the more powerful features of the Win32 debug API set.\par
                    282: \par
                    283: \pard\plain
                    284: \s9\li360\keep \f1\fs20\lang1024
                    285: // ************************************************************************\line
                    286: // FUNCTION : SkipThreadBreakPoint( DWORD );\line
                    287: // PURPOSE  : Skip over the break point instruction belonging to dwThreadId\line
                    288: // COMMENTS : Only the MIPS R4000 needs this\line
                    289: // ************************************************************************\line
                    290: BOOL\line
                    291: SkipBreakPoint( DWORD dwThreadId )\line
                    292: \{\line
                    293:   CONTEXT  Context;\line
                    294: \line
                    295:   // insert code here to get hThread given dwThreadId\line
                    296: \line
                    297:   Context.ContextFlags = CONTEXT_CONTROL;\line
                    298:   if( !GetThreadContext( hThread, &Context ) )\line
                    299:     return( FALSE );\line
                    300: \line
                    301:   Context.Fir += 4L;  // Fir is the PC (program counter)\line
                    302:                       //   BREAK (breakpoint instruction) occupies 4 bytes\line
                    303: \line
                    304:   SetThreadContext( (ThreadNode->NodeData).hThread, &Context );\line
                    305: \line
                    306:   return( TRUE );\line
                    307: \}\par
                    308: \pard\plain
                    309: \page
                    310: 
                    311: 
                    312: \s10\f1\fs20\up6\lang1024
                    313: #{\footnote {#} File}
                    314: ${\footnote {$} File Menu}
                    315: K{\footnote {K} File Menu}
                    316: K{\footnote {K} Menu Commands}
                    317: \s6\brdrb\brdrs\brdrw30\brsp20\brdrcf2 \b\f2\fs28
                    318: The File Menu\par
                    319: \pard\plain
                    320: \s4\li270\sb60\tx1440\tx2340
                    321: Allows the user to select the debugee for this application.\line\line
                    322: {\b Open}\line
                    323: Displays a dialog box that will allow you to open and run an executable file using a common dialog box.  This executable file will become the debugee.\line\line
                    324: {\b Attach}\line
                    325: Displays a dialog box that will allow you to select a currently running process to attach to.  This process will become the debugee.\line\line
                    326: {\b Exit}\line
                    327: Exits the {\b Debug Event Browser} application.\par
                    328: \pard\plain
                    329: \page
                    330: 
                    331: 
                    332: \s10\f1\fs20\up6\lang1024
                    333: #{\footnote {#} Edit}
                    334: ${\footnote {$} Edit Menu}
                    335: K{\footnote {K} Edit Menu}
                    336: K{\footnote {K} Menu Commands}
                    337: \s6\brdrb\brdrs\brdrw30\brsp20\brdrcf2 \b\f2\fs28
                    338: The Edit Menu\par
                    339: \pard\plain
                    340: \s4\li270\sb60\tx1440\tx2340
                    341: Allows the user to copy text to the clipboard.\line\line
                    342: {\b Cut}\line
                    343: Copies the text in the Debug Event window and then delete it from the window.\line\line
                    344: {\b Copy}\line
                    345: Copies the text in the Debug Event window.\line\line
                    346: {\b Delete}\line
                    347: Deletes the text in the Debug Event window.\par
                    348: \pard\plain
                    349: \page
                    350: 
                    351: 
                    352: \s10\f1\fs20\up6\lang1024
                    353: #{\footnote {#} Options}
                    354: ${\footnote {$} Options Menu}
                    355: K{\footnote {K} Options Menu}
                    356: K{\footnote {K} Menu Commands}
                    357: \s6\brdrb\brdrs\brdrw30\brsp20\brdrcf2 \b\f2\fs28
                    358: The Options Menu\par
                    359: \pard\plain
                    360: \s4\li270\sb60\tx1440\tx2340
                    361: Allows the user to set various options and preferences for this application.\line\line
                    362: {\b Fonts}\line
                    363: Displays a dialog box that will allow you to set the font for the Debug Event window.\line\line
                    364: {\b Background Color}\line
                    365: Displays a dialog box that will allow you to set the background color for the Debug Event window.\line\line
                    366: {\b Preferences}\line
                    367: Displays a dialog box that will allow you to set the options and preferences for this application.\line\line
                    368: {\b Toolbar}\line
                    369: Displays a Tool Bar when checked.\line\line
                    370: {\b Use Saved Directory}\line
                    371: This menu option will set the default directory to the one that was previously saved.  This only occurs when checked.\line\line
                    372: {\b Save Settings On Exit}\line
                    373: This menu option will save all the current session settings.\par
                    374: \pard\plain
                    375: \page
                    376: 
                    377: 
                    378: \s10\f1\fs20\up6\lang1024
                    379: #{\footnote {#} Help}
                    380: ${\footnote {$} Help Menu}
                    381: K{\footnote {K} Help Menu}
                    382: K{\footnote {K} Menu Commands}
                    383: \s6\brdrb\brdrs\brdrw30\brsp20\brdrcf2 \b\f2\fs28
                    384: The Help Menu\par
                    385: \pard\plain
                    386: \s4\li270\sb60\tx1440\tx2340
                    387: Displays various types of information regarding to the {\b Debug Event Browser} application.\line\line
                    388: {\b Contents}\line
                    389: Displays the contents of the Online Help.\line\line
                    390: {\b Search for Help on...}\line
                    391: Displays a list of keywords to search for Online Help topics.\line\line
                    392: {\b How to use Help}\line
                    393: Displays the instructions for using the Online Help facilities.\line\line
                    394: {\b About {\b DEB}...}\line
                    395: Displays information about the {\b Debug Event Browser}.\par
                    396: \pard\plain
                    397: \page
                    398: 
                    399: 
                    400: \s10\f1\fs20\up6\lang1024
                    401: #{\footnote {#} Keyboard}
                    402: ${\footnote {$} Keyboard Commands}
                    403: K{\footnote {K} Keyboard Commands}
                    404: \s6\brdrb\brdrs\brdrw30\brsp20\brdrcf2 \b\f2\fs28
                    405: Keyboard Commands\par
                    406: \pard\plain
                    407: \s4\li270\sb60\tx1440\tx2340
                    408: The keyboard commands allows quick and convenient access to several {\b Debug Event Browser} options simply with the pressing of one key.\line\line
                    409: {\b Ctrl+X}\line
                    410: Copies the text in the Debug Event window and then delete it from the window.\line\line
                    411: {\b Ctrl+C}\line
                    412: Copies the text in the Debug Event window.\line\line
                    413: {\b Del}\line
                    414: Deletes the text in the Debug Event window.\par
                    415: \pard\plain
                    416: \page
                    417: 
                    418: 
                    419: \s10\f1\fs20\up6\lang1024
                    420: #{\footnote {#} Toolbar}
                    421: ${\footnote {$} Toolbar}
                    422: K{\footnote {K} Toolbar}
                    423: \s6\brdrb\brdrs\brdrw30\brsp20\brdrcf2 \b\f2\fs28
                    424: Toolbar\par
                    425: \pard\plain
                    426: \s4\li270\sb60\tx1440\tx2340
                    427: The Toolbar allows quick and convenient access to several {\b Debug Event Browser} options simply with the click of the mouse.\par\par
                    428: \pard\plain
                    429: \qc \{bmc toolbar.bmp\}\par
                    430: \pard\plain
                    431: \page
                    432: 
                    433: 
                    434: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.