Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
2.7 KiB

  1. /*-----------------------------------------------------------------------------
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module:
  4. exts.c
  5. Sample old windbg style interface using extension
  6. ------------------------------------------------------------------------------*/
  7. #include "simple.h"
  8. //
  9. // Extension to read and dump dwords from target
  10. //
  11. DECLARE_API( read )
  12. {
  13. ULONG cb;
  14. ULONG64 Address;
  15. ULONG Buffer[4];
  16. Address = GetExpression(args);
  17. // Read and display first 4 dwords at Address
  18. if (ReadMemory(Address, &Buffer, sizeof(Buffer), &cb) && cb == sizeof(Buffer)) {
  19. dprintf("%I64lx: %08lx %08lx %08lx %08lx\n\n", Address,
  20. Buffer[0], Buffer[1], Buffer[2], Buffer[3]);
  21. }
  22. }
  23. //
  24. // Extension to edit a dword on target
  25. //
  26. // !edit <address> <value>
  27. //
  28. DECLARE_API( edit )
  29. {
  30. ULONG cb;
  31. ULONG64 Address;
  32. ULONG Value;
  33. if (GetExpressionEx(args, &Address, &args)) {
  34. Value = (ULONG) GetExpression( args);
  35. } else {
  36. dprintf("Usage: !edit <address> <value>\n");
  37. return;
  38. }
  39. // Read and display first 4 dwords at Address
  40. if (WriteMemory(Address, &Value, sizeof(Value), &cb) && cb == sizeof(Value)) {
  41. dprintf("%I64lx: %08lx\n", Address, Value);
  42. }
  43. }
  44. //
  45. // Extension to dump stacktrace
  46. //
  47. DECLARE_API ( stack )
  48. {
  49. EXTSTACKTRACE64 stk[20];
  50. ULONG frames, i;
  51. CHAR Buffer[256];
  52. ULONG64 displacement;
  53. // Get stacktrace for surrent thread
  54. frames = StackTrace( 0, 0, 0, stk, 20 );
  55. if (!frames) {
  56. dprintf("Stacktrace failed\n");
  57. }
  58. for (i=0; i<frames; i++) {
  59. if (i==0) {
  60. dprintf( "ChildEBP RetAddr Args to Child\n" );
  61. }
  62. Buffer[0] = '!';
  63. GetSymbol(stk[i].ProgramCounter, (PUCHAR)Buffer, &displacement);
  64. dprintf( "%08p %08p %08p %08p %08p %s",
  65. stk[i].FramePointer,
  66. stk[i].ReturnAddress,
  67. stk[i].Args[0],
  68. stk[i].Args[1],
  69. stk[i].Args[2],
  70. Buffer
  71. );
  72. if (displacement) {
  73. dprintf( "+0x%p", displacement );
  74. }
  75. dprintf( "\n" );
  76. }
  77. }
  78. /*
  79. A built-in help for the extension dll
  80. */
  81. DECLARE_API ( help )
  82. {
  83. dprintf("Help for extension dll simple.dll\n"
  84. " read <addr> - It reads and dumps 4 dwords at <addr>\n"
  85. " edit <addr> <val> - It modifies a dword value to <val> at <addr>\n"
  86. " stack - Printd current stack trace\n"
  87. " help - Shows this help\n"
  88. );
  89. }