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.

204 lines
4.4 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: decode.c
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 8-10-95 RichardW Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <windows.h>
  18. #include <ntsdexts.h>
  19. #include "ber.h"
  20. #include "rsa.h"
  21. PNTSD_EXTENSION_APIS pExtApis;
  22. HANDLE hDbgThread;
  23. HANDLE hDbgProcess;
  24. extern BOOL BerVerbose;
  25. #define DebuggerOut (pExtApis->lpOutputRoutine)
  26. #define GetSymbol (pExtApis->lpGetSymbolRoutine)
  27. #define GetExpr (PVOID) (pExtApis->lpGetExpressionRoutine)
  28. #define InitDebugHelp(hProc,hThd,pApis) {hDbgProcess = hProc; hDbgThread = hThd; pExtApis = pApis;}
  29. #define ExitIfCtrlC() if (pExtApis->lpCheckControlCRoutine()) return;
  30. #define BreakIfCtrlC() if (pExtApis->lpCheckControlCRoutine()) break;
  31. int
  32. ReadMemory( PVOID pvAddress,
  33. ULONG cbMemory,
  34. PVOID pvLocalMemory)
  35. {
  36. SIZE_T cbActual = cbMemory;
  37. if (ReadProcessMemory(hDbgProcess, pvAddress, pvLocalMemory, cbMemory, &cbActual))
  38. {
  39. if (cbActual != cbMemory)
  40. {
  41. return(-1);
  42. }
  43. return(0);
  44. }
  45. return(GetLastError());
  46. }
  47. void
  48. BERDecode(HANDLE hProcess,
  49. HANDLE hThread,
  50. DWORD dwCurrentPc,
  51. PNTSD_EXTENSION_APIS lpExt,
  52. LPSTR pszCommand)
  53. {
  54. PUCHAR pbBuffer;
  55. PVOID pRemote;
  56. DWORD cb;
  57. UCHAR Short[8];
  58. DWORD len;
  59. DWORD i;
  60. DWORD Length;
  61. CHAR Buf[80];
  62. PSTR pBuf;
  63. PUCHAR End;
  64. UCHAR Type;
  65. PSTR pszNext;
  66. DWORD Flags;
  67. DWORD headerLength ;
  68. PUCHAR Scan ;
  69. InitDebugHelp(hProcess, hThread, lpExt);
  70. Flags = 0;
  71. while ( *pszCommand == '-' )
  72. {
  73. pszCommand++;
  74. if ( *pszCommand == 'v' )
  75. {
  76. Flags |= DECODE_VERBOSE_OIDS ;
  77. }
  78. if ( *pszCommand == 'n' )
  79. {
  80. Flags |= DECODE_NEST_OCTET_STRINGS ;
  81. }
  82. pszCommand++;
  83. pszCommand++;
  84. }
  85. pszNext = strchr(pszCommand, ' ');
  86. if (pszNext)
  87. {
  88. *pszNext++ = '\0';
  89. }
  90. pRemote = GetExpr(pszCommand);
  91. if (pszNext)
  92. {
  93. cb = (DWORD)((ULONG_PTR)GetExpr(pszNext));
  94. }
  95. else
  96. {
  97. ReadMemory(pRemote, 4, Short);
  98. if (Short[1] & 0x80)
  99. {
  100. headerLength = Short[1] & 0x7F ;
  101. cb = 0 ;
  102. Scan = &Short[2];
  103. ReadMemory( pRemote, headerLength + 1, Short );
  104. while ( headerLength )
  105. {
  106. cb = (cb << 8) + *Scan ;
  107. headerLength-- ;
  108. Scan++ ;
  109. }
  110. }
  111. else
  112. {
  113. cb = Short[1];
  114. }
  115. }
  116. pbBuffer = LocalAlloc(LMEM_FIXED, cb + 4);
  117. if (!pbBuffer)
  118. {
  119. DebuggerOut("Failed to alloc mem\n");
  120. return;
  121. }
  122. DebuggerOut("Size is %d (%#x) bytes\n", cb, cb);
  123. ReadMemory(pRemote, cb + 4, pbBuffer);
  124. ber_decode(lpExt->lpOutputRoutine,
  125. lpExt->lpCheckControlCRoutine,
  126. pbBuffer,
  127. Flags,
  128. 0, 0, cb + 4, 0);
  129. }
  130. void
  131. DumpKey(HANDLE hProcess,
  132. HANDLE hThread,
  133. DWORD dwCurrentPc,
  134. PNTSD_EXTENSION_APIS lpExt,
  135. LPSTR pszCommand)
  136. {
  137. BSAFE_PUB_KEY Pub;
  138. BSAFE_PRV_KEY Prv;
  139. PVOID Key;
  140. DWORD KeyType;
  141. DWORD Bits;
  142. BSAFE_KEY_PARTS Parts;
  143. DWORD PubSize;
  144. DWORD PrvSize;
  145. InitDebugHelp(hProcess, hThread, lpExt);
  146. Key = GetExpr(pszCommand);
  147. ReadMemory( Key, sizeof(DWORD), &KeyType );
  148. if ((KeyType != RSA1) && (KeyType != RSA2))
  149. {
  150. DebuggerOut("not an rsa key\n");
  151. return;
  152. }
  153. ReadMemory( Key, sizeof(BSAFE_PUB_KEY), &Pub );
  154. Bits = Pub.bitlen;
  155. }