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.

4564 lines
136 KiB

  1. //+-----------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) Microsoft Corporation 1991 - 1992
  6. //
  7. // File:
  8. //
  9. // Contents:
  10. //
  11. //
  12. // History:
  13. //
  14. //------------------------------------------------------------------------
  15. extern "C"
  16. {
  17. #include "lsasrvp.h"
  18. #include "ausrvp.h"
  19. #include "spmgr.h"
  20. #include "sidcache.h"
  21. }
  22. #include <stdio.h>
  23. #include <malloc.h>
  24. #include <dbghelp.h>
  25. #include <ntsdexts.h>
  26. #include <dsysdbg.h>
  27. #define SECURITY_PACKAGE
  28. #include <security.h>
  29. #include <secint.h>
  30. #include <cryptdll.h>
  31. #include "debugp.h"
  32. #include "..\spmgr.h"
  33. #include "..\sphelp.h"
  34. #include "..\sesmgr.h"
  35. #include "..\scavenge.hxx"
  36. #include "..\negotiat.hxx"
  37. #include "..\sht.hxx"
  38. #include "..\lht.hxx"
  39. #define DBP_TYPES_ONLY
  40. #include "..\dspolicy\dbp.h"
  41. #define LSAEXTS
  42. #include "..\dspolicy\dbftrust.h"
  43. #define FlagSize(x) (sizeof(x) / sizeof(char *))
  44. char * AccessMask[] = { "Delete", "ReadControl", "WriteDac", "WriteOwner",
  45. "Synch", "", "", "",
  46. "Sacl", "MaxAllowed", "", "",
  47. "GenericAll", "GenericExec", "GenericWrite", "GenericRead"};
  48. char * HandleFlags[] = { "Locked", "DeletePending", "NoCallback" };
  49. char * LhtFlags[] = { "NoSerialize", "Callback", "Unique",
  50. "Child", "LimitDepth", "DeletePending", "NoFree"};
  51. char * LhtSubFlags[] = { "SubTable" };
  52. char * ShtFlags[] = { "NoSerialize", "Callback", "Unique",
  53. "NoFree", "DeletePending" };
  54. char * ScavFlags[] = { "NewThread", "One Shot", "FreeHandle", "",
  55. "", "", "", "",
  56. "", "", "", "", "", "", "", "",
  57. "", "", "", "", "", "", "", "",
  58. "", "TriggerFree", "StateChange", "Immediate",
  59. "DebugBreak", "AboutToDie", "InProgress", "Seconds" };
  60. char * ScavClasses[] = { "<Invalid>", "PackageChange" };
  61. #define ScavClassName(x) (x < (sizeof(ScavClasses) / sizeof(char *) ) ? \
  62. ScavClasses[ x ] : "<Invalid>" )
  63. char * QueueTypes[] = { "Shared", "Single", "ShareRead", "Zombie" };
  64. #define QueueTypeName(x) (x < (sizeof( QueueTypes ) / sizeof( char * ) ) ? \
  65. QueueTypes[ x ] : "<Invalid>" )
  66. char * SessFlags[] = { "Queue", "TcbPriv", "Clone", "Impersonate",
  67. "Desktop", "Untrusted", "InProc", "Autonomous",
  68. "Default", "Unload", "Scavenger", "Cleanup",
  69. "Kernel", "Restricted", "MaybeKernel", "EFS",
  70. "Shadow", "Wow64", "", "",
  71. "", "", "", "",
  72. "", "", "", "",
  73. "", "", "", "" };
  74. char * PackageFlags[] = {"Invalid", "Unload", "Never Load", "Internal", "Never Call",
  75. "Preferred", "Delete", "Info", "ContextThunk", "Shutdown Pending",
  76. "Shutdown", "WowSupport", "", "", "", "", "AuthPkg"
  77. };
  78. char * Capabilities[] = {"Sign/Verify", "Seal/Unseal", "Token Only", "Datagram",
  79. "Connection", "Multi-Required", "ClientOnly", "ExtError",
  80. "Impersonation", "Win32Name", "Stream", "Negotiable",
  81. "GSS Compat", "Logon", "AsciiBuffer", "Fragment",
  82. "MutualAuth", "Delegation", "", "",
  83. "", "", "", ""
  84. };
  85. char * APIFlags[] = {"Error", "Memory", "PrePack", "GetState",
  86. "AnsiCall", "HandleChange", "CallBack", "VmAlloc",
  87. "ExecNow", "Win32Error", "KMap Mem", ""
  88. };
  89. char * CallInfoFlags[] = { "Kernel", "Ansi", "Urgent", "Recursive",
  90. "InProc", "Cleanup", "WowClient", ""
  91. };
  92. char * LsaCallInfoFlags[] = { "Impersonating", "InProcCall", "SupressAudits",
  93. "NoHandleCheck", "KernelPool", "KMap Used" };
  94. char * NegCredFlags[] = { "DefaultPlaceholder","Default","Multi",
  95. "UseSnego","Kernel","Explicit", "MultiPart",
  96. "AllowNtlm", "NegNtlm", "NtlmLoopback" };
  97. char * NegContextFlags[] = { "PackageCalled", "FreeEachMech",
  98. "Negotiating", "Fragmenting",
  99. "FragInbound", "FragOutbound",
  100. "Uplevel", "MutualAuth", };
  101. char * NegPackageFlags[] = { "Preferred", "NT4", "ExtraOID", "Inbound",
  102. "Outbound", "Loopback" };
  103. char * SDFlags[] = {"OwnerDef","GroupDef","DaclPresent","DaclDef","SaclPresent",
  104. "SaclDef","SelfRelative"};
  105. char * ImpLevels[] = {"Anonymous", "Identification", "Impersonation", "Delegation"};
  106. #define ImpLevel(x) ((x < (sizeof(ImpLevels) / sizeof(char *))) ? ImpLevels[x] : "Illegal!")
  107. char * SecBufferTypes[] = {"Empty", "Data", "Token", "Package", "Missing", "Extra",
  108. "Trailer", "Header" };
  109. #define SecBufferType(x) (((x & ~(SECBUFFER_ATTRMASK)) < (sizeof(SecBufferTypes) / sizeof(char *))) ? \
  110. SecBufferTypes[ (x & ~(SECBUFFER_ATTRMASK)) ] : "Invalid" )
  111. char * LogonTypes[] = {"Invalid", "Invalid",
  112. "Interactive",
  113. "Network",
  114. "Batch",
  115. "Service",
  116. "Proxy",
  117. "Unlock",
  118. "NetworkCleartext",
  119. "NewCredentials" };
  120. #define LogonTypeName( x ) ( ( x < sizeof( LogonTypes ) / sizeof( char * )) ? \
  121. LogonTypes[ x ] : "Invalid" )
  122. char * MessageNames[] = { "<Disconnect>",
  123. "<Connect>",
  124. "LsaLookupPackage",
  125. "LsaLogonUser",
  126. "LsaCallPackage",
  127. "LsaDeregisterLogonProcess",
  128. "<empty>",
  129. "(I) GetBinding",
  130. "(I) SetSession",
  131. "(I) FindPackage",
  132. "EnumeratePackages",
  133. "AcquireCredentialHandle",
  134. "EstablishCredentials",
  135. "FreeCredentialHandle",
  136. "InitializeSecurityContext",
  137. "AcceptSecurityContext",
  138. "ApplyControlToken",
  139. "DeleteSecurityContext",
  140. "QueryPackage",
  141. "GetUserInfo",
  142. "GetCredentials",
  143. "SaveCredentials",
  144. "DeleteCredentials",
  145. "QueryCredAttributes",
  146. "AddPackage",
  147. "DeletePackage",
  148. "GenerateKey",
  149. "GenerateDirEfs",
  150. "DecryptFek",
  151. "GenerateSessionKey",
  152. "Callback",
  153. "QueryContextAttributes",
  154. "PolicyChangeNotify",
  155. "GetUserName",
  156. "AddCredential",
  157. "EnumLogonSession",
  158. "GetLogonSessionData",
  159. "SetContextAttribute",
  160. "LookupAccountSid",
  161. "LookupAccountName",
  162. "<empty>" };
  163. #define ApiLabel(x) (((x+2) < sizeof(MessageNames) / sizeof(char *)) ? \
  164. MessageNames[(x+2)] : "[Illegal API Number!]")
  165. #define NAME_BASE "lsasrv"
  166. #define PACKAGE_LIST NAME_BASE "!pPackageControlList"
  167. #define PACKAGE_COUNT NAME_BASE "!PackageControlCount"
  168. #define DLL_COUNT NAME_BASE "!PackageDllCount"
  169. #define DLL_LIST NAME_BASE "!pPackageDllList"
  170. #define SESSION_LIST NAME_BASE "!SessionList"
  171. #define MEMORY_LIST NAME_BASE "!pLastBlock"
  172. #define TLS_SESSION NAME_BASE "!dwSession"
  173. #define PFASTMEM NAME_BASE "!pFastMem"
  174. #define CFASTMEM NAME_BASE "!cFastMem"
  175. #define FFASTMEM NAME_BASE "!fFastMemStats"
  176. #define MAXPOOLTHREADS NAME_BASE "!MaxPoolThreads"
  177. #define GLOBALQUEUE NAME_BASE "!GlobalQueue"
  178. #define SCAVLIST NAME_BASE "!ScavList"
  179. #define NOTIFYLIST NAME_BASE "!NotifyList"
  180. #define LPC_APILOG NAME_BASE "!LpcApiLog"
  181. #define INTERNAL_APILOG NAME_BASE "!InternalApiLog"
  182. #define FAULTINGTID NAME_BASE "!FaultingTid"
  183. #define EXCEPTIONINFO NAME_BASE "!dwExceptionInfo"
  184. #define TLS_CALLINFO NAME_BASE "!dwCallInfo"
  185. WCHAR *Packages[] = {L"Kerberos", L"NTLM", L"MSV" };
  186. #define AllocHeap(x) RtlAllocateHeap(RtlProcessHeap(), HEAP_ZERO_MEMORY, x)
  187. #define FreeHeap(x) RtlFreeHeap(RtlProcessHeap(), 0, x)
  188. void PrintToken(HANDLE, PNTSD_EXTENSION_APIS);
  189. void LocalDumpSid(PSID);
  190. PNTSD_EXTENSION_APIS pExtApis;
  191. HANDLE hDbgThread;
  192. HANDLE hDbgProcess;
  193. #define DebuggerOut (pExtApis->lpOutputRoutine)
  194. #define LsaGetSymbol (pExtApis->lpGetSymbolRoutine)
  195. #define GetExpr (PVOID) (pExtApis->lpGetExpressionRoutine)
  196. #define InitDebugHelp(hProc,hThd,pApis) {hDbgProcess = hProc; hDbgThread = hThd; pExtApis = pApis;}
  197. #define DBG_STACK_TRACE 8
  198. CHAR*
  199. SidNameUseXLate(
  200. INT i
  201. )
  202. {
  203. switch ( i ) {
  204. case SidTypeUser:
  205. return "User";
  206. case SidTypeGroup:
  207. return "Group";
  208. case SidTypeDomain:
  209. return "Domain";
  210. case SidTypeAlias:
  211. return "Alias";
  212. case SidTypeWellKnownGroup:
  213. return "WellKnownGroup";
  214. case SidTypeDeletedAccount:
  215. return "Deleted Account";
  216. case SidTypeInvalid:
  217. return "Invalid Sid";
  218. case SidTypeUnknown:
  219. return "Unknown Type";
  220. case SidTypeComputer:
  221. return "Computer";
  222. default:
  223. return "Really Unknown -- This is a bug";
  224. }
  225. }
  226. SECURITY_STATUS
  227. LsaReadMemory( PVOID pvAddress,
  228. ULONG cbMemory,
  229. PVOID pvLocalMemory)
  230. {
  231. SIZE_T cbActual = cbMemory;
  232. if (ReadProcessMemory(hDbgProcess, pvAddress, pvLocalMemory, cbMemory, &cbActual))
  233. {
  234. if (cbActual != cbMemory)
  235. {
  236. return(-1);
  237. }
  238. return(0);
  239. }
  240. return(GetLastError());
  241. }
  242. SECURITY_STATUS
  243. LsaWriteMemory(PVOID pvLocalMemory,
  244. ULONG cbMemory,
  245. PVOID pvAddress)
  246. {
  247. SIZE_T cbActual = cbMemory;
  248. if (WriteProcessMemory(hDbgProcess, pvAddress, pvLocalMemory, cbMemory, &cbActual))
  249. {
  250. if (cbActual != cbMemory)
  251. {
  252. return(-1);
  253. }
  254. return(0);
  255. }
  256. return(GetLastError());
  257. }
  258. DWORD
  259. GetDword(PVOID pvMemory)
  260. {
  261. DWORD dwVal;
  262. SIZE_T cbActual = sizeof(DWORD);
  263. if (ReadProcessMemory(hDbgProcess, pvMemory, &dwVal, sizeof(DWORD), &cbActual))
  264. {
  265. if (cbActual != sizeof(DWORD))
  266. {
  267. return((DWORD) -1);
  268. }
  269. return(dwVal);
  270. }
  271. return((DWORD) -1);
  272. }
  273. TEB *
  274. GetTeb(HANDLE hThread)
  275. {
  276. NTSTATUS Status;
  277. THREAD_BASIC_INFORMATION ThreadInfo;
  278. ULONG cbReturned;
  279. PTEB Teb;
  280. Status = NtQueryInformationThread( hThread,
  281. ThreadBasicInformation,
  282. &ThreadInfo,
  283. sizeof(ThreadInfo),
  284. &cbReturned);
  285. if (!NT_SUCCESS(Status))
  286. {
  287. DebuggerOut("Failed to read Teb, %x\n", Status);
  288. return(NULL);
  289. }
  290. Teb = (PTEB) AllocHeap(sizeof(TEB));
  291. if ( Teb )
  292. {
  293. LsaReadMemory(ThreadInfo.TebBaseAddress, sizeof(TEB), Teb);
  294. }
  295. return(Teb);
  296. }
  297. PVOID
  298. GetTlsFromTeb(
  299. ULONG Index,
  300. TEB * Teb)
  301. {
  302. return(Teb->TlsSlots[Index]);
  303. }
  304. SECURITY_STATUS
  305. GetTlsEntry(ULONG TlsValue,
  306. PVOID * ppvValue)
  307. {
  308. TEB * Teb;
  309. Teb = GetTeb(hDbgThread);
  310. if (!Teb)
  311. {
  312. DebuggerOut("Could not read teb for thread\n");
  313. return(STATUS_UNSUCCESSFUL);
  314. }
  315. *ppvValue = GetTlsFromTeb(TlsValue, Teb);
  316. FreeHeap(Teb);
  317. return(0);
  318. }
  319. void DisplayFlags( DWORD Flags,
  320. DWORD FlagLimit,
  321. char *flagset[],
  322. UCHAR * buffer)
  323. {
  324. char * offset;
  325. DWORD mask, test, i;
  326. DWORD scratch;
  327. if (!Flags) {
  328. strcpy((CHAR *)buffer, "None");
  329. return;
  330. }
  331. buffer[0] = '0';
  332. mask = 0;
  333. offset = (CHAR *) buffer;
  334. test = 1;
  335. for (i = 0 ; i < FlagLimit ; i++ ) {
  336. if (Flags & test) {
  337. scratch = sprintf(offset, "%s", flagset[i]);
  338. offset += scratch;
  339. mask |= test;
  340. if (Flags & (~mask)) {
  341. *offset++ = ',';
  342. }
  343. }
  344. test <<= 1;
  345. }
  346. }
  347. #define TIMEBUF_SZ 64
  348. char *Months[] = { "", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
  349. "Aug", "Sep", "Oct", "Nov", "Dec" };
  350. void CTimeStamp(
  351. PTimeStamp ptsTime,
  352. LPSTR pszTimeBuf,
  353. BOOL LocalOnly)
  354. {
  355. SYSTEMTIME stTime;
  356. FILETIME tLocal;
  357. SYSTEMTIME stLocal;
  358. if (ptsTime->HighPart == 0)
  359. {
  360. strcpy(pszTimeBuf, "<Zero>");
  361. return;
  362. }
  363. else if (ptsTime->HighPart >= 0x7FFFFFFF)
  364. {
  365. strcpy(pszTimeBuf, "<Never>");
  366. return;
  367. }
  368. FileTimeToLocalFileTime((LPFILETIME) ptsTime, &tLocal);
  369. FileTimeToSystemTime((LPFILETIME) ptsTime, &stTime);
  370. FileTimeToSystemTime(&tLocal, &stLocal);
  371. if ( LocalOnly )
  372. {
  373. sprintf( pszTimeBuf, "%02d:%02d:%02d.%03d",
  374. stLocal.wHour, stLocal.wMinute, stLocal.wSecond, stLocal.wMilliseconds);
  375. }
  376. else
  377. {
  378. sprintf(pszTimeBuf, "%02d:%02d:%02d.%03d, %s %02d, %d UTC (%02d:%02d %s %02d Local)", stTime.wHour,
  379. stTime.wMinute, stTime.wSecond, stTime.wMilliseconds,
  380. Months[stTime.wMonth], stTime.wDay, stTime.wYear,
  381. stLocal.wHour, stLocal.wMinute, Months[stLocal.wMonth], stLocal.wDay);
  382. }
  383. }
  384. void
  385. MapString(
  386. PSECURITY_STRING pClientString,
  387. PSECURITY_STRING pLocalString)
  388. {
  389. if (!pLocalString->Buffer)
  390. {
  391. pLocalString->Buffer = (PWSTR) AllocHeap(pClientString->Length + 2);
  392. pLocalString->MaximumLength = pClientString->Length + 2;
  393. }
  394. if ( !pLocalString->Buffer )
  395. {
  396. return;
  397. }
  398. RtlZeroMemory(pLocalString->Buffer, pLocalString->MaximumLength);
  399. if (!LsaReadMemory(pClientString->Buffer, pClientString->Length, pLocalString->Buffer))
  400. {
  401. pLocalString->Length = pClientString->Length;
  402. }
  403. else
  404. {
  405. DebuggerOut("\nWarning: could not read string @%p\n", pClientString->Buffer);
  406. }
  407. }
  408. BOOL
  409. MapSid(
  410. PSID RemoteSid,
  411. PSID * LocalSid
  412. )
  413. {
  414. SID Temp ;
  415. PSID Copy ;
  416. *LocalSid = NULL ;
  417. if ( RemoteSid == NULL )
  418. {
  419. return FALSE ;
  420. }
  421. if ( !LsaReadMemory( RemoteSid, sizeof( SID ), &Temp ) )
  422. {
  423. return FALSE ;
  424. }
  425. Copy = AllocHeap( RtlLengthSid( &Temp ) );
  426. if ( !Copy )
  427. {
  428. return FALSE ;
  429. }
  430. if ( !LsaReadMemory( RemoteSid, RtlLengthSid( &Temp ), Copy ) )
  431. {
  432. FreeHeap( Copy );
  433. return FALSE ;
  434. }
  435. *LocalSid = Copy ;
  436. return TRUE ;
  437. }
  438. WCHAR * GetPackageName(
  439. DWORD_PTR dwPackageId)
  440. {
  441. switch (dwPackageId)
  442. {
  443. case SPMGR_ID:
  444. return(L"SPMgr");
  445. default:
  446. return(L"");
  447. }
  448. }
  449. #define PACKAGE_VERBOSE 0x00000001
  450. #define PACKAGE_NOISY 0x00000002
  451. #define PACKAGE_TITLE 0x00000004
  452. void
  453. ShowPackageControl(
  454. PVOID Base,
  455. PLSAP_SECURITY_PACKAGE pSecPkgCtrl,
  456. DWORD fVerbose)
  457. {
  458. SECURITY_STRING sLocal;
  459. UCHAR buffer[ MAX_PATH ];
  460. ULONG_PTR Disp;
  461. PSECPKG_FUNCTION_TABLE pTable;
  462. sLocal.Buffer = NULL;
  463. MapString(&pSecPkgCtrl->Name, &sLocal);
  464. if (fVerbose & PACKAGE_TITLE)
  465. {
  466. DebuggerOut("Security Package Control structure at %p\n", Base);
  467. }
  468. DebuggerOut("ID \t%d\n", pSecPkgCtrl->dwPackageID);
  469. DebuggerOut("Name \t%ws\n", sLocal.Buffer);
  470. FreeHeap(sLocal.Buffer);
  471. if (fVerbose & PACKAGE_VERBOSE)
  472. {
  473. DisplayFlags(pSecPkgCtrl->fPackage, FlagSize(PackageFlags), PackageFlags, buffer);
  474. DebuggerOut(" Flags \t%#x: %s\n", pSecPkgCtrl->fPackage, buffer);
  475. DisplayFlags(pSecPkgCtrl->fCapabilities, 18, Capabilities, buffer);
  476. DebuggerOut(" Capabilities\t%#x: %s\n", pSecPkgCtrl->fCapabilities, buffer);
  477. DebuggerOut(" RPC ID \t%d\n", pSecPkgCtrl->dwRPCID);
  478. DebuggerOut(" Version \t%d\n", pSecPkgCtrl->Version );
  479. DebuggerOut(" TokenSize\t%d\n", pSecPkgCtrl->TokenSize );
  480. DebuggerOut(" Thunks \t%p\n", pSecPkgCtrl->Thunks );
  481. }
  482. sLocal.Buffer = NULL;
  483. if (fVerbose & PACKAGE_NOISY)
  484. {
  485. pTable = &pSecPkgCtrl->FunctionTable;
  486. DebuggerOut(" Function table:\n");
  487. LsaGetSymbol((ULONG_PTR)pTable->Initialize, buffer, &Disp);
  488. DebuggerOut(" Initialize \t%s\n", buffer);
  489. LsaGetSymbol((ULONG_PTR)pTable->GetInfo, buffer, &Disp);
  490. DebuggerOut(" GetInfo \t%s\n", buffer);
  491. LsaGetSymbol((ULONG_PTR)pTable->LogonUser, buffer, &Disp);
  492. DebuggerOut(" LogonUser \t%s\n", buffer);
  493. LsaGetSymbol((ULONG_PTR)pTable->AcceptCredentials, buffer, &Disp);
  494. DebuggerOut(" AcceptCreds \t%s\n", buffer);
  495. LsaGetSymbol((ULONG_PTR)pTable->AcquireCredentialsHandle, buffer, &Disp);
  496. DebuggerOut(" AcquireCreds \t%s\n", buffer);
  497. LsaGetSymbol((ULONG_PTR)pTable->FreeCredentialsHandle, buffer, &Disp);
  498. DebuggerOut(" FreeCreds \t%s\n", buffer);
  499. LsaGetSymbol((ULONG_PTR)pTable->SaveCredentials, buffer, &Disp);
  500. DebuggerOut(" SaveCredentials \t%s\n", buffer);
  501. LsaGetSymbol((ULONG_PTR)pTable->GetCredentials, buffer, &Disp);
  502. DebuggerOut(" GetCredentials \t%s\n", buffer);
  503. LsaGetSymbol((ULONG_PTR)pTable->DeleteCredentials, buffer, &Disp);
  504. DebuggerOut(" DeleteCredentials \t%s\n", buffer);
  505. LsaGetSymbol((ULONG_PTR)pTable->InitLsaModeContext, buffer, &Disp);
  506. DebuggerOut(" InitLsaModeContext \t%s\n", buffer);
  507. LsaGetSymbol((ULONG_PTR)pTable->LogonTerminated, buffer, &Disp);
  508. DebuggerOut(" LogonTerminated \t%s\n", buffer);
  509. LsaGetSymbol((ULONG_PTR)pTable->AcceptLsaModeContext, buffer, &Disp);
  510. DebuggerOut(" AcceptLsaModeContext\t%s\n", buffer);
  511. LsaGetSymbol((ULONG_PTR)pTable->DeleteContext, buffer, &Disp);
  512. DebuggerOut(" DeleteContext \t%s\n", buffer);
  513. LsaGetSymbol((ULONG_PTR)pTable->ApplyControlToken, buffer, &Disp);
  514. DebuggerOut(" ApplyControlToken \t%s\n", buffer);
  515. LsaGetSymbol((ULONG_PTR)pTable->Shutdown, buffer, &Disp);
  516. DebuggerOut(" Shutdown \t%s\n", buffer);
  517. LsaGetSymbol((ULONG_PTR)pTable->GetUserInfo, buffer, &Disp);
  518. DebuggerOut(" GetUserInfo \t%s\n", buffer);
  519. }
  520. }
  521. void
  522. ShowSession(
  523. PVOID pvSessionStart,
  524. PSession pSession)
  525. {
  526. UCHAR Buffer[128];
  527. ULONG_PTR Disp;
  528. LSAP_SESSION_RUNDOWN Rundown ;
  529. LSAP_SHARED_SECTION Section ;
  530. int i;
  531. PUCHAR ListEnd ;
  532. PVOID There ;
  533. DWORD Tag;
  534. LARGE_HANDLE_TABLE Large ;
  535. SMALL_HANDLE_TABLE Small ;
  536. PVOID Table ;
  537. DebuggerOut("Session @%p:\n", pvSessionStart);
  538. DebuggerOut(" Process ID\t%x\n", pSession->dwProcessID);
  539. DebuggerOut(" LPC Port \t%x\n", pSession->hPort);
  540. DisplayFlags(pSession->fSession, // Flags
  541. 32, // Flag limit
  542. SessFlags, // Flag set
  543. Buffer);
  544. DebuggerOut(" Flags \t%x: %s\n", pSession->fSession, Buffer);
  545. Table = pSession->SharedData->CredTable ;
  546. LsaReadMemory( Table, sizeof(DWORD), &Tag );
  547. if ( Tag == LHT_TAG )
  548. {
  549. LsaReadMemory( Table, sizeof( Large ), &Large );
  550. DebuggerOut(" CredTable \t%p, %d handles\n", Table, Large.Count );
  551. }
  552. else if ( Tag == SHT_TAG )
  553. {
  554. LsaReadMemory( Table, sizeof( Small ), &Small );
  555. DebuggerOut(" CredTable \t%p, %d handles\n", Table, Small.Count );
  556. }
  557. else
  558. {
  559. DebuggerOut(" CredTable \t%p, not a valid table\n", Table );
  560. }
  561. Table = pSession->SharedData->ContextTable ;
  562. LsaReadMemory( Table, sizeof(DWORD), &Tag );
  563. if ( Tag == LHT_TAG )
  564. {
  565. LsaReadMemory( Table, sizeof( Large ), &Large );
  566. DebuggerOut(" ContextTable\t%p, %d handles\n", Table, Large.Count );
  567. }
  568. else if ( Tag == SHT_TAG )
  569. {
  570. LsaReadMemory( Table, sizeof( Small ), &Small );
  571. DebuggerOut(" ContextTable\t%p, %d handles\n", Table, Small.Count );
  572. }
  573. else
  574. {
  575. DebuggerOut(" ContextTable\t%p, not a valid table\n", Table );
  576. }
  577. DebuggerOut(" RefCount \t%d\n", pSession->RefCount );
  578. ListEnd = (PUCHAR) pvSessionStart + FIELD_OFFSET( Session, RundownList ) ;
  579. if ( pSession->RundownList.Flink == (PLIST_ENTRY) ListEnd )
  580. {
  581. DebuggerOut(" No rundown functions\n" );
  582. }
  583. else
  584. {
  585. DebuggerOut(" Rundown Functions:\n" );
  586. There = pSession->RundownList.Flink ;
  587. do
  588. {
  589. LsaReadMemory( There,
  590. sizeof( LSAP_SESSION_RUNDOWN ),
  591. &Rundown );
  592. LsaGetSymbol( (ULONG_PTR) Rundown.Rundown, Buffer, &Disp );
  593. DebuggerOut(" %s( %p )\n", Buffer, Rundown.Parameter );
  594. There = Rundown.List.Flink ;
  595. if (pExtApis->lpCheckControlCRoutine())
  596. {
  597. break;
  598. }
  599. } while ( There != ListEnd );
  600. }
  601. ListEnd = (PUCHAR) pvSessionStart + FIELD_OFFSET( Session, SectionList ) ;
  602. if ( pSession->SectionList.Flink == (PLIST_ENTRY) ListEnd )
  603. {
  604. DebuggerOut(" No shared sections\n");
  605. }
  606. else
  607. {
  608. DebuggerOut(" Shared Sections\n");
  609. There = pSession->SectionList.Flink ;
  610. do
  611. {
  612. LsaReadMemory( There,
  613. sizeof( LSAP_SHARED_SECTION ),
  614. &Section );
  615. DebuggerOut(" Section %p, base at %p\n",
  616. Section.Section, Section.Base );
  617. There = Section.List.Flink ;
  618. if (pExtApis->lpCheckControlCRoutine())
  619. {
  620. break;
  621. }
  622. } while ( There != ListEnd );
  623. }
  624. }
  625. void
  626. DumpSessionList(HANDLE hProcess,
  627. HANDLE hThread,
  628. DWORD dwCurrentPc,
  629. PNTSD_EXTENSION_APIS lpExt,
  630. LPSTR pszCommand)
  631. {
  632. PVOID pvSessionStart;
  633. PVOID pvAddress;
  634. Session Sess;
  635. NTSTATUS Status;
  636. LSAP_SHARED_SESSION_DATA SharedData ;
  637. InitDebugHelp(hProcess, hThread, lpExt);
  638. pvAddress = (PVOID) GetExpr(SESSION_LIST);
  639. (void) LsaReadMemory(pvAddress, sizeof(PVOID), &pvSessionStart);
  640. DebuggerOut("psSessionList (@%p) = %p\n", pvAddress, pvSessionStart);
  641. do
  642. {
  643. Status = LsaReadMemory(pvSessionStart, sizeof(Session), &Sess);
  644. if (Status != 0)
  645. {
  646. DebuggerOut("Failed reading memory @%p\n", pvSessionStart);
  647. break;
  648. }
  649. LsaReadMemory( Sess.SharedData, sizeof( SharedData ), &SharedData );
  650. Sess.SharedData = &SharedData ;
  651. ShowSession(pvSessionStart, &Sess);
  652. pvSessionStart = Sess.List.Flink ;
  653. } while (pvSessionStart != pvAddress );
  654. return;
  655. }
  656. void
  657. DumpSession(HANDLE hProcess,
  658. HANDLE hThread,
  659. DWORD dwCurrentPc,
  660. PNTSD_EXTENSION_APIS lpExt,
  661. LPSTR pszCommand)
  662. {
  663. PVOID pvAddress;
  664. PVOID BaseAddress ;
  665. Session Sess;
  666. NTSTATUS Status;
  667. UINT_PTR id;
  668. LSAP_SHARED_SESSION_DATA SharedData ;
  669. BOOL Found;
  670. InitDebugHelp(hProcess, hThread, lpExt);
  671. pvAddress = GetExpr( pszCommand );
  672. id = ( UINT_PTR ) pvAddress;
  673. if ( id < 0x00010000 )
  674. {
  675. //
  676. // Search by process id:
  677. //
  678. pvAddress = (PVOID) GetExpr( SESSION_LIST );
  679. BaseAddress = pvAddress ;
  680. LsaReadMemory( pvAddress, sizeof( PVOID ), &pvAddress );
  681. Found = FALSE ;
  682. do
  683. {
  684. Status = LsaReadMemory(pvAddress, sizeof(Session), &Sess);
  685. if (Status != 0)
  686. {
  687. DebuggerOut("Failed reading memory @%p\n", pvAddress );
  688. break;
  689. }
  690. if ( Sess.dwProcessID == id )
  691. {
  692. LsaReadMemory( Sess.SharedData, sizeof( SharedData ), &SharedData );
  693. Sess.SharedData = &SharedData ;
  694. ShowSession( pvAddress, &Sess );
  695. Found = TRUE ;
  696. }
  697. pvAddress = Sess.List.Flink ;
  698. } while (pvAddress != BaseAddress );
  699. if ( !Found )
  700. {
  701. DebuggerOut( "No session found with process id == %x\n", id );
  702. }
  703. }
  704. else
  705. {
  706. Status = LsaReadMemory(pvAddress, sizeof(Session), &Sess);
  707. LsaReadMemory( Sess.SharedData, sizeof( SharedData ), &SharedData );
  708. Sess.SharedData = &SharedData ;
  709. ShowSession(pvAddress, &Sess);
  710. }
  711. }
  712. NTSTATUS
  713. ReadCallInfo(
  714. PLSA_CALL_INFO CallInfo
  715. )
  716. {
  717. DWORD TlsValue ;
  718. PVOID pvInfo ;
  719. NTSTATUS Status ;
  720. TlsValue = GetDword(GetExpr(TLS_CALLINFO));
  721. Status = GetTlsEntry(TlsValue, &pvInfo);
  722. if (Status != 0)
  723. {
  724. DebuggerOut("Could not get TLS %d for Thread\n", TlsValue);
  725. return Status ;
  726. }
  727. if ( pvInfo )
  728. {
  729. Status = LsaReadMemory( pvInfo, sizeof( LSA_CALL_INFO ), CallInfo );
  730. }
  731. else
  732. {
  733. Status = STATUS_UNSUCCESSFUL ;
  734. }
  735. return Status ;
  736. }
  737. VOID
  738. ShowCallInfo(
  739. PVOID pv,
  740. PLSA_CALL_INFO CallInfo
  741. )
  742. {
  743. ULONG i;
  744. CHAR Flags[ 128 ];
  745. DisplayFlags(CallInfo->CallInfo.Attributes, // Flags
  746. 8, // Flag limit
  747. CallInfoFlags, // Flag set
  748. (PUCHAR) Flags );
  749. DebuggerOut("LSA_CALL_INFO at %p\n", pv );
  750. DebuggerOut(" Message %p\n", CallInfo->Message );
  751. DebuggerOut(" Session %p\n", CallInfo->Session );
  752. DebuggerOut(" CallInfo.ThreadId %x\n", CallInfo->CallInfo.ThreadId );
  753. DebuggerOut(" CallInfo.ProcessId %x\n", CallInfo->CallInfo.ProcessId );
  754. DebuggerOut(" CallInfo.Attributes %x : %s\n", CallInfo->CallInfo.Attributes, Flags );
  755. DebuggerOut(" InProcToken %x\n", CallInfo->InProcToken );
  756. DebuggerOut(" InProcCall %x\n", CallInfo->InProcCall );
  757. DisplayFlags(CallInfo->Flags, 6, LsaCallInfoFlags, (PUCHAR) Flags );
  758. DebuggerOut(" Flags %x : %s\n", CallInfo->Flags, Flags );
  759. DebuggerOut(" Allocs %d\n", CallInfo->Allocs );
  760. for (i = 0 ; i < CallInfo->Allocs ; i++ )
  761. {
  762. DebuggerOut(" Buffers[%d] %p\n", CallInfo->Buffers[i]);
  763. }
  764. DebuggerOut(" KMap %p\n", CallInfo->KMap );
  765. }
  766. VOID
  767. DumpThreadCallInfo(
  768. HANDLE hProcess,
  769. HANDLE hThread,
  770. DWORD dwCurrentPc,
  771. PNTSD_EXTENSION_APIS lpExt,
  772. LPSTR pszCommand
  773. )
  774. {
  775. LSA_CALL_INFO CallInfo ;
  776. NTSTATUS Status ;
  777. InitDebugHelp(hProcess, hThread, lpExt);
  778. Status = ReadCallInfo( &CallInfo );
  779. if ( Status == 0 )
  780. {
  781. ShowCallInfo( NULL, &CallInfo );
  782. }
  783. }
  784. VOID
  785. DumpCallInfo(
  786. HANDLE hProcess,
  787. HANDLE hThread,
  788. DWORD dwCurrentPc,
  789. PNTSD_EXTENSION_APIS lpExt,
  790. LPSTR pszCommand
  791. )
  792. {
  793. LSA_CALL_INFO CallInfo ;
  794. NTSTATUS Status ;
  795. PVOID pv ;
  796. InitDebugHelp(hProcess, hThread, lpExt);
  797. pv = GetExpr( pszCommand );
  798. if ( pv )
  799. {
  800. LsaReadMemory( pv, sizeof( LSA_CALL_INFO ), &CallInfo );
  801. ShowCallInfo( pv, &CallInfo );
  802. }
  803. }
  804. void
  805. DumpThreadSession( HANDLE hProcess,
  806. HANDLE hThread,
  807. DWORD dwCurrentPc,
  808. PNTSD_EXTENSION_APIS lpExt,
  809. LPSTR pszCommand)
  810. {
  811. PVOID pvSessionStart;
  812. Session Session;
  813. NTSTATUS Status;
  814. DWORD TlsValue;
  815. LSAP_SHARED_SESSION_DATA SharedData ;
  816. InitDebugHelp(hProcess, hThread, lpExt);
  817. TlsValue = GetDword(GetExpr(TLS_SESSION));
  818. Status = GetTlsEntry(TlsValue, &pvSessionStart);
  819. if (Status != 0)
  820. {
  821. DebuggerOut("Could not get TLS %d for Thread\n", TlsValue);
  822. return;
  823. }
  824. if (pvSessionStart)
  825. {
  826. Status = LsaReadMemory(pvSessionStart, sizeof(Session), &Session);
  827. LsaReadMemory( Session.SharedData, sizeof( SharedData ), &SharedData );
  828. Session.SharedData = &SharedData ;
  829. ShowSession(pvSessionStart, &Session);
  830. }
  831. else
  832. {
  833. DebuggerOut("TLS entry was NULL!\n");
  834. }
  835. return;
  836. }
  837. void
  838. DumpPackage( HANDLE hProcess,
  839. HANDLE hThread,
  840. DWORD dwCurrentPc,
  841. PNTSD_EXTENSION_APIS lpExt,
  842. LPSTR pszCommand)
  843. {
  844. PVOID pvSPC = NULL;
  845. PVOID pSPC;
  846. PLSAP_SECURITY_PACKAGE pControl;
  847. UINT_PTR dwExpr;
  848. PVOID pcPackage;
  849. DWORD cPackages;
  850. DWORD cb;
  851. DWORD fDump;
  852. BOOLEAN fDumpAll;
  853. BOOLEAN fDumpSingle;
  854. UINT_PTR Index;
  855. LSAP_SECURITY_PACKAGE Package;
  856. PLSAP_SECURITY_PACKAGE * pPackageList ;
  857. InitDebugHelp(hProcess, hThread, lpExt);
  858. fDump = 0;
  859. dwExpr = 0;
  860. fDumpAll = FALSE;
  861. fDumpSingle = FALSE;
  862. pSPC = NULL;
  863. Index = 0;
  864. pcPackage = GetExpr(PACKAGE_COUNT);
  865. LsaReadMemory(pcPackage, sizeof(DWORD), &cPackages);
  866. DebuggerOut(" There are %d package in the system\n", cPackages);
  867. if (pszCommand && *pszCommand != '\0' )
  868. {
  869. DebuggerOut("Processing '%s'\n", pszCommand);
  870. while (*pszCommand)
  871. {
  872. while (*pszCommand == ' ')
  873. {
  874. pszCommand++;
  875. }
  876. if (*pszCommand == '-')
  877. {
  878. pszCommand++;
  879. switch (*pszCommand)
  880. {
  881. case 'V':
  882. case 'v':
  883. fDump |= PACKAGE_VERBOSE;
  884. break;
  885. case 'B':
  886. case 'b':
  887. fDump |= PACKAGE_NOISY;
  888. break;
  889. case 'a':
  890. case 'A':
  891. fDumpAll = TRUE;
  892. break;
  893. default:
  894. DebuggerOut("Invalid switch '%c'\n", *pszCommand);
  895. break;
  896. }
  897. pszCommand++;
  898. continue;
  899. }
  900. dwExpr = (UINT_PTR) GetExpr(pszCommand);
  901. fDumpAll = FALSE;
  902. if (dwExpr < cPackages)
  903. {
  904. Index = dwExpr;
  905. fDumpSingle = TRUE;
  906. }
  907. else if (dwExpr < 0x00010000)
  908. {
  909. DebuggerOut("Invalid package ID (%d)\n", dwExpr);
  910. return;
  911. } else
  912. pSPC = (PVOID) dwExpr;
  913. while (*pszCommand && *pszCommand != ' ')
  914. {
  915. pszCommand++;
  916. }
  917. }
  918. }
  919. else
  920. {
  921. fDumpAll = TRUE;
  922. }
  923. if (pSPC == NULL)
  924. {
  925. pvSPC = GetExpr(PACKAGE_LIST);
  926. LsaReadMemory(pvSPC, sizeof(PVOID), &pSPC);
  927. }
  928. DebuggerOut(" Package table pointer is at %p, address is %p\n", pvSPC, pSPC);
  929. pPackageList = (PLSAP_SECURITY_PACKAGE *) AllocHeap( sizeof(PVOID) * cPackages );
  930. if ( pPackageList )
  931. {
  932. LsaReadMemory( pSPC, sizeof(PVOID) * cPackages, pPackageList );
  933. }
  934. else
  935. {
  936. DebuggerOut("Out of memory\n");
  937. return;
  938. }
  939. if (fDumpSingle)
  940. {
  941. LsaReadMemory( pPackageList[ Index ], sizeof( LSAP_SECURITY_PACKAGE ), &Package );
  942. ShowPackageControl( pPackageList[ Index ],
  943. &Package,
  944. fDump | PACKAGE_TITLE );
  945. }
  946. else
  947. {
  948. for ( Index = 0 ; Index < cPackages ; Index++ )
  949. {
  950. LsaReadMemory( pPackageList[ Index ], sizeof( LSAP_SECURITY_PACKAGE ), &Package );
  951. ShowPackageControl( pPackageList[ Index ], &Package, fDump );
  952. }
  953. }
  954. FreeHeap( pPackageList );
  955. }
  956. BOOL
  957. ShowScavItem(
  958. PVOID Base,
  959. PLSAP_SCAVENGER_ITEM Item
  960. )
  961. {
  962. ULONG_PTR Disp ;
  963. UCHAR Symbol[ MAX_PATH ];
  964. DWORD Handle ;
  965. PVOID HandleTable ;
  966. if ( (Item->ScavCheck != SCAVMAGIC_ACTIVE) &&
  967. (Item->ScavCheck != SCAVMAGIC_FREE) )
  968. {
  969. DebuggerOut("Invalid scavenger item (check value not matched)\n");
  970. return FALSE ;
  971. }
  972. DebuggerOut( "LSAP_SCAVENGER_ITEM at %#x\n", Base );
  973. LsaGetSymbol((ULONG_PTR)Item->Function, Symbol, &Disp);
  974. DebuggerOut( " Function \t%s\n", Symbol );
  975. DebuggerOut( " Parameter \t%p\n", Item->Parameter );
  976. DisplayFlags(Item->Flags, 32, ScavFlags, (PUCHAR) Symbol );
  977. DebuggerOut( " Flags \t%x:%s\n", Item->Flags, Symbol );
  978. DebuggerOut( " PackageId \t%d\n", Item->PackageId );
  979. if ( Item->TimerHandle )
  980. {
  981. DebuggerOut( " TimerHandle \t%x\n", Item->TimerHandle );
  982. }
  983. switch ( Item->Type )
  984. {
  985. case NOTIFIER_TYPE_INTERVAL:
  986. DebuggerOut( " Type \tInterval\n" );
  987. break;
  988. case NOTIFIER_TYPE_HANDLE_WAIT:
  989. DebuggerOut( " Type \tHandle Wait\n");
  990. break;
  991. case NOTIFIER_TYPE_NOTIFY_EVENT:
  992. DebuggerOut( " Type \tNotify Event\n" );
  993. DebuggerOut( " Class \t%x\n", Item->Class );
  994. break;
  995. default:
  996. DebuggerOut( " Type \tUNKNOWN\n" );
  997. break;
  998. }
  999. return TRUE ;
  1000. }
  1001. void
  1002. DumpScavList( HANDLE hProcess,
  1003. HANDLE hThread,
  1004. DWORD dwCurrentPc,
  1005. PNTSD_EXTENSION_APIS lpExt,
  1006. LPSTR pszCommand)
  1007. {
  1008. LSAP_SCAVENGER_ITEM Item ;
  1009. PVOID ListAddress ;
  1010. LIST_ENTRY List ;
  1011. PLIST_ENTRY Scan ;
  1012. UINT_PTR index = 0 ;
  1013. BOOL DumpAll = FALSE ;
  1014. DWORD max = 0 ;
  1015. InitDebugHelp(hProcess, hThread, lpExt);
  1016. if ( _strnicmp( pszCommand, "notify", 6 ) == 0 )
  1017. {
  1018. ListAddress = GetExpr( NOTIFYLIST );
  1019. }
  1020. else
  1021. {
  1022. ListAddress = GetExpr( SCAVLIST );
  1023. }
  1024. LsaReadMemory( ListAddress, sizeof( LIST_ENTRY ), &List );
  1025. Scan = List.Flink ;
  1026. while ( Scan != ListAddress )
  1027. {
  1028. LsaReadMemory( Scan, sizeof( LSAP_SCAVENGER_ITEM ), &Item );
  1029. if ( !ShowScavItem( Scan, &Item ) )
  1030. {
  1031. break;
  1032. }
  1033. Scan = Item.List.Flink ;
  1034. if (pExtApis->lpCheckControlCRoutine())
  1035. {
  1036. break;
  1037. }
  1038. }
  1039. }
  1040. void
  1041. PrintSid( HANDLE hProcess,
  1042. HANDLE hThread,
  1043. PNTSD_EXTENSION_APIS lpExt,
  1044. PVOID pvSid )
  1045. {
  1046. SID Sid;
  1047. PSID pSid;
  1048. if (LsaReadMemory(pvSid, sizeof(SID), &Sid))
  1049. {
  1050. DebuggerOut("Could not read from %p\n", pvSid);
  1051. }
  1052. pSid = AllocHeap(RtlLengthRequiredSid(Sid.SubAuthorityCount));
  1053. if (pSid == NULL)
  1054. {
  1055. DebuggerOut("Unable to allocate memory to print SID\n");
  1056. }
  1057. else
  1058. {
  1059. if (LsaReadMemory(pvSid, RtlLengthRequiredSid(Sid.SubAuthorityCount), pSid))
  1060. {
  1061. DebuggerOut("Could not read from %p\n", pvSid);
  1062. }
  1063. LocalDumpSid(pSid);
  1064. DebuggerOut("\n");
  1065. FreeHeap(pSid);
  1066. }
  1067. }
  1068. void
  1069. DumpSid( HANDLE hProcess,
  1070. HANDLE hThread,
  1071. DWORD dwCurrentPc,
  1072. PNTSD_EXTENSION_APIS lpExt,
  1073. LPSTR pszCommand)
  1074. {
  1075. PVOID pvSid;
  1076. InitDebugHelp(hProcess, hThread, lpExt);
  1077. pvSid = GetExpr(pszCommand);
  1078. PrintSid(hProcess, hThread, lpExt, pvSid );
  1079. }
  1080. void
  1081. DumpToken( HANDLE hProcess,
  1082. HANDLE hThread,
  1083. DWORD dwCurrentPc,
  1084. PNTSD_EXTENSION_APIS lpExt,
  1085. LPSTR pszCommand)
  1086. {
  1087. DWORD fDump = 0;
  1088. HANDLE hToken;
  1089. HANDLE hRemoteToken;
  1090. #define DUMP_HEX 1
  1091. InitDebugHelp(hProcess, hThread, lpExt);
  1092. while (*pszCommand == '-')
  1093. {
  1094. pszCommand++;
  1095. if (*pszCommand == 'x')
  1096. {
  1097. fDump |= DUMP_HEX;
  1098. }
  1099. if (*pszCommand == 'a')
  1100. {
  1101. fDump |= 0x80; // Dump SD
  1102. }
  1103. pszCommand++;
  1104. }
  1105. hRemoteToken = GetExpr(pszCommand);
  1106. if (DuplicateHandle(hProcess,
  1107. hRemoteToken,
  1108. GetCurrentProcess(),
  1109. &hToken,
  1110. 0, FALSE,
  1111. DUPLICATE_SAME_ACCESS) )
  1112. {
  1113. PrintToken(hToken, lpExt);
  1114. CloseHandle(hToken);
  1115. }
  1116. else
  1117. {
  1118. DebuggerOut("Error %d duplicating token handle\n", GetLastError());
  1119. }
  1120. }
  1121. void
  1122. DumpThreadToken( HANDLE hProcess,
  1123. HANDLE hThread,
  1124. DWORD dwCurrentPc,
  1125. PNTSD_EXTENSION_APIS lpExt,
  1126. LPSTR pszCommand)
  1127. {
  1128. DWORD fDump = 0;
  1129. HANDLE hToken;
  1130. HANDLE hRemoteToken = NULL;
  1131. PVOID pad;
  1132. NTSTATUS Status;
  1133. #define DUMP_HEX 1
  1134. InitDebugHelp(hProcess, hThread, lpExt);
  1135. while (*pszCommand == '-')
  1136. {
  1137. pszCommand++;
  1138. if (*pszCommand == 'x')
  1139. {
  1140. fDump |= DUMP_HEX;
  1141. }
  1142. if (*pszCommand == 'a')
  1143. {
  1144. fDump |= 0x80; // Dump SD
  1145. }
  1146. pszCommand++;
  1147. }
  1148. Status = NtOpenThreadToken(hThread, TOKEN_QUERY, FALSE, &hRemoteToken);
  1149. if ((Status == STATUS_NO_TOKEN) || (hRemoteToken == NULL))
  1150. {
  1151. DebuggerOut("Thread is not impersonating. Using process token.\n");
  1152. Status = NtOpenProcessToken(hProcess, TOKEN_QUERY, &hRemoteToken);
  1153. }
  1154. hToken = hRemoteToken;
  1155. if (NT_SUCCESS(Status))
  1156. {
  1157. PrintToken(hToken, lpExt);
  1158. CloseHandle(hToken);
  1159. }
  1160. else
  1161. {
  1162. DebuggerOut("Error %#x getting thread token\n", Status);
  1163. }
  1164. }
  1165. #define SATYPE_USER 1
  1166. #define SATYPE_GROUP 2
  1167. #define SATYPE_PRIV 3
  1168. void
  1169. LocalDumpSid(PSID pxSid)
  1170. {
  1171. PISID pSid = (PISID) pxSid;
  1172. UNICODE_STRING ucsSid;
  1173. #if 0
  1174. if (fHex)
  1175. {
  1176. DebuggerOut(" S-%d-0x", pSid->Revision);
  1177. for (i = 0;i < 6 ; i++ )
  1178. {
  1179. if (j)
  1180. {
  1181. DebuggerOut("%x", pSid->IdentifierAuthority.Value[i]);
  1182. }
  1183. else
  1184. {
  1185. if (pSid->IdentifierAuthority.Value[i])
  1186. {
  1187. j = 1;
  1188. DebuggerOut("%x", pSid->IdentifierAuthority.Value[i]);
  1189. }
  1190. }
  1191. if (i==4)
  1192. {
  1193. j = 1;
  1194. }
  1195. }
  1196. for (i = 0; i < pSid->SubAuthorityCount ; i++ )
  1197. {
  1198. DebuggerOut("-0x%x", pSid->SubAuthority[i]);
  1199. }
  1200. }
  1201. else
  1202. #endif // 0
  1203. {
  1204. RtlConvertSidToUnicodeString(&ucsSid, pxSid, TRUE);
  1205. DebuggerOut(" %wZ", &ucsSid);
  1206. RtlFreeUnicodeString(&ucsSid);
  1207. }
  1208. }
  1209. void
  1210. DumpSidAttr(PSID_AND_ATTRIBUTES pSA,
  1211. int SAType)
  1212. {
  1213. LocalDumpSid(pSA->Sid);
  1214. if (SAType == SATYPE_GROUP)
  1215. {
  1216. DebuggerOut("\tAttributes - ");
  1217. if (pSA->Attributes & SE_GROUP_MANDATORY)
  1218. {
  1219. DebuggerOut("Mandatory ");
  1220. }
  1221. if (pSA->Attributes & SE_GROUP_ENABLED_BY_DEFAULT)
  1222. {
  1223. DebuggerOut("Default ");
  1224. }
  1225. if (pSA->Attributes & SE_GROUP_ENABLED)
  1226. {
  1227. DebuggerOut("Enabled ");
  1228. }
  1229. if (pSA->Attributes & SE_GROUP_OWNER)
  1230. {
  1231. DebuggerOut("Owner ");
  1232. }
  1233. if (pSA->Attributes & SE_GROUP_LOGON_ID)
  1234. {
  1235. DebuggerOut("LogonId ");
  1236. }
  1237. }
  1238. }
  1239. WCHAR * GetPrivName(PLUID pPriv)
  1240. {
  1241. switch (pPriv->LowPart)
  1242. {
  1243. case SE_CREATE_TOKEN_PRIVILEGE:
  1244. return(SE_CREATE_TOKEN_NAME);
  1245. case SE_ASSIGNPRIMARYTOKEN_PRIVILEGE:
  1246. return(SE_ASSIGNPRIMARYTOKEN_NAME);
  1247. case SE_LOCK_MEMORY_PRIVILEGE:
  1248. return(SE_LOCK_MEMORY_NAME);
  1249. case SE_INCREASE_QUOTA_PRIVILEGE:
  1250. return(SE_INCREASE_QUOTA_NAME);
  1251. case SE_UNSOLICITED_INPUT_PRIVILEGE:
  1252. return(SE_UNSOLICITED_INPUT_NAME);
  1253. case SE_TCB_PRIVILEGE:
  1254. return(SE_TCB_NAME);
  1255. case SE_SECURITY_PRIVILEGE:
  1256. return(SE_SECURITY_NAME);
  1257. case SE_TAKE_OWNERSHIP_PRIVILEGE:
  1258. return(SE_TAKE_OWNERSHIP_NAME);
  1259. case SE_LOAD_DRIVER_PRIVILEGE:
  1260. return(SE_LOAD_DRIVER_NAME);
  1261. case SE_SYSTEM_PROFILE_PRIVILEGE:
  1262. return(SE_SYSTEM_PROFILE_NAME);
  1263. case SE_SYSTEMTIME_PRIVILEGE:
  1264. return(SE_SYSTEMTIME_NAME);
  1265. case SE_PROF_SINGLE_PROCESS_PRIVILEGE:
  1266. return(SE_PROF_SINGLE_PROCESS_NAME);
  1267. case SE_INC_BASE_PRIORITY_PRIVILEGE:
  1268. return(SE_INC_BASE_PRIORITY_NAME);
  1269. case SE_CREATE_PAGEFILE_PRIVILEGE:
  1270. return(SE_CREATE_PAGEFILE_NAME);
  1271. case SE_CREATE_PERMANENT_PRIVILEGE:
  1272. return(SE_CREATE_PERMANENT_NAME);
  1273. case SE_BACKUP_PRIVILEGE:
  1274. return(SE_BACKUP_NAME);
  1275. case SE_RESTORE_PRIVILEGE:
  1276. return(SE_RESTORE_NAME);
  1277. case SE_SHUTDOWN_PRIVILEGE:
  1278. return(SE_SHUTDOWN_NAME);
  1279. case SE_DEBUG_PRIVILEGE:
  1280. return(SE_DEBUG_NAME);
  1281. case SE_AUDIT_PRIVILEGE:
  1282. return(SE_AUDIT_NAME);
  1283. case SE_SYSTEM_ENVIRONMENT_PRIVILEGE:
  1284. return(SE_SYSTEM_ENVIRONMENT_NAME);
  1285. case SE_CHANGE_NOTIFY_PRIVILEGE:
  1286. return(SE_CHANGE_NOTIFY_NAME);
  1287. case SE_REMOTE_SHUTDOWN_PRIVILEGE:
  1288. return(SE_REMOTE_SHUTDOWN_NAME);
  1289. case SE_UNDOCK_PRIVILEGE:
  1290. return(SE_UNDOCK_NAME);
  1291. case SE_SYNC_AGENT_PRIVILEGE:
  1292. return(SE_SYNC_AGENT_NAME);
  1293. case SE_ENABLE_DELEGATION_PRIVILEGE:
  1294. return(SE_ENABLE_DELEGATION_NAME);
  1295. default:
  1296. return(L"Unknown Privilege");
  1297. }
  1298. }
  1299. void
  1300. DumpLuidAttr(PLUID_AND_ATTRIBUTES pLA,
  1301. int LAType)
  1302. {
  1303. DebuggerOut("0x%x%08x", pLA->Luid.HighPart, pLA->Luid.LowPart);
  1304. DebuggerOut(" %-32ws", GetPrivName(&pLA->Luid));
  1305. if (LAType == SATYPE_PRIV)
  1306. {
  1307. DebuggerOut(" Attributes - ");
  1308. if (pLA->Attributes & SE_PRIVILEGE_ENABLED)
  1309. {
  1310. DebuggerOut("Enabled ");
  1311. }
  1312. if (pLA->Attributes & SE_PRIVILEGE_ENABLED_BY_DEFAULT)
  1313. {
  1314. DebuggerOut("Default ");
  1315. }
  1316. }
  1317. }
  1318. void
  1319. PrintToken(HANDLE hToken,
  1320. PNTSD_EXTENSION_APIS lpExt)
  1321. {
  1322. PTOKEN_USER pTUser;
  1323. PTOKEN_GROUPS pTGroups;
  1324. PTOKEN_PRIVILEGES pTPrivs;
  1325. PTOKEN_PRIMARY_GROUP pTPrimaryGroup;
  1326. TOKEN_STATISTICS TStats;
  1327. ULONG cbRetInfo;
  1328. NTSTATUS status;
  1329. DWORD i;
  1330. DWORD dwSessionId;
  1331. pTUser = (PTOKEN_USER) alloca (256);
  1332. pTGroups = (PTOKEN_GROUPS) alloca (4096);
  1333. pTPrivs = (PTOKEN_PRIVILEGES) alloca (1024);
  1334. pTPrimaryGroup = (PTOKEN_PRIMARY_GROUP) alloca (128);
  1335. if ( pTUser == NULL ||
  1336. pTGroups == NULL ||
  1337. pTPrivs == NULL ||
  1338. pTPrimaryGroup == NULL ) {
  1339. DebuggerOut( "Failed to allocate memory\n" );
  1340. return;
  1341. }
  1342. status = NtQueryInformationToken( hToken,
  1343. TokenSessionId,
  1344. &dwSessionId,
  1345. sizeof(dwSessionId),
  1346. &cbRetInfo);
  1347. if (!NT_SUCCESS(status))
  1348. {
  1349. DebuggerOut("Failed to query token: %#x\n", status);
  1350. return;
  1351. }
  1352. DebuggerOut("TS Session ID: %x\n", dwSessionId);
  1353. status = NtQueryInformationToken( hToken,
  1354. TokenUser,
  1355. pTUser,
  1356. 256,
  1357. &cbRetInfo);
  1358. if (!NT_SUCCESS(status))
  1359. {
  1360. DebuggerOut("Failed to query token: %#x\n", status);
  1361. return;
  1362. }
  1363. DebuggerOut("User\n ");
  1364. DumpSidAttr(&pTUser->User, SATYPE_USER);
  1365. DebuggerOut("\nGroups");
  1366. status = NtQueryInformationToken( hToken,
  1367. TokenGroups,
  1368. pTGroups,
  1369. 4096,
  1370. &cbRetInfo);
  1371. for (i = 0; i < pTGroups->GroupCount ; i++ )
  1372. {
  1373. DebuggerOut("\n %02d ", i);
  1374. DumpSidAttr(&pTGroups->Groups[i], SATYPE_GROUP);
  1375. }
  1376. status = NtQueryInformationToken( hToken,
  1377. TokenPrimaryGroup,
  1378. pTPrimaryGroup,
  1379. 128,
  1380. &cbRetInfo);
  1381. DebuggerOut("\nPrimary Group:\n ");
  1382. LocalDumpSid(pTPrimaryGroup->PrimaryGroup);
  1383. DebuggerOut("\nPrivs\n");
  1384. status = NtQueryInformationToken( hToken,
  1385. TokenPrivileges,
  1386. pTPrivs,
  1387. 1024,
  1388. &cbRetInfo);
  1389. if (!NT_SUCCESS(status))
  1390. {
  1391. printf("NtQueryInformationToken returned %#x\n", status);
  1392. return;
  1393. }
  1394. for (i = 0; i < pTPrivs->PrivilegeCount ; i++ )
  1395. {
  1396. DebuggerOut("\n %02d ", i);
  1397. DumpLuidAttr(&pTPrivs->Privileges[i], SATYPE_PRIV);
  1398. }
  1399. status = NtQueryInformationToken( hToken,
  1400. TokenStatistics,
  1401. &TStats,
  1402. sizeof(TStats),
  1403. &cbRetInfo);
  1404. DebuggerOut("\n\nAuth ID %x:%x\n", TStats.AuthenticationId.HighPart, TStats.AuthenticationId.LowPart);
  1405. DebuggerOut("Impersonation Level: %s\n", ImpLevel(TStats.ImpersonationLevel));
  1406. DebuggerOut("TokenType %s\n", TStats.TokenType == TokenPrimary ? "Primary" : "Impersonation");
  1407. }
  1408. VOID
  1409. ElapsedTimeToString(
  1410. PLARGE_INTEGER Time,
  1411. CHAR * String
  1412. )
  1413. {
  1414. TIME_FIELDS ElapsedTime ;
  1415. RtlTimeToElapsedTimeFields( Time, &ElapsedTime );
  1416. if ( ElapsedTime.Hour )
  1417. {
  1418. sprintf( String, "%d:%02d:%02d.%03d",
  1419. ElapsedTime.Hour,
  1420. ElapsedTime.Minute,
  1421. ElapsedTime.Second,
  1422. ElapsedTime.Milliseconds );
  1423. }
  1424. else if ( ElapsedTime.Minute )
  1425. {
  1426. sprintf( String, "%02d:%02d.%03d",
  1427. ElapsedTime.Minute,
  1428. ElapsedTime.Second,
  1429. ElapsedTime.Milliseconds );
  1430. }
  1431. else if ( ElapsedTime.Second )
  1432. {
  1433. sprintf( String, "%02.%03d",
  1434. ElapsedTime.Second,
  1435. ElapsedTime.Milliseconds );
  1436. }
  1437. else if ( ElapsedTime.Milliseconds )
  1438. {
  1439. sprintf( String, "0.%03d",
  1440. ElapsedTime.Milliseconds );
  1441. }
  1442. else
  1443. {
  1444. strcpy( String, "0" );
  1445. }
  1446. }
  1447. void
  1448. DumpLpc( HANDLE hProcess,
  1449. HANDLE hThread,
  1450. DWORD dwCurrentPc,
  1451. PNTSD_EXTENSION_APIS lpExt,
  1452. LPSTR pszCommand)
  1453. {
  1454. PVOID pRemote;
  1455. DWORD i;
  1456. PLSAP_API_LOG pLog ;
  1457. LSAP_API_LOG LocalLog ;
  1458. ULONG Size ;
  1459. FILETIME LocalTime ;
  1460. PLSAP_API_LOG_ENTRY Entry ;
  1461. PVOID Table ;
  1462. CHAR timebuf[ 128 ];
  1463. CHAR timebuf2[ 64 ];
  1464. InitDebugHelp(hProcess, hThread, lpExt);
  1465. if ( _stricmp( pszCommand, "internal" ) == 0 )
  1466. {
  1467. pRemote = GetExpr( INTERNAL_APILOG );
  1468. }
  1469. else
  1470. {
  1471. pRemote = GetExpr( LPC_APILOG );
  1472. }
  1473. LsaReadMemory( pRemote, sizeof( PVOID ), &Table );
  1474. LsaReadMemory( Table, sizeof( LocalLog ), &LocalLog );
  1475. Size = (LocalLog.TotalSize - 1) * sizeof( LSAP_API_LOG_ENTRY ) +
  1476. sizeof( LSAP_API_LOG ) ;
  1477. pLog = (PLSAP_API_LOG) LocalAlloc( LMEM_FIXED, Size );
  1478. if ( !pLog )
  1479. {
  1480. DebuggerOut( "no memory\n" );
  1481. return;
  1482. }
  1483. LsaReadMemory( Table, Size, pLog );
  1484. DebuggerOut("MessageId\tStatus and Time\n");
  1485. for (i = 0; i < pLog->TotalSize ; i++ )
  1486. {
  1487. Entry = &pLog->Entries[ i ];
  1488. DebuggerOut("%08x%c\t", Entry->MessageId,
  1489. ( i == pLog->Current ? '*' : ' ') );
  1490. if (Entry->ThreadId == 0)
  1491. {
  1492. CTimeStamp( (PTimeStamp) &Entry->QueueTime, timebuf, TRUE );
  1493. DebuggerOut("Queued, Message @%p, Task @%p (%s)\n",
  1494. Entry->pvMessage,
  1495. Entry->WorkItem,
  1496. timebuf );
  1497. }
  1498. else if (Entry->ThreadId == 0xFFFFFFFF)
  1499. {
  1500. // CTimeStamp( (PTimeStamp) &Entry->QueueTime, timebuf, TRUE );
  1501. timebuf[0] = '\0';
  1502. ElapsedTimeToString( &Entry->WorkTime, timebuf2 );
  1503. DebuggerOut("Completed, (%s, status %x), %s [%s]\n",
  1504. ApiLabel( (UINT_PTR) Entry->pvMessage ),
  1505. Entry->WorkItem,
  1506. timebuf,
  1507. timebuf2 );
  1508. }
  1509. else
  1510. {
  1511. CTimeStamp( (PTimeStamp) &Entry->WorkTime, timebuf, TRUE );
  1512. DebuggerOut("Active, thread %x, Message @%p, %s\n",
  1513. Entry->ThreadId,
  1514. Entry->pvMessage,
  1515. timebuf );
  1516. }
  1517. }
  1518. }
  1519. VOID
  1520. ShowSecBuffer(
  1521. PSTR Banner,
  1522. PSecBuffer Buffer)
  1523. {
  1524. DWORD Mask;
  1525. Mask = Buffer->BufferType & SECBUFFER_ATTRMASK ;
  1526. DebuggerOut("%s\t", Banner);
  1527. DebuggerOut("%s%s%s %d bytes, %p\n",
  1528. Mask & SECBUFFER_READONLY ? "[RO]" : "",
  1529. Mask & SECBUFFER_UNMAPPED ? "[!Map]" : "",
  1530. SecBufferType( Buffer->BufferType ),
  1531. Buffer->cbBuffer,
  1532. Buffer->pvBuffer );
  1533. }
  1534. VOID
  1535. ShowLpcMessage(
  1536. PVOID pvMessage,
  1537. PSPM_LPC_MESSAGE pMessage)
  1538. {
  1539. SPMInitContextAPI * pInit;
  1540. SPMAcceptContextAPI * pAccept;
  1541. SPMDeleteContextAPI * pDelete ;
  1542. SPMFreeCredHandleAPI * pFreeCred ;
  1543. SPMAcquireCredsAPI * pAcquire;
  1544. SPMCallbackAPI * pCallback ;
  1545. SPMAddCredentialAPI * pAddCred ;
  1546. SPMQueryCredAttributesAPI * pQueryCred ;
  1547. SPMEfsGenerateKeyAPI * pGenKey ;
  1548. SPMEfsGenerateDirEfsAPI * pGenDir ;
  1549. SPMEfsDecryptFekAPI * pDecryptFek ;
  1550. SPMGetBindingAPI * pGetBinding ;
  1551. DWORD i;
  1552. UCHAR Flags[ 80 ];
  1553. DebuggerOut("SPM_LPC_MESSAGE at %p\n", pvMessage);
  1554. DebuggerOut(" Message id \t%x\n", pMessage->pmMessage.MessageId);
  1555. DebuggerOut(" From \t%x.%x\n", pMessage->pmMessage.ClientId.UniqueProcess,pMessage->pmMessage.ClientId.UniqueThread);
  1556. DebuggerOut(" API Number \t%d\n", pMessage->ApiMessage.dwAPI);
  1557. DebuggerOut(" Result \t%#x\n",pMessage->ApiMessage.scRet);
  1558. DebuggerOut(" LSA Args \t%p\n", (PUCHAR) pvMessage + (DWORD_PTR) ((PUCHAR) &pMessage->ApiMessage.Args) - ((PUCHAR) pMessage));
  1559. DebuggerOut(" SPM Args \t%p\n", (PUCHAR) pvMessage + (DWORD_PTR) ((PUCHAR) &pMessage->ApiMessage.Args.SpmArguments.API) - ((PUCHAR) pMessage));
  1560. DebuggerOut(" Data \t%p\n", (PUCHAR) pvMessage + (DWORD_PTR) (&pMessage->ApiMessage.bData[0]) - ((PUCHAR) pMessage));
  1561. if ( pMessage->ApiMessage.dwAPI > LsapAuMaxApiNumber)
  1562. {
  1563. Flags[0] = '\0';
  1564. DisplayFlags( pMessage->ApiMessage.Args.SpmArguments.fAPI,
  1565. 12,
  1566. APIFlags,
  1567. Flags );
  1568. DebuggerOut(" Flags \t%x: %s\n",
  1569. pMessage->ApiMessage.Args.SpmArguments.fAPI,
  1570. Flags );
  1571. DebuggerOut(" Context \t%p\n",
  1572. pMessage->ApiMessage.Args.SpmArguments.ContextPointer );
  1573. }
  1574. switch (pMessage->ApiMessage.dwAPI)
  1575. {
  1576. case LsapAuLookupPackageApi:
  1577. DebuggerOut(" LsapAuLookupPackageApi\n");
  1578. DebuggerOut(" (o) Number \t%d\n",pMessage->ApiMessage.Args.LsaArguments.LookupPackage.AuthenticationPackage);
  1579. DebuggerOut(" (i) Length \t%d\n",pMessage->ApiMessage.Args.LsaArguments.LookupPackage.PackageNameLength);
  1580. DebuggerOut(" (i) Name \t%s\n",pMessage->ApiMessage.Args.LsaArguments.LookupPackage.PackageName);
  1581. break;
  1582. case LsapAuLogonUserApi:
  1583. DebuggerOut(" LsapAuLogonUserApi\n");
  1584. DebuggerOut(" (i) Origin \t{%d,%d,%p}\n",pMessage->ApiMessage.Args.LsaArguments.LogonUser.OriginName.Length,
  1585. pMessage->ApiMessage.Args.LsaArguments.LogonUser.OriginName.MaximumLength,
  1586. pMessage->ApiMessage.Args.LsaArguments.LogonUser.OriginName.Buffer);
  1587. DebuggerOut(" (i) LogonTyp\t%d\n",pMessage->ApiMessage.Args.LsaArguments.LogonUser.LogonType);
  1588. DebuggerOut(" (i) Package \t%d\n",pMessage->ApiMessage.Args.LsaArguments.LogonUser.AuthenticationPackage);
  1589. DebuggerOut(" (i) AuthInfo\t%p\n",pMessage->ApiMessage.Args.LsaArguments.LogonUser.AuthenticationInformation);
  1590. DebuggerOut(" (i) AuthInfo\t%d\n",pMessage->ApiMessage.Args.LsaArguments.LogonUser.AuthenticationInformationLength);
  1591. DebuggerOut(" (i) GroupCou\t%d\n",pMessage->ApiMessage.Args.LsaArguments.LogonUser.LocalGroupsCount);
  1592. DebuggerOut(" (i) Groups \t%p\n",pMessage->ApiMessage.Args.LsaArguments.LogonUser.LocalGroups);
  1593. DebuggerOut(" (i) Source \t%s\n",pMessage->ApiMessage.Args.LsaArguments.LogonUser.SourceContext.SourceName);
  1594. DebuggerOut(" (o) SubStat \t%x\n",pMessage->ApiMessage.Args.LsaArguments.LogonUser.SubStatus);
  1595. DebuggerOut(" (o) Profile \t%p\n",pMessage->ApiMessage.Args.LsaArguments.LogonUser.ProfileBuffer);
  1596. DebuggerOut(" (o) ProfLen \t%x\n",pMessage->ApiMessage.Args.LsaArguments.LogonUser.ProfileBufferLength);
  1597. DebuggerOut(" (o) LogonId \t%x:%x\n",pMessage->ApiMessage.Args.LsaArguments.LogonUser.LogonId.HighPart,pMessage->ApiMessage.Args.LsaArguments.LogonUser.LogonId.LowPart);
  1598. DebuggerOut(" (o) Token \t%x\n",pMessage->ApiMessage.Args.LsaArguments.LogonUser.Token);
  1599. DebuggerOut(" (o) Quota \t%x\n",pMessage->ApiMessage.Args.LsaArguments.LogonUser.Quotas.PagedPoolLimit);
  1600. break;
  1601. case LsapAuCallPackageApi:
  1602. DebuggerOut(" LsapCallPackageApi\n");
  1603. DebuggerOut(" (i) Package\t%d\n",pMessage->ApiMessage.Args.LsaArguments.CallPackage.AuthenticationPackage);
  1604. DebuggerOut(" (i) Buffer \t%d\n",pMessage->ApiMessage.Args.LsaArguments.CallPackage.ProtocolSubmitBuffer);
  1605. DebuggerOut(" (i) Length \t%d\n",pMessage->ApiMessage.Args.LsaArguments.CallPackage.SubmitBufferLength);
  1606. DebuggerOut(" (o) Status \t%d\n",pMessage->ApiMessage.Args.LsaArguments.CallPackage.ProtocolStatus);
  1607. DebuggerOut(" (o) RBuffer\t%d\n",pMessage->ApiMessage.Args.LsaArguments.CallPackage.ProtocolReturnBuffer);
  1608. DebuggerOut(" (o) Length \t%d\n",pMessage->ApiMessage.Args.LsaArguments.CallPackage.ReturnBufferLength);
  1609. break;
  1610. case LsapAuDeregisterLogonProcessApi:
  1611. DebuggerOut(" LsapAuDeregisterLogonProcessApi\n");
  1612. break;
  1613. case SPMAPI_GetBinding:
  1614. DebuggerOut(" GetBinding\n");
  1615. pGetBinding = &pMessage->ApiMessage.Args.SpmArguments.API.GetBinding ;
  1616. DebuggerOut(" (i) ulPackageId \t%p\n", pGetBinding->ulPackageId) ;
  1617. break;
  1618. case SPMAPI_InitContext:
  1619. DebuggerOut(" InitContext\n");
  1620. pInit = &pMessage->ApiMessage.Args.SpmArguments.API.InitContext;
  1621. DebuggerOut(" (i) hCredentials \t%p:%p\n", pInit->hCredential.dwUpper, pInit->hCredential.dwLower);
  1622. DebuggerOut(" (i) hContext \t%p:%p\n", pInit->hContext.dwUpper, pInit->hContext.dwLower);
  1623. DebuggerOut(" (i) ssTarget \t%p\n", pInit->ssTarget.Buffer);
  1624. DebuggerOut(" (i) fContextReq \t%x\n", pInit->fContextReq);
  1625. DebuggerOut(" (i) Reserved1 \t%x\n", pInit->dwReserved1);
  1626. DebuggerOut(" (i) TargetDataRep \t%x\n", pInit->TargetDataRep);
  1627. DebuggerOut(" (i) sbdInput \t%d : %p\n", pInit->sbdInput.cBuffers, pInit->sbdInput.pBuffers );
  1628. DebuggerOut(" (i) Reserved2 \t%x\n", pInit->dwReserved2);
  1629. DebuggerOut(" (o) hNewContext \t%p:%p\n", pInit->hNewContext.dwUpper, pInit->hNewContext.dwLower );
  1630. DebuggerOut(" (b) sbdOutput \t%d : %p\n", pInit->sbdOutput.cBuffers, pInit->sbdOutput.pBuffers );
  1631. DebuggerOut(" (o) fContextAttr \t%x\n", pInit->fContextAttr );
  1632. DebuggerOut(" (o) tsExpiry \t%s\n","");
  1633. DebuggerOut(" (o) MappedContext \t%x\n", pInit->MappedContext );
  1634. ShowSecBuffer(" (o) ContextData \t", &pInit->ContextData );
  1635. for ( i = 0 ; i < pInit->sbdInput.cBuffers ; i++ )
  1636. {
  1637. ShowSecBuffer(" (i) InputBuffer\t", &pInit->sbData[i]);
  1638. }
  1639. for ( i = 0; i < pInit->sbdOutput.cBuffers ; i++ )
  1640. {
  1641. ShowSecBuffer(" (b) OutputBuffer\t", &pInit->sbData[i + pInit->sbdInput.cBuffers]);
  1642. }
  1643. break;
  1644. case SPMAPI_AcceptContext:
  1645. DebuggerOut(" AcceptContext\n");
  1646. pAccept = &pMessage->ApiMessage.Args.SpmArguments.API.AcceptContext;
  1647. DebuggerOut(" (i) hCredentials \t%p : %p\n", pAccept->hCredential.dwUpper, pAccept->hCredential.dwLower );
  1648. DebuggerOut(" (i) hContext \t%p : %p\n", pAccept->hContext.dwUpper, pAccept->hContext.dwLower );
  1649. DebuggerOut(" (i) sbdInput \t%d : %p\n", pAccept->sbdInput.cBuffers, pAccept->sbdInput.pBuffers );
  1650. DebuggerOut(" (i) fContextReq \t%x\n", pAccept->fContextReq );
  1651. DebuggerOut(" (i) TargetDataRep \t%x\n", pAccept->TargetDataRep );
  1652. DebuggerOut(" (o) hNewContext \t%p : %p\n", pAccept->hNewContext.dwUpper, pAccept->hNewContext.dwLower );
  1653. DebuggerOut(" (b) sbdOutput \t%d : %p\n", pAccept->sbdOutput.cBuffers, pAccept->sbdOutput.pBuffers );
  1654. DebuggerOut(" (o) fContextAttr \t%x \n", pAccept->fContextAttr );
  1655. DebuggerOut(" (o) MappedContext \t%x\n", pAccept->MappedContext );
  1656. ShowSecBuffer(" (o) ContextData \t", &pAccept->ContextData );
  1657. for ( i = 0 ; i < pAccept->sbdInput.cBuffers ; i++ )
  1658. {
  1659. ShowSecBuffer(" (i) InputBuffer\t", &pAccept->sbData[i]);
  1660. }
  1661. for ( i = 0; i < pAccept->sbdOutput.cBuffers ; i++ )
  1662. {
  1663. ShowSecBuffer(" (b) OutputBuffer\t", &pAccept->sbData[i + pAccept->sbdInput.cBuffers]);
  1664. }
  1665. break;
  1666. case SPMAPI_FindPackage:
  1667. DebuggerOut(" FindPackage\n");
  1668. break;
  1669. case SPMAPI_EnumPackages:
  1670. DebuggerOut(" EnumPackages\n");
  1671. break;
  1672. case SPMAPI_AcquireCreds:
  1673. DebuggerOut(" AcquireCreds\n");
  1674. pAcquire = &pMessage->ApiMessage.Args.SpmArguments.API.AcquireCreds ;
  1675. DebuggerOut(" (i) fCredentialUse \t%x\n", pAcquire->fCredentialUse );
  1676. DebuggerOut(" (i) LogonId \t%x : %x\n", pAcquire->LogonID.LowPart, pAcquire->LogonID.HighPart );
  1677. DebuggerOut(" (i) pvAuthData \t%p\n", pAcquire->pvAuthData );
  1678. DebuggerOut(" (i) pvGetKeyFn \t%p\n", pAcquire->pvGetKeyFn );
  1679. DebuggerOut(" (i) ulGetKeyArgs \t%p\n", pAcquire->ulGetKeyArgument );
  1680. DebuggerOut(" (o) hCredentials \t%p : %p\n", pAcquire->hCredential.dwUpper, pAcquire->hCredential.dwLower );
  1681. break;
  1682. case SPMAPI_EstablishCreds:
  1683. DebuggerOut(" EstablishCreds\n");
  1684. break;
  1685. case SPMAPI_FreeCredHandle:
  1686. DebuggerOut(" FreeCredHandle\n");
  1687. pFreeCred = &pMessage->ApiMessage.Args.SpmArguments.API.FreeCredHandle ;
  1688. DebuggerOut(" (i) hCredential \t%p : %p\n", pFreeCred->hCredential.dwUpper, pFreeCred->hCredential.dwLower );
  1689. break;
  1690. case SPMAPI_ApplyToken:
  1691. DebuggerOut(" ApplyToken\n");
  1692. break;
  1693. case SPMAPI_DeleteContext:
  1694. DebuggerOut(" DeleteContext\n");
  1695. pDelete = &pMessage->ApiMessage.Args.SpmArguments.API.DeleteContext ;
  1696. DebuggerOut(" (i) hContext \t%p : %p\n", pDelete->hContext.dwUpper, pDelete->hContext.dwLower );
  1697. break;
  1698. case SPMAPI_QueryPackage:
  1699. DebuggerOut(" QueryPackage\n");
  1700. break;
  1701. case SPMAPI_GetUserInfo:
  1702. DebuggerOut(" GetUserInfo\n");
  1703. break;
  1704. case SPMAPI_GetCreds:
  1705. DebuggerOut(" GetCreds\n");
  1706. break;
  1707. case SPMAPI_SaveCreds:
  1708. DebuggerOut(" SaveCreds\n");
  1709. break;
  1710. case SPMAPI_DeleteCreds:
  1711. DebuggerOut(" DeleteCreds\n");
  1712. break;
  1713. case SPMAPI_QueryCredAttributes:
  1714. DebuggerOut(" QueryCredAttributes\n");
  1715. pQueryCred = &pMessage->ApiMessage.Args.SpmArguments.API.QueryCredAttributes ;
  1716. DebuggerOut(" (i) hCredentials \t%p : %p\n", pQueryCred->hCredentials.dwUpper, pQueryCred->hCredentials.dwLower );
  1717. DebuggerOut(" (i) ulAttribute \t%d\n", pQueryCred->ulAttribute );
  1718. DebuggerOut(" (i) pBuffer \t%p\n", pQueryCred->pBuffer );
  1719. DebuggerOut(" (o) Allocs \t%d\n", pQueryCred->Allocs );
  1720. for ( i = 0 ; i < pQueryCred->Allocs ; i++ )
  1721. {
  1722. DebuggerOut(" (o) Buffers[%d] \t %p\n", pQueryCred->Buffers[ i ] );
  1723. }
  1724. break;
  1725. case SPMAPI_AddPackage:
  1726. DebuggerOut(" AddPackage\n");
  1727. break;
  1728. case SPMAPI_DeletePackage:
  1729. DebuggerOut(" DeletePackage\n");
  1730. break;
  1731. case SPMAPI_EfsGenerateKey:
  1732. DebuggerOut(" EfsGenerateKey\n" );
  1733. pGenKey = &pMessage->ApiMessage.Args.SpmArguments.API.EfsGenerateKey ;
  1734. DebuggerOut(" (i) EfsStream \t%p\n", pGenKey->EfsStream );
  1735. DebuggerOut(" (i) DirectoryEfsStream\t%p\n", pGenKey->DirectoryEfsStream);
  1736. DebuggerOut(" (i) DirectoryStreamLen\t%#x\n", pGenKey->DirectoryEfsStreamLength );
  1737. DebuggerOut(" (i) Fek \t%p\n", pGenKey->Fek );
  1738. DebuggerOut(" (o) BufferLength \t%#x\n", pGenKey->BufferLength );
  1739. DebuggerOut(" (o) BufferBase \t%p\n", pGenKey->BufferBase );
  1740. break;
  1741. case SPMAPI_EfsGenerateDirEfs:
  1742. DebuggerOut(" EfsGenerateDirEfs\n" );
  1743. pGenDir = &pMessage->ApiMessage.Args.SpmArguments.API.EfsGenerateDirEfs ;
  1744. DebuggerOut(" (i) DirectoryEfsStream\t%p\n", pGenDir->DirectoryEfsStream);
  1745. DebuggerOut(" (i) DirectoryStreamLen\t%#x\n", pGenDir->DirectoryEfsStreamLength );
  1746. DebuggerOut(" (i) EfsStream \t%p\n", pGenDir->EfsStream );
  1747. DebuggerOut(" (o) BufferBase \t%p\n", pGenDir->BufferBase );
  1748. DebuggerOut(" (o) BufferLength \t%#x\n", pGenDir->BufferLength );
  1749. break;
  1750. case SPMAPI_EfsDecryptFek:
  1751. DebuggerOut(" EfsDecryptFek\n" );
  1752. pDecryptFek = &pMessage->ApiMessage.Args.SpmArguments.API.EfsDecryptFek ;
  1753. DebuggerOut(" (i) Fek \t%p\n", pDecryptFek->Fek );
  1754. DebuggerOut(" (i) EfsStream \t%p\n", pDecryptFek->EfsStream );
  1755. DebuggerOut(" (i) EfsStreamLength\t%p\n", pDecryptFek->EfsStreamLength );
  1756. DebuggerOut(" (i) OpenType \t%#x\n", pDecryptFek->OpenType );
  1757. DebuggerOut(" (?) NewEfs \t%p\n", pDecryptFek->NewEfs );
  1758. DebuggerOut(" (o) BufferBase \t%p\n", pDecryptFek->BufferBase );
  1759. DebuggerOut(" (o) BufferLength \t%#x\n", pDecryptFek->BufferLength );
  1760. break;
  1761. case SPMAPI_EfsGenerateSessionKey:
  1762. DebuggerOut(" EfsGenerateSessionKey\n" );
  1763. break;
  1764. case SPMAPI_Callback:
  1765. DebuggerOut(" Callback\n" );
  1766. pCallback = &pMessage->ApiMessage.Args.SpmArguments.API.Callback ;
  1767. DebuggerOut(" (i) Type \t%x\n", pCallback->Type );
  1768. DebuggerOut(" (i) CallbackFunction\t%p\n", pCallback->CallbackFunction );
  1769. DebuggerOut(" (i) Argument1 \t%p\n", pCallback->Argument1 );
  1770. DebuggerOut(" (i) Argument2 \t%p\n", pCallback->Argument2 );
  1771. ShowSecBuffer(" (i) Input \t", &pCallback->Input );
  1772. ShowSecBuffer(" (o) Output \t", &pCallback->Output );
  1773. break;
  1774. case SPMAPI_QueryContextAttr:
  1775. DebuggerOut(" QueryContextAttributes\n" );
  1776. break;
  1777. case SPMAPI_LsaPolicyChangeNotify:
  1778. DebuggerOut(" LsaPolicyChangeNotify\n" );
  1779. break;
  1780. case SPMAPI_GetUserNameX:
  1781. DebuggerOut(" GetUserName\n" );
  1782. break;
  1783. case SPMAPI_AddCredential:
  1784. DebuggerOut(" AddCredential\n" );
  1785. pAddCred = &pMessage->ApiMessage.Args.SpmArguments.API.AddCredential ;
  1786. DebuggerOut(" (i) hCredentials \t%p : %p\n",
  1787. pAddCred->hCredentials.dwUpper, pAddCred->hCredentials.dwLower );
  1788. DebuggerOut(" (i) fCredentialUse \t%x\n", pAddCred->fCredentialUse );
  1789. DebuggerOut(" (i) LogonId \t%x : %x\n", pAddCred->LogonID.LowPart, pAddCred->LogonID.HighPart );
  1790. DebuggerOut(" (i) pvAuthData \t%p\n", pAddCred->pvAuthData );
  1791. DebuggerOut(" (i) pvGetKeyFn \t%p\n", pAddCred->pvGetKeyFn );
  1792. DebuggerOut(" (i) ulGetKeyArgs \t%p\n", pAddCred->ulGetKeyArgument );
  1793. break;
  1794. case SPMAPI_EnumLogonSession:
  1795. DebuggerOut(" EnumLogonSession\n" );
  1796. break;
  1797. case SPMAPI_GetLogonSessionData:
  1798. DebuggerOut(" GetLogonSessionData\n" );
  1799. break;
  1800. case SPMAPI_SetContextAttr:
  1801. DebuggerOut(" SetContextAttr\n" );
  1802. break;
  1803. case SPMAPI_LookupAccountSidX:
  1804. DebuggerOut(" LookupAccountSid\n");
  1805. break;
  1806. case SPMAPI_LookupAccountNameX:
  1807. DebuggerOut(" LookupAccountName\n");
  1808. break;
  1809. default:
  1810. DebuggerOut("No message parsing for this message\n");
  1811. break;
  1812. }
  1813. }
  1814. void
  1815. DumpLpcMessage( HANDLE hProcess,
  1816. HANDLE hThread,
  1817. DWORD dwCurrentPc,
  1818. PNTSD_EXTENSION_APIS lpExt,
  1819. LPSTR pszCommand)
  1820. {
  1821. SPM_LPC_MESSAGE Message;
  1822. PVOID pvMessage;
  1823. InitDebugHelp(hProcess, hThread, lpExt);
  1824. pvMessage = GetExpr(pszCommand);
  1825. if (!pvMessage)
  1826. {
  1827. DebuggerOut("no message\n");
  1828. return;
  1829. }
  1830. LsaReadMemory(pvMessage, sizeof(SPM_LPC_MESSAGE), &Message);
  1831. ShowLpcMessage( pvMessage, &Message );
  1832. }
  1833. void
  1834. DumpThreadLpc(
  1835. HANDLE hProcess,
  1836. HANDLE hThread,
  1837. DWORD dwCurrentPc,
  1838. PNTSD_EXTENSION_APIS lpExt,
  1839. LPSTR pszCommand)
  1840. {
  1841. SPM_LPC_MESSAGE Message;
  1842. PVOID pvMessage;
  1843. NTSTATUS Status;
  1844. LSA_CALL_INFO CallInfo ;
  1845. InitDebugHelp(hProcess, hThread, lpExt);
  1846. Status = ReadCallInfo( &CallInfo );
  1847. if (Status != 0)
  1848. {
  1849. return;
  1850. }
  1851. if ( CallInfo.Message )
  1852. {
  1853. Status = LsaReadMemory(CallInfo.Message, sizeof(SPM_LPC_MESSAGE), &Message);
  1854. ShowLpcMessage(CallInfo.Message, &Message);
  1855. }
  1856. else
  1857. {
  1858. DebuggerOut("TLS entry was NULL!\n");
  1859. }
  1860. }
  1861. extern"C"
  1862. void
  1863. GetTls( HANDLE hProcess,
  1864. HANDLE hThread,
  1865. DWORD dwCurrentPc,
  1866. PNTSD_EXTENSION_APIS lpExt,
  1867. LPSTR pszCommand)
  1868. {
  1869. TEB * Teb;
  1870. DWORD Index;
  1871. InitDebugHelp(hProcess, hThread, lpExt);
  1872. Index = (DWORD)((ULONG_PTR)GetExpr(pszCommand));
  1873. Teb = GetTeb(hThread);
  1874. if (!Teb)
  1875. {
  1876. DebuggerOut("Could not read TEB\n");
  1877. }
  1878. else
  1879. {
  1880. DebuggerOut("TLS %#x is %p\n", Index, Teb->TlsSlots[Index]);
  1881. FreeHeap(Teb);
  1882. }
  1883. }
  1884. PVOID
  1885. ShowTask(
  1886. PVOID pTask)
  1887. {
  1888. LSAP_THREAD_TASK Task;
  1889. UCHAR Symbol[256];
  1890. ULONG_PTR Disp;
  1891. if (pTask)
  1892. {
  1893. LsaReadMemory(pTask, sizeof(LSAP_THREAD_TASK), &Task);
  1894. }
  1895. else
  1896. {
  1897. return (NULL);
  1898. }
  1899. DebuggerOut("Task at %p:\n", pTask);
  1900. LsaGetSymbol((ULONG_PTR)Task.pFunction, Symbol, &Disp);
  1901. DebuggerOut(" Function \t%s\n", Symbol);
  1902. DebuggerOut(" Parameter \t%p\n", Task.pvParameter);
  1903. DebuggerOut(" Session \t%p\n", Task.pSession);
  1904. return(Task.Next.Flink);
  1905. }
  1906. void
  1907. DumpQueue( HANDLE hProcess,
  1908. HANDLE hThread,
  1909. DWORD dwCurrentPc,
  1910. PNTSD_EXTENSION_APIS lpExt,
  1911. LPSTR pszCommand)
  1912. {
  1913. LSAP_TASK_QUEUE Queue;
  1914. PVOID pTask;
  1915. PVOID pQueue;
  1916. BOOL Single = FALSE;
  1917. UCHAR Symbol[ MAX_PATH ];
  1918. ULONG_PTR Offset;
  1919. InitDebugHelp(hProcess, hThread, lpExt);
  1920. pQueue = GetExpr(pszCommand);
  1921. if (!pQueue)
  1922. {
  1923. pQueue = (PVOID) GetExpr(GLOBALQUEUE);
  1924. }
  1925. LsaReadMemory(pQueue, sizeof(Queue), &Queue);
  1926. DebuggerOut("Queue at %p\n", pQueue);
  1927. DebuggerOut(" Type \t%d : %s\n", Queue.Type, QueueTypeName( Queue.Type ) );
  1928. DebuggerOut(" Semaphore\t%d\n", Queue.hSemaphore);
  1929. DebuggerOut(" Tasks \t%d\n", Queue.Tasks);
  1930. DebuggerOut(" pTasks \t%p %p\n", Queue.pTasks.Flink,
  1931. Queue.pTasks.Blink);
  1932. DebuggerOut(" pNext \t%p\n", Queue.pNext);
  1933. DebuggerOut(" pShared \t%p\n", Queue.pShared);
  1934. DebuggerOut(" TotalThd \t%d\n", Queue.TotalThreads);
  1935. DebuggerOut(" IdleThd \t%d\n", Queue.IdleThreads);
  1936. if ( Queue.OwnerSession )
  1937. {
  1938. DebuggerOut(" Session \t%p\n", Queue.OwnerSession );
  1939. }
  1940. LsaGetSymbol((ULONG_PTR) Queue.pOriginal, Symbol, &Offset );
  1941. if ( Offset )
  1942. {
  1943. DebuggerOut(" Parent \t%p\n", Queue.pOriginal );
  1944. }
  1945. else
  1946. {
  1947. DebuggerOut(" Parent \t%s\n", Symbol );
  1948. }
  1949. DebuggerOut(" Tasks Queued\t%d\n", Queue.QueuedCounter);
  1950. DebuggerOut(" Tasks Read\t%d\n", Queue.TaskCounter);
  1951. DebuggerOut(" Tasks Missed\t%d\n", Queue.MissedTasks );
  1952. DebuggerOut(" Tasks High Water\t%d\n", Queue.TaskHighWater );
  1953. DebuggerOut(" StartSync\t%x\n", Queue.StartSync );
  1954. DebuggerOut(" Req Thread\t%d\n", Queue.ReqThread );
  1955. DebuggerOut(" Max Threads\t%d\n", Queue.MaxThreads );
  1956. pTask = Queue.pTasks.Flink;
  1957. while ((pTask != NULL) && (pTask != (PLSAP_THREAD_TASK) Queue.pTasks.Blink))
  1958. {
  1959. pTask = ShowTask(pTask);
  1960. if (lpExt->lpCheckControlCRoutine())
  1961. {
  1962. break;
  1963. }
  1964. }
  1965. }
  1966. void
  1967. DumpThreadTask( HANDLE hProcess,
  1968. HANDLE hThread,
  1969. DWORD dwCurrentPc,
  1970. PNTSD_EXTENSION_APIS lpExt,
  1971. LPSTR pszCommand)
  1972. {
  1973. LSAP_THREAD_TASK Task;
  1974. PVOID pTask;
  1975. BOOL Single = FALSE;
  1976. InitDebugHelp(hProcess, hThread, lpExt);
  1977. pTask = GetExpr(pszCommand);
  1978. if (!pTask)
  1979. {
  1980. return;
  1981. }
  1982. else
  1983. {
  1984. Single = TRUE;
  1985. }
  1986. do
  1987. {
  1988. pTask = ShowTask( pTask );
  1989. if (lpExt->lpCheckControlCRoutine())
  1990. {
  1991. break;
  1992. }
  1993. } while ( pTask && !Single );
  1994. }
  1995. VOID
  1996. ShowNegCreds(
  1997. PNEG_CREDS pCreds,
  1998. PVOID pOriginalAddr)
  1999. {
  2000. DWORD i;
  2001. UCHAR Buffer[ MAX_PATH ];
  2002. DebuggerOut("NEG_CREDS at %p\n", pOriginalAddr );
  2003. DebuggerOut(" List \t%p %p\n", pCreds->List.Flink, pCreds->List.Blink );
  2004. DebuggerOut(" RefCount \t%d\n", pCreds->RefCount );
  2005. DebuggerOut(" Process \t%x\n", pCreds->ClientProcessId );
  2006. DebuggerOut(" LogonId \t%x %x\n",
  2007. pCreds->ClientLogonId.HighPart, pCreds->ClientLogonId.LowPart );
  2008. DisplayFlags( pCreds->Flags, 5, NegCredFlags, Buffer );
  2009. DebuggerOut(" Flags \t%x : %s\n", pCreds->Flags, Buffer );
  2010. if ( pCreds->Flags & NEGCRED_MULTI )
  2011. {
  2012. DebuggerOut(" AdditionalCreds\t%p %p\n",
  2013. pCreds->AdditionalCreds.Flink, pCreds->AdditionalCreds.Blink );
  2014. }
  2015. DebuggerOut(" Count \t%d\n", pCreds->Count );
  2016. for ( i = 0 ; i < pCreds->Count ; i++ )
  2017. {
  2018. DebuggerOut(" Creds[%2d] \tPackage %p, Handle %p : %p \n", i,
  2019. pCreds->Creds[i].Package, pCreds->Creds[i].Handle.dwUpper,
  2020. pCreds->Creds[i].Handle.dwLower );
  2021. }
  2022. }
  2023. PVOID
  2024. ReadAndDumpNegCred(
  2025. PVOID Address
  2026. )
  2027. {
  2028. #define CRED_SIZE (sizeof( NEG_CREDS ) + 16 * sizeof( NEG_CRED_HANDLE ) )
  2029. UCHAR Buffer[ CRED_SIZE ];
  2030. PNEG_CREDS pCreds ;
  2031. DWORD Size;
  2032. LsaReadMemory( Address, sizeof( NEG_CREDS ), Buffer );
  2033. pCreds = (PNEG_CREDS) Buffer ;
  2034. Size = sizeof( NEG_CREDS ) + (pCreds->Count - 1) * sizeof( NEG_CRED_HANDLE );
  2035. if ( Size <= CRED_SIZE )
  2036. {
  2037. LsaReadMemory( Address, Size, Buffer );
  2038. }
  2039. else
  2040. {
  2041. LsaReadMemory( Address, CRED_SIZE, Buffer );
  2042. pCreds->Count = 16;
  2043. }
  2044. ShowNegCreds( pCreds, Address );
  2045. return pCreds->List.Flink ;
  2046. }
  2047. VOID
  2048. DumpNegCred(
  2049. HANDLE hProcess,
  2050. HANDLE hThread,
  2051. DWORD dwCurrentPc,
  2052. PNTSD_EXTENSION_APIS lpExt,
  2053. LPSTR pszCommand)
  2054. {
  2055. PVOID Base ;
  2056. PVOID Next ;
  2057. PVOID p ;
  2058. InitDebugHelp(hProcess, hThread, lpExt);
  2059. p = GetExpr(pszCommand);
  2060. if ( p != 0 )
  2061. {
  2062. ReadAndDumpNegCred( p );
  2063. }
  2064. else
  2065. {
  2066. p = GetExpr( "lsasrv!NegCredList" );
  2067. LsaReadMemory( p, sizeof(PVOID), &Next );
  2068. while ( Next != p )
  2069. {
  2070. Next = ReadAndDumpNegCred( Next );
  2071. if (lpExt->lpCheckControlCRoutine())
  2072. {
  2073. break;
  2074. }
  2075. }
  2076. }
  2077. }
  2078. VOID
  2079. ShowNegContext(
  2080. PNEG_CONTEXT Context,
  2081. PVOID pOriginalAddr)
  2082. {
  2083. UCHAR TimeBuf[ MAX_PATH ];
  2084. if ( ( Context->CheckMark != NEGCONTEXT_CHECK ) &&
  2085. ( Context->CheckMark != NEGCONTEXT2_CHECK ) )
  2086. {
  2087. DebuggerOut("****** Invalid Context Record *******\n");
  2088. return;
  2089. }
  2090. DebuggerOut("NEG_CONTEXT at %p\n", pOriginalAddr);
  2091. DebuggerOut(" Creds \t%#x\n", Context->Creds );
  2092. DebuggerOut(" CredIndex \t%d\n", Context->CredIndex );
  2093. DebuggerOut(" Handle \t%p : %p\n", Context->Handle.dwUpper, Context->Handle.dwLower );
  2094. DebuggerOut(" Target at \t%p \n", Context->Target.Buffer );
  2095. DebuggerOut(" Attributes \t%x\n", Context->Attributes );
  2096. ShowSecBuffer(" MappedBuffer ",&Context->MappedBuffer );
  2097. DebuggerOut(" Mapped \t%s\n", Context->Mapped ? "TRUE" : "FALSE");
  2098. DebuggerOut(" CallCount \t%d\n", Context->CallCount );
  2099. DebuggerOut(" LastStatus \t%x\n", Context->LastStatus );
  2100. DebuggerOut(" Check \t%p\n", Context->Check );
  2101. DebuggerOut(" Buffer \t%p\n", Context->Buffer );
  2102. CTimeStamp( &Context->Expiry, (PCHAR)TimeBuf, FALSE );
  2103. DebuggerOut(" Expiry \t%s\n", TimeBuf );
  2104. DisplayFlags( Context->Flags, 7, NegContextFlags, TimeBuf );
  2105. DebuggerOut(" Flags \t%x : %s\n", Context->Flags, TimeBuf );
  2106. DebuggerOut(" Message \t%p\n", Context->Message );
  2107. DebuggerOut(" CurrentSize \t%#x\n", Context->CurrentSize );
  2108. DebuggerOut(" TotalSize \t%#x\n", Context->TotalSize );
  2109. DebuggerOut(" SupportedMechs\t%p\n", Context->SupportedMechs );
  2110. }
  2111. VOID
  2112. DumpNegContext(
  2113. HANDLE hProcess,
  2114. HANDLE hThread,
  2115. DWORD dwCurrentPc,
  2116. PNTSD_EXTENSION_APIS lpExt,
  2117. LPSTR pszCommand)
  2118. {
  2119. NEG_CONTEXT Context ;
  2120. PVOID p;
  2121. InitDebugHelp(hProcess, hThread, lpExt);
  2122. p = GetExpr(pszCommand);
  2123. LsaReadMemory( p, sizeof( NEG_CONTEXT ), &Context );
  2124. ShowNegContext( &Context, p );
  2125. }
  2126. VOID
  2127. DumpSecBuffer(
  2128. HANDLE hProcess,
  2129. HANDLE hThread,
  2130. DWORD dwCurrentPc,
  2131. PNTSD_EXTENSION_APIS lpExt,
  2132. LPSTR pszCommand)
  2133. {
  2134. SecBuffer Buf;
  2135. PVOID p;
  2136. InitDebugHelp(hProcess, hThread, lpExt);
  2137. p = GetExpr(pszCommand);
  2138. LsaReadMemory( p, sizeof(SecBuffer), &Buf );
  2139. ShowSecBuffer("Buffer\t", &Buf );
  2140. }
  2141. VOID
  2142. DumpSecBufferDesc(
  2143. HANDLE hProcess,
  2144. HANDLE hThread,
  2145. DWORD dwCurrentPc,
  2146. PNTSD_EXTENSION_APIS lpExt,
  2147. LPSTR pszCommand)
  2148. {
  2149. SecBuffer Buf[16];
  2150. SecBufferDesc Desc;
  2151. PVOID p;
  2152. ULONG i;
  2153. InitDebugHelp(hProcess, hThread, lpExt);
  2154. p = GetExpr(pszCommand);
  2155. LsaReadMemory( p, sizeof(SecBufferDesc), &Desc );
  2156. LsaReadMemory( Desc.pBuffers, sizeof(SecBuffer) * min(Desc.cBuffers, 16), Buf);
  2157. DebuggerOut("SecBufferDesc at %p\n", p);
  2158. DebuggerOut(" ulVersion \t%d\n", Desc.ulVersion );
  2159. DebuggerOut(" pBuffers \t%p\n", Desc.pBuffers );
  2160. DebuggerOut(" cBuffers \t%x\n", Desc.cBuffers );
  2161. for (i = 0 ; i < min(Desc.cBuffers, 16) ; i++ )
  2162. {
  2163. ShowSecBuffer(" Buffer\t", &Buf[i] );
  2164. }
  2165. }
  2166. VOID
  2167. DumpHandleList(
  2168. HANDLE hProcess,
  2169. HANDLE hThread,
  2170. DWORD dwCurrentPc,
  2171. PNTSD_EXTENSION_APIS lpExt,
  2172. LPSTR pszCommand)
  2173. {
  2174. SEC_HANDLE_ENTRY List ;
  2175. PVOID p;
  2176. ULONG i;
  2177. InitDebugHelp(hProcess, hThread, lpExt);
  2178. p = GetExpr(pszCommand);
  2179. List.List.Flink = (PLIST_ENTRY) p;
  2180. do
  2181. {
  2182. LsaReadMemory( List.List.Flink, sizeof( List ), &List );
  2183. DebuggerOut(" Handle %p : %p, Ref = %d, Context = %p \n",
  2184. List.Handle.dwLower,
  2185. List.Handle.dwUpper,
  2186. List.RefCount,
  2187. List.Context );
  2188. if (lpExt->lpCheckControlCRoutine())
  2189. {
  2190. break;
  2191. }
  2192. } while ( List.List.Flink != p );
  2193. }
  2194. VOID
  2195. ShowSmallTable(
  2196. PSMALL_HANDLE_TABLE Table,
  2197. LONG Indent
  2198. )
  2199. {
  2200. UCHAR Buffer[ 64 ];
  2201. UCHAR IndentString[ 80 ];
  2202. ULONG_PTR i;
  2203. for ( i = 0 ; i < ( DWORD )Indent; i++)
  2204. {
  2205. IndentString[ i ] = ' ';
  2206. }
  2207. IndentString[ Indent ] = '\0' ;
  2208. DisplayFlags( Table->Flags, 3, ShtFlags, Buffer );
  2209. DebuggerOut("%s Flags \t%x: %s\n", IndentString, Table->Flags, Buffer );
  2210. DebuggerOut("%s Count \t%d\n", IndentString, Table->Count );
  2211. DebuggerOut("%s Pending\t%p\n", IndentString, Table->PendingHandle );
  2212. DebuggerOut("%s ListHead\t%p\n", IndentString, Table->List.Flink );
  2213. if ( Table->DeleteCallback )
  2214. {
  2215. LsaGetSymbol((ULONG_PTR) Table->DeleteCallback, Buffer, &i );
  2216. DebuggerOut( "%s Callback\t%s\n", IndentString, Buffer );
  2217. }
  2218. }
  2219. VOID
  2220. ShowLargeTable(
  2221. int indent,
  2222. PLARGE_HANDLE_TABLE Table
  2223. )
  2224. {
  2225. LARGE_HANDLE_TABLE SubTable ;
  2226. UCHAR Buffer[ 64 ];
  2227. UCHAR Indent[ 64 ];
  2228. ULONG_PTR i;
  2229. for (i = 0 ; i < ( ULONG )indent ; i++ )
  2230. {
  2231. Indent[i] = ' ';
  2232. }
  2233. Indent[indent] = '\0';
  2234. DisplayFlags( Table->Flags, 3, LhtFlags, Buffer );
  2235. DebuggerOut("%s Flags \t%x: %s\n", Indent, Table->Flags, Buffer );
  2236. DebuggerOut("%s Depth \t%d\n", Indent, Table->Depth );
  2237. DebuggerOut("%s Parent \t%p\n", Indent, Table->Parent );
  2238. DebuggerOut("%s Count \t%d\n", Indent, Table->Count );
  2239. if ( Table->DeleteCallback )
  2240. {
  2241. LsaGetSymbol((ULONG_PTR) Table->DeleteCallback, Buffer, &i );
  2242. DebuggerOut("%s Callback \t%s\n", Indent, Buffer );
  2243. }
  2244. DebuggerOut("%s Lists\n", Indent );
  2245. for ( i = 0 ; i < HANDLE_TABLE_SIZE ; i++ )
  2246. {
  2247. if ( Table->Lists[i].Flags & LHT_SUB_TABLE )
  2248. {
  2249. if ( Table->Lists[i].Flags & (~LHT_SUB_TABLE))
  2250. {
  2251. DebuggerOut("%s CORRUPT\n", Indent);
  2252. }
  2253. else
  2254. {
  2255. DebuggerOut("%s %x : Sub Table at %p\n", Indent, i, Table->Lists[i].List.Flink );
  2256. LsaReadMemory( Table->Lists[i].List.Flink,
  2257. sizeof( LARGE_HANDLE_TABLE),
  2258. &SubTable );
  2259. ShowLargeTable( 4+indent, &SubTable );
  2260. }
  2261. }
  2262. else
  2263. {
  2264. DebuggerOut("%s List %x\n", Indent, i );
  2265. ShowSmallTable( &Table->Lists[i], 4+indent );
  2266. }
  2267. }
  2268. }
  2269. VOID
  2270. DumpHandleTable(
  2271. HANDLE hProcess,
  2272. HANDLE hThread,
  2273. DWORD dwCurrentPc,
  2274. PNTSD_EXTENSION_APIS lpExt,
  2275. LPSTR pszCommand)
  2276. {
  2277. DWORD Tag;
  2278. LARGE_HANDLE_TABLE Large ;
  2279. SMALL_HANDLE_TABLE Small ;
  2280. PVOID Table ;
  2281. InitDebugHelp(hProcess, hThread, lpExt);
  2282. Table = GetExpr( pszCommand );
  2283. if ( Table == NULL )
  2284. {
  2285. return;
  2286. }
  2287. LsaReadMemory( Table, sizeof(DWORD), &Tag );
  2288. if ( Tag == LHT_TAG )
  2289. {
  2290. DebuggerOut("LARGE_HANDLE_TABLE at %p\n", Table );
  2291. LsaReadMemory( Table, sizeof( Large ), &Large );
  2292. ShowLargeTable( 0, &Large );
  2293. }
  2294. else if ( Tag == SHT_TAG )
  2295. {
  2296. DebuggerOut("SMALL_HANDLE_TABLE at %p\n", Table );
  2297. LsaReadMemory( Table, sizeof( Small ), &Small );
  2298. ShowSmallTable( &Small, 0 );
  2299. }
  2300. else
  2301. {
  2302. DebuggerOut("%p - not a handle table\n", Table );
  2303. }
  2304. }
  2305. VOID
  2306. ShowLogonSession(
  2307. PVOID Base,
  2308. PLSAP_LOGON_SESSION LogonSession,
  2309. BOOL Verbose
  2310. )
  2311. {
  2312. SECURITY_STRING LocalString = { 0 };
  2313. PWSTR Temp ;
  2314. SECURITY_STRING LocalCopy = { 0 };
  2315. CHAR Buffer[ 80 ];
  2316. DebuggerOut( "LSAP_LOGON_SESSION at %p\n", Base );
  2317. MapString( &LogonSession->AuthorityName, &LocalString );
  2318. Temp = LocalString.Buffer ;
  2319. LocalString.Buffer = NULL ;
  2320. MapString( &LogonSession->AccountName, &LocalString );
  2321. DebuggerOut( " LogonId %x:%x (%s) %ws \\ %ws \n",
  2322. LogonSession->LogonId.HighPart,
  2323. LogonSession->LogonId.LowPart,
  2324. LogonTypeName( LogonSession->LogonType),
  2325. Temp, LocalString.Buffer );
  2326. FreeHeap( Temp );
  2327. FreeHeap( LocalString.Buffer );
  2328. if ( Verbose )
  2329. {
  2330. DebuggerOut( " Package %d, caller <%x>, attr = %x\n",
  2331. LogonSession->CreatingPackage,
  2332. LogonSession->Process,
  2333. LogonSession->ContextAttr );
  2334. DebuggerOut( " SID\t" );
  2335. LocalDumpSid( LogonSession->UserSid );
  2336. CTimeStamp( &LogonSession->LogonTime, Buffer, TRUE );
  2337. DebuggerOut( " Logon Time\t%s\n", Buffer );
  2338. }
  2339. }
  2340. VOID
  2341. DumpLogonSession(
  2342. HANDLE hProcess,
  2343. HANDLE hThread,
  2344. DWORD dwCurrentPc,
  2345. PNTSD_EXTENSION_APIS lpExt,
  2346. LPSTR pszCommand)
  2347. {
  2348. PVOID p, p1;
  2349. PVOID Actual ;
  2350. PSTR Colon ;
  2351. LSAP_LOGON_SESSION LogonSession ;
  2352. LUID Luid ;
  2353. BOOLEAN DumpAll;
  2354. InitDebugHelp( hProcess,
  2355. hThread,
  2356. lpExt);
  2357. Colon = strchr( pszCommand, ':' );
  2358. if ( Colon )
  2359. {
  2360. if (2 != sscanf( pszCommand, "%x:%x", &Luid.HighPart, &Luid.LowPart ))
  2361. {
  2362. DebuggerOut( "Invalid argument: '%s'\n", pszCommand );
  2363. }
  2364. DumpAll = TRUE ;
  2365. p = NULL ;
  2366. }
  2367. else
  2368. {
  2369. Luid.HighPart = Luid.LowPart = 0 ;
  2370. p = GetExpr( pszCommand );
  2371. DumpAll = FALSE ;
  2372. }
  2373. if ( p == NULL )
  2374. {
  2375. p1 = GetExpr( "lsasrv!logonsessionlist" );
  2376. LsaReadMemory( p1, sizeof( PVOID ), &p );
  2377. DumpAll = TRUE ;
  2378. }
  2379. else
  2380. {
  2381. p1 = NULL ;
  2382. }
  2383. if ( p == NULL )
  2384. {
  2385. DebuggerOut( "Unable to get value of lsasrv!logonsessionlist\n" );
  2386. return;
  2387. }
  2388. while ( p != p1 )
  2389. {
  2390. if ( DumpAll )
  2391. {
  2392. Actual = CONTAINING_RECORD( p, LSAP_LOGON_SESSION, List );
  2393. }
  2394. else
  2395. {
  2396. Actual = p ;
  2397. }
  2398. LsaReadMemory( Actual, sizeof( LSAP_LOGON_SESSION ), &LogonSession );
  2399. if ( RtlIsZeroLuid( &Luid) ||
  2400. RtlEqualLuid( &Luid, &LogonSession.LogonId) ||
  2401. (!DumpAll) )
  2402. {
  2403. ShowLogonSession( Actual, &LogonSession, (!DumpAll) );
  2404. }
  2405. p = LogonSession.List.Flink ;
  2406. if ( (!DumpAll) || ( p1 == NULL ) )
  2407. {
  2408. break;
  2409. }
  2410. }
  2411. }
  2412. void
  2413. ShowLsaHandle(
  2414. IN LSAP_DB_HANDLE DbHandle,
  2415. IN BOOLEAN Index
  2416. )
  2417. {
  2418. SECURITY_STRING LocalString;
  2419. #ifdef DBG
  2420. LARGE_INTEGER LocalTime;
  2421. TIME_FIELDS TimeFields;
  2422. NTSTATUS Status;
  2423. #endif
  2424. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2425. DebuggerOut( "Next \t0x%lp\n", DbHandle->Next );
  2426. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2427. DebuggerOut( "Previous \t0x%lp\n", DbHandle->Previous );
  2428. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2429. DebuggerOut( "UserHandleList Flink \t0x%lp\n", DbHandle->UserHandleList.Flink );
  2430. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2431. DebuggerOut( "UserHandleList Blink \t0x%lp\n", DbHandle->UserHandleList.Blink );
  2432. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2433. DebuggerOut( "Allocated \t%s\n", DbHandle->Allocated ? "TRUE" : "FALSE" );
  2434. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2435. DebuggerOut( "ReferenceCount\t%lu\n", DbHandle->ReferenceCount );
  2436. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2437. LocalString.Buffer = NULL;
  2438. MapString( ( PSECURITY_STRING )( &DbHandle->LogicalNameU ),
  2439. &LocalString );
  2440. DebuggerOut( "LogicalNameU \t%ws\n", LocalString.Buffer );
  2441. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2442. FreeHeap( LocalString.Buffer );
  2443. LocalString.Buffer = NULL;
  2444. MapString( ( PSECURITY_STRING )( &DbHandle->PhysicalNameU ),
  2445. &LocalString );
  2446. DebuggerOut( "PhysicalNameU \t%ws\n", LocalString.Buffer );
  2447. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2448. FreeHeap( LocalString.Buffer );
  2449. if ( DbHandle->Sid ) {
  2450. DebuggerOut( "Sid \t" );
  2451. LocalDumpSid( DbHandle->Sid );
  2452. DebuggerOut( "\n" );
  2453. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2454. } else {
  2455. DebuggerOut( "Sid \t%s\n", "<NULL>" );
  2456. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2457. }
  2458. DebuggerOut( "KeyHandle \t0x%lx\n", DbHandle->KeyHandle );
  2459. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2460. DebuggerOut( "ObjectTypeId \t0x%lu\n", DbHandle->ObjectTypeId );
  2461. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2462. DebuggerOut( "ContainerHandle\t0x%lp\n", DbHandle->ContainerHandle );
  2463. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2464. DebuggerOut( "DesiredAccess \t0x%08lx\n", DbHandle->DesiredAccess );
  2465. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2466. DebuggerOut( "GrantedAccess \t0x%08lx\n", DbHandle->GrantedAccess );
  2467. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2468. DebuggerOut( "RequestAccess \t0x%08lx\n", DbHandle->RequestedAccess );
  2469. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2470. DebuggerOut( "GenerateOnClose\t%s\n",DbHandle->GenerateOnClose ? "TRUE" : "FALSE" );
  2471. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2472. DebuggerOut( "Trusted \t%s\n", DbHandle->Trusted ? "TRUE" : "FALSE" );
  2473. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2474. DebuggerOut( "DeletedObject \t%s\n", DbHandle->DeletedObject ? "TRUE" : "FALSE" );
  2475. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2476. DebuggerOut( "NetworkClient \t%s\n",DbHandle->NetworkClient ? "TRUE" : "FALSE" );
  2477. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2478. DebuggerOut( "Options \t0x%08lx\n", DbHandle->Options);
  2479. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2480. if ( DbHandle->PhysicalNameDs.Length == 0 ) {
  2481. DebuggerOut( "PhysicalNameDs\t%s\n", "<NULL>" );
  2482. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2483. } else {
  2484. LocalString.Buffer = NULL;
  2485. MapString( ( PSECURITY_STRING )( &DbHandle->PhysicalNameDs ),
  2486. &LocalString );
  2487. DebuggerOut( "PhysicalNameDs\t%ws\n", LocalString.Buffer );
  2488. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2489. FreeHeap( LocalString.Buffer );
  2490. }
  2491. DebuggerOut( "fWriteDs \t%s\n", DbHandle->fWriteDs ? "TRUE" : "FALSE" );
  2492. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2493. DebuggerOut( "ObjectOptions \t0x%08lx\n", DbHandle->ObjectOptions );
  2494. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2495. DebuggerOut( "UserEntry \t0x%lp\n", DbHandle->UserEntry );
  2496. #ifdef DBG
  2497. Status = RtlSystemTimeToLocalTime( &DbHandle->HandleCreateTime, &LocalTime );
  2498. if ( !NT_SUCCESS( Status ) ) {
  2499. DebuggerOut( "Can't convert create time from GMT to Local time: 0x%lx\n", Status );
  2500. } else {
  2501. RtlTimeToTimeFields( &LocalTime, &TimeFields );
  2502. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2503. DebuggerOut( "HandleCreateTime \t%ld/%ld/%ld %ld:%2.2ld:%2.2ld (%8.8lx %8.8lx)\n",
  2504. TimeFields.Month,
  2505. TimeFields.Day,
  2506. TimeFields.Year,
  2507. TimeFields.Hour,
  2508. TimeFields.Minute,
  2509. TimeFields.Second,
  2510. DbHandle->HandleCreateTime.LowPart,
  2511. DbHandle->HandleCreateTime.HighPart );
  2512. }
  2513. Status = RtlSystemTimeToLocalTime( &DbHandle->HandleLastAccessTime, &LocalTime );
  2514. if ( !NT_SUCCESS( Status ) ) {
  2515. DebuggerOut( "Can't convert LastAccess time from GMT to Local time: 0x%lx\n", Status );
  2516. } else {
  2517. RtlTimeToTimeFields( &LocalTime, &TimeFields );
  2518. DebuggerOut( "%c", Index ? '\t' : '\0' );
  2519. DebuggerOut( "HandleLastAccessTime \t%ld/%ld/%ld %ld:%2.2ld:%2.2ld (%8.8lx %8.8lx)\n",
  2520. TimeFields.Month,
  2521. TimeFields.Day,
  2522. TimeFields.Year,
  2523. TimeFields.Hour,
  2524. TimeFields.Minute,
  2525. TimeFields.Second,
  2526. DbHandle->HandleLastAccessTime.LowPart,
  2527. DbHandle->HandleLastAccessTime.HighPart );
  2528. }
  2529. #endif
  2530. }
  2531. VOID
  2532. DumpLsaHandle(
  2533. HANDLE hProcess,
  2534. HANDLE hThread,
  2535. DWORD dwCurrentPc,
  2536. PNTSD_EXTENSION_APIS lpExt,
  2537. LPSTR pszCommand)
  2538. {
  2539. _LSAP_DB_HANDLE DbHandle;
  2540. PVOID Handle;
  2541. InitDebugHelp( hProcess,
  2542. hThread,
  2543. lpExt);
  2544. Handle = GetExpr( pszCommand );
  2545. if ( Handle == NULL ) {
  2546. return;
  2547. }
  2548. LsaReadMemory( Handle,
  2549. sizeof( _LSAP_DB_HANDLE ),
  2550. &DbHandle );
  2551. ShowLsaHandle( &DbHandle, FALSE );
  2552. }
  2553. void
  2554. ShowLsaHandleTable(
  2555. IN LSAP_DB_HANDLE HandleTable
  2556. )
  2557. {
  2558. _LSAP_DB_HANDLE ThisHandle, *Stop;
  2559. ULONG i = 0;
  2560. LsaReadMemory( HandleTable->Next,
  2561. sizeof( _LSAP_DB_HANDLE ),
  2562. &ThisHandle );
  2563. Stop = ThisHandle.Previous;
  2564. while ( ThisHandle.Next != Stop ) {
  2565. DebuggerOut( "LsaHandleTable entry %lu\n", i++ );
  2566. ShowLsaHandle( &ThisHandle, TRUE );
  2567. LsaReadMemory( ThisHandle.Next,
  2568. sizeof( _LSAP_DB_HANDLE ),
  2569. &ThisHandle );
  2570. }
  2571. return;
  2572. }
  2573. VOID
  2574. DumpLsaHandleTable(
  2575. HANDLE hProcess,
  2576. HANDLE hThread,
  2577. DWORD dwCurrentPc,
  2578. PNTSD_EXTENSION_APIS lpExt,
  2579. LPSTR pszCommand)
  2580. {
  2581. _LSAP_DB_HANDLE HandleTable;
  2582. PVOID Table;
  2583. InitDebugHelp( hProcess,
  2584. hThread,
  2585. lpExt);
  2586. Table = GetExpr( pszCommand );
  2587. if ( Table == NULL ) {
  2588. return;
  2589. }
  2590. LsaReadMemory( Table,
  2591. sizeof( _LSAP_DB_HANDLE ),
  2592. &HandleTable );
  2593. ShowLsaHandleTable( &HandleTable );
  2594. }
  2595. VOID
  2596. DumpLsaSidCache(
  2597. HANDLE hProcess,
  2598. HANDLE hThread,
  2599. DWORD dwCurrentPc,
  2600. PNTSD_EXTENSION_APIS lpExt,
  2601. LPSTR pszCommand)
  2602. {
  2603. PVOID RawAddress;
  2604. PVOID pEntry;
  2605. LSAP_DB_SID_CACHE_ENTRY Entry;
  2606. NTSTATUS Status;
  2607. LARGE_INTEGER LocalTime;
  2608. TIME_FIELDS TimeFields;
  2609. UNICODE_STRING Dummy;
  2610. WCHAR NameBuffer[256];
  2611. InitDebugHelp( hProcess,
  2612. hThread,
  2613. lpExt);
  2614. pEntry = GetExpr( pszCommand );
  2615. if ( pEntry == NULL ) {
  2616. //
  2617. // Find the address of the sid cache
  2618. //
  2619. RawAddress = (VOID *) GetExpr("lsasrv!LsapSidCache");
  2620. if ( NULL == RawAddress ) {
  2621. DebuggerOut( "Can't locate the variable lsasrv!SidCache\nPlease get correct symbols or update this debugger extension\n" );
  2622. return;
  2623. }
  2624. pEntry = RawAddress;
  2625. (VOID) LsaReadMemory( RawAddress, sizeof(pEntry), (PVOID) &pEntry );
  2626. if ( NULL == pEntry ) {
  2627. DebuggerOut( "Sid cache is empty!\n" );
  2628. return;
  2629. }
  2630. } else {
  2631. RtlZeroMemory( &Entry, sizeof( Entry ) );
  2632. (VOID) LsaReadMemory( pEntry, sizeof(Entry), (PVOID) &Entry );
  2633. pEntry = Entry.Next;
  2634. }
  2635. //
  2636. // The first is the head and as such is empty
  2637. //
  2638. DebuggerOut( "Head of list located at address 0x%p\n", pEntry );
  2639. if ( !pEntry ) {
  2640. DebuggerOut( "Sid cache is empty!\n" );
  2641. return;
  2642. }
  2643. while ( pEntry ) {
  2644. //
  2645. // Read the entry
  2646. //
  2647. RtlZeroMemory( &Entry, sizeof( Entry ) );
  2648. (VOID) LsaReadMemory( pEntry, sizeof(Entry), (PVOID) &Entry );
  2649. //
  2650. // Print the entry
  2651. //
  2652. DebuggerOut( "New entry located at address 0x%p, next entry 0x%p\n", pEntry, Entry.Next );
  2653. if ( Entry.AccountName.Buffer ) {
  2654. RtlZeroMemory( NameBuffer, sizeof(NameBuffer) );
  2655. (VOID) LsaReadMemory( Entry.AccountName.Buffer,
  2656. Entry.AccountName.MaximumLength,
  2657. (PVOID) NameBuffer );
  2658. RtlInitUnicodeString( &Dummy, NameBuffer );
  2659. DebuggerOut( "Account Name: %wZ\n", &Dummy );
  2660. } else {
  2661. DebuggerOut( "No Account Name\n" );
  2662. }
  2663. if ( Entry.Sid ) {
  2664. DebuggerOut( "Account Sid: " );
  2665. PrintSid( hProcess,
  2666. hThread,
  2667. lpExt,
  2668. Entry.Sid );
  2669. } else {
  2670. DebuggerOut( "No Account Sid\n" );
  2671. }
  2672. if ( Entry.DomainName.Buffer ) {
  2673. RtlZeroMemory( NameBuffer, sizeof(NameBuffer) );
  2674. (VOID) LsaReadMemory( Entry.DomainName.Buffer,
  2675. Entry.DomainName.MaximumLength,
  2676. (PVOID) NameBuffer );
  2677. RtlInitUnicodeString( &Dummy, NameBuffer );
  2678. DebuggerOut( "Domain Name: %wZ\n", &Dummy );
  2679. } else {
  2680. DebuggerOut( "No Domain Name\n" );
  2681. }
  2682. if ( Entry.DomainSid ) {
  2683. DebuggerOut( "Domain Sid: " );
  2684. PrintSid( hProcess,
  2685. hThread,
  2686. lpExt,
  2687. Entry.DomainSid );
  2688. }
  2689. DebuggerOut( "Sid Type: %s\n", SidNameUseXLate( Entry.SidType ) );
  2690. Status = RtlSystemTimeToLocalTime( &Entry.CreateTime, &LocalTime );
  2691. if ( !NT_SUCCESS( Status ) ) {
  2692. DebuggerOut( "Can't convert create time from GMT to Local time: 0x%lx\n", Status );
  2693. } else {
  2694. RtlTimeToTimeFields( &LocalTime, &TimeFields );
  2695. DebuggerOut( "Create Time %ld/%ld/%ld %ld:%2.2ld:%2.2ld (%8.8lx %8.8lx)\n",
  2696. TimeFields.Month,
  2697. TimeFields.Day,
  2698. TimeFields.Year,
  2699. TimeFields.Hour,
  2700. TimeFields.Minute,
  2701. TimeFields.Second,
  2702. Entry.CreateTime.LowPart,
  2703. Entry.CreateTime.HighPart );
  2704. }
  2705. Status = RtlSystemTimeToLocalTime( &Entry.RefreshTime, &LocalTime );
  2706. if ( !NT_SUCCESS( Status ) ) {
  2707. DebuggerOut( "Can't convert Last Use time from GMT to Local time: 0x%lx\n", Status );
  2708. } else {
  2709. RtlTimeToTimeFields( &LocalTime, &TimeFields );
  2710. DebuggerOut( "Refresh Time %ld/%ld/%ld %ld:%2.2ld:%2.2ld (%8.8lx %8.8lx)\n",
  2711. TimeFields.Month,
  2712. TimeFields.Day,
  2713. TimeFields.Year,
  2714. TimeFields.Hour,
  2715. TimeFields.Minute,
  2716. TimeFields.Second,
  2717. Entry.LastUse.LowPart,
  2718. Entry.LastUse.HighPart );
  2719. }
  2720. Status = RtlSystemTimeToLocalTime( &Entry.ExpirationTime, &LocalTime );
  2721. if ( !NT_SUCCESS( Status ) ) {
  2722. DebuggerOut( "Can't convert expiration time from GMT to Local time: 0x%lx\n", Status );
  2723. } else {
  2724. RtlTimeToTimeFields( &LocalTime, &TimeFields );
  2725. DebuggerOut( "Expiration Time %ld/%ld/%ld %ld:%2.2ld:%2.2ld (%8.8lx %8.8lx)\n",
  2726. TimeFields.Month,
  2727. TimeFields.Day,
  2728. TimeFields.Year,
  2729. TimeFields.Hour,
  2730. TimeFields.Minute,
  2731. TimeFields.Second,
  2732. Entry.ExpirationTime.LowPart,
  2733. Entry.ExpirationTime.HighPart );
  2734. }
  2735. Status = RtlSystemTimeToLocalTime( &Entry.LastUse, &LocalTime );
  2736. if ( !NT_SUCCESS( Status ) ) {
  2737. DebuggerOut( "Can't convert Last Use time from GMT to Local time: 0x%lx\n", Status );
  2738. } else {
  2739. RtlTimeToTimeFields( &LocalTime, &TimeFields );
  2740. DebuggerOut( "Last Used %ld/%ld/%ld %ld:%2.2ld:%2.2ld (%8.8lx %8.8lx)\n",
  2741. TimeFields.Month,
  2742. TimeFields.Day,
  2743. TimeFields.Year,
  2744. TimeFields.Hour,
  2745. TimeFields.Minute,
  2746. TimeFields.Second,
  2747. Entry.LastUse.LowPart,
  2748. Entry.LastUse.HighPart );
  2749. }
  2750. DebuggerOut( "Flags: %d\n", Entry.Flags );
  2751. DebuggerOut( "\n" );
  2752. //
  2753. // Get the next entry
  2754. //
  2755. pEntry = Entry.Next;
  2756. } // while
  2757. return;
  2758. }
  2759. void
  2760. DumpLsaHandleTypeList(
  2761. IN PLIST_ENTRY ListEntry
  2762. )
  2763. {
  2764. PLIST_ENTRY Next, Read;
  2765. _LSAP_DB_HANDLE Handle, *HandlePtr;
  2766. ULONG i = 0;
  2767. Next = ListEntry->Flink;
  2768. while ( Next != ListEntry ) {
  2769. HandlePtr = CONTAINING_RECORD( Next,
  2770. struct _LSAP_DB_HANDLE,
  2771. Next );
  2772. LsaReadMemory( HandlePtr,
  2773. sizeof( _LSAP_DB_HANDLE ),
  2774. &Handle );
  2775. DebuggerOut( "Handle entry %lu\n", i++);
  2776. ShowLsaHandle( &Handle, TRUE );
  2777. Next = HandlePtr->UserHandleList.Flink;
  2778. }
  2779. }
  2780. void
  2781. ShowLsaHandleTableEx(
  2782. IN PLSAP_DB_HANDLE_TABLE HandleTable
  2783. )
  2784. {
  2785. PLIST_ENTRY HandleEntry;
  2786. PLSAP_DB_HANDLE_TABLE_USER_ENTRY CurrentUserEntry = NULL;
  2787. LSAP_DB_HANDLE_TABLE_USER_ENTRY ThisUserEntry;
  2788. ULONG i = 0;
  2789. HandleEntry = HandleTable->UserHandleList.Flink;
  2790. for ( i = 0; i < HandleTable->UserCount; i++ ) {
  2791. CurrentUserEntry = CONTAINING_RECORD( HandleEntry,
  2792. LSAP_DB_HANDLE_TABLE_USER_ENTRY,
  2793. Next );
  2794. LsaReadMemory( CurrentUserEntry,
  2795. sizeof( LSAP_DB_HANDLE_TABLE_USER_ENTRY ),
  2796. &ThisUserEntry );
  2797. DebuggerOut( "HandleTable Entry #%lu\n", i );
  2798. DebuggerOut( "User id %x:%x\n",
  2799. ThisUserEntry.LogonId.HighPart,
  2800. ThisUserEntry.LogonId.LowPart);
  2801. #if DBG
  2802. DebuggerOut( "UserToken 0x%lx\n", ThisUserEntry.UserToken );
  2803. #endif
  2804. DebuggerOut( "Policy Handle List:\n" );
  2805. DumpLsaHandleTypeList( &ThisUserEntry.PolicyHandles );
  2806. DebuggerOut( "Object Handle List:\n" );
  2807. DumpLsaHandleTypeList( &ThisUserEntry.ObjectHandles );
  2808. HandleEntry = &ThisUserEntry.Next;
  2809. }
  2810. }
  2811. VOID
  2812. DumpLsaHandleTableEx(
  2813. HANDLE hProcess,
  2814. HANDLE hThread,
  2815. DWORD dwCurrentPc,
  2816. PNTSD_EXTENSION_APIS lpExt,
  2817. LPSTR pszCommand)
  2818. {
  2819. LSAP_DB_HANDLE_TABLE HandleTableEx;
  2820. PVOID Table;
  2821. InitDebugHelp( hProcess,
  2822. hThread,
  2823. lpExt);
  2824. Table = GetExpr( pszCommand );
  2825. if ( Table == NULL ) {
  2826. return;
  2827. }
  2828. LsaReadMemory( Table,
  2829. sizeof( LSAP_DB_HANDLE_TABLE ),
  2830. &HandleTableEx );
  2831. ShowLsaHandleTableEx( &HandleTableEx );
  2832. }
  2833. VOID
  2834. ShowTopLevelNameEntry(
  2835. IN FTCache::TLN_ENTRY * EntryAddr,
  2836. IN FTCache::TLN_ENTRY * EntryData
  2837. )
  2838. {
  2839. FTCache::TDO_ENTRY TdoEntry;
  2840. FTCache::TLN_KEY TlnKey;
  2841. SECURITY_STRING sLocal;
  2842. DebuggerOut( "TopLevelNameEntry: %p\n", EntryAddr );
  2843. DebuggerOut( "TdoListEntry: %p %p\n", EntryData->TdoListEntry.Flink, EntryData->TdoListEntry.Blink );
  2844. DebuggerOut( "AvlListEntry: %p %p\n", EntryData->AvlListEntry.Flink, EntryData->TdoListEntry.Blink );
  2845. DebuggerOut( "Excluded: %s\n", ( EntryData->Excluded ? "Yes" : "No" ));
  2846. DebuggerOut( "Flags: %d\n", EntryData->m_Flags );
  2847. if ( EntryData->Excluded ) {
  2848. FTCache::TLN_ENTRY TlnEntry;
  2849. LsaReadMemory(
  2850. EntryData->SuperiorEntry,
  2851. sizeof( FTCache::TLN_ENTRY ),
  2852. &TlnEntry
  2853. );
  2854. LsaReadMemory(
  2855. TlnEntry.TlnKey,
  2856. sizeof( FTCache::TLN_KEY ),
  2857. &TlnKey
  2858. );
  2859. sLocal.Buffer = NULL;
  2860. MapString( &TlnKey.TopLevelName, &sLocal );
  2861. DebuggerOut( "SuperiorEntry: %p (%ws)\n", EntryData->SuperiorEntry, sLocal.Buffer );
  2862. FreeHeap( sLocal.Buffer );
  2863. } else if ( EntryData->SubordinateEntry ) {
  2864. FTCache::TLN_ENTRY TlnEntry;
  2865. LsaReadMemory(
  2866. EntryData->SubordinateEntry,
  2867. sizeof( FTCache::TLN_ENTRY ),
  2868. &TlnEntry
  2869. );
  2870. LsaReadMemory(
  2871. TlnEntry.TlnKey,
  2872. sizeof( FTCache::TLN_KEY ),
  2873. &TlnKey
  2874. );
  2875. sLocal.Buffer = NULL;
  2876. MapString( &TlnKey.TopLevelName, &sLocal );
  2877. DebuggerOut( "SubordinateEntry: %p (%ws)\n", EntryData->SubordinateEntry, sLocal.Buffer );
  2878. FreeHeap( sLocal.Buffer );
  2879. } else {
  2880. DebuggerOut( "SubordinateEntry: NULL\n" );
  2881. }
  2882. LsaReadMemory(
  2883. EntryData->TdoEntry,
  2884. sizeof( FTCache::TDO_ENTRY ),
  2885. &TdoEntry
  2886. );
  2887. sLocal.Buffer = NULL;
  2888. MapString( &TdoEntry.TrustedDomainName, &sLocal );
  2889. DebuggerOut( "TdoEntry: %p (%ws)\n", EntryData->TdoEntry, sLocal.Buffer );
  2890. FreeHeap( sLocal.Buffer );
  2891. LsaReadMemory(
  2892. EntryData->TlnKey,
  2893. sizeof( FTCache::TLN_KEY ),
  2894. &TlnKey
  2895. );
  2896. sLocal.Buffer = NULL;
  2897. MapString( &TlnKey.TopLevelName, &sLocal );
  2898. DebuggerOut( "TlnKey: %p (%ws)\n", EntryData->TlnKey, sLocal.Buffer );
  2899. FreeHeap( sLocal.Buffer );
  2900. DebuggerOut( "\n" );
  2901. }
  2902. VOID
  2903. ShowDomainInfoEntry(
  2904. IN FTCache::DOMAIN_INFO_ENTRY * EntryAddr,
  2905. IN FTCache::DOMAIN_INFO_ENTRY * EntryData
  2906. )
  2907. {
  2908. FTCache::TDO_ENTRY TdoEntry;
  2909. FTCache::TLN_ENTRY SubordinateTo;
  2910. FTCache::TLN_KEY TlnKey;
  2911. FTCache::DNS_NAME_KEY DnsKey;
  2912. FTCache::NETBIOS_NAME_KEY NetbiosKey;
  2913. SECURITY_STRING sLocal;
  2914. DebuggerOut( "DomainInfoEntry: %p\n", EntryAddr );
  2915. DebuggerOut( "TdoListEntry: %p %p", EntryData->TdoListEntry.Flink, EntryData->TdoListEntry.Blink );
  2916. DebuggerOut( "SidAvlListEntry: %p\n", EntryData->SidAvlListEntry.Flink, EntryData->SidAvlListEntry.Blink );
  2917. DebuggerOut( "DnsAvlListEntry: %p\n", EntryData->DnsAvlListEntry.Flink, EntryData->DnsAvlListEntry.Blink );
  2918. DebuggerOut( "NetbiosAvlListEntry: %p\n", EntryData->NetbiosAvlListEntry.Flink, EntryData->NetbiosAvlListEntry.Blink );
  2919. DebuggerOut( "Flags: %d\n", EntryData->m_Flags );
  2920. DebuggerOut( "Time: %x-%x\n", EntryData->Time.HighPart, EntryData->Time.LowPart );
  2921. DebuggerOut( "Sid: " );
  2922. LocalDumpSid( EntryData->Sid );
  2923. DebuggerOut( "\n" );
  2924. LsaReadMemory(
  2925. EntryData->TdoEntry,
  2926. sizeof( FTCache::TDO_ENTRY ),
  2927. &TdoEntry
  2928. );
  2929. sLocal.Buffer = NULL;
  2930. MapString( &TdoEntry.TrustedDomainName, &sLocal );
  2931. DebuggerOut( "TdoEntry: %p (%ws)\n", EntryData->TdoEntry, sLocal.Buffer );
  2932. FreeHeap( sLocal.Buffer );
  2933. LsaReadMemory(
  2934. EntryData->SubordinateTo,
  2935. sizeof( FTCache::TLN_ENTRY ),
  2936. &SubordinateTo
  2937. );
  2938. LsaReadMemory(
  2939. SubordinateTo.TlnKey,
  2940. sizeof( FTCache::TLN_KEY ),
  2941. &TlnKey
  2942. );
  2943. sLocal.Buffer = NULL;
  2944. MapString( &TlnKey.TopLevelName, &sLocal );
  2945. DebuggerOut( "SubordinateTo: %p (%ws)\n", EntryData->SubordinateTo, sLocal.Buffer );
  2946. FreeHeap( sLocal.Buffer );
  2947. DebuggerOut( "SidKey: %p\n", EntryData->SidKey );
  2948. LsaReadMemory(
  2949. EntryData->SidKey,
  2950. sizeof( FTCache::DNS_NAME_KEY ),
  2951. &DnsKey
  2952. );
  2953. sLocal.Buffer = NULL;
  2954. MapString( &DnsKey.DnsName, &sLocal );
  2955. DebuggerOut( "DnsKey: %p (%ws)\n", EntryData->DnsKey, sLocal.Buffer );
  2956. FreeHeap( sLocal.Buffer );
  2957. if ( EntryData->NetbiosKey ) {
  2958. LsaReadMemory(
  2959. EntryData->NetbiosKey,
  2960. sizeof( FTCache::NETBIOS_NAME_KEY ),
  2961. &NetbiosKey
  2962. );
  2963. sLocal.Buffer = NULL;
  2964. MapString( &NetbiosKey.NetbiosName, &sLocal );
  2965. DebuggerOut( "NetbiosKey: %p (%ws)\n", EntryData->NetbiosKey, sLocal.Buffer );
  2966. FreeHeap( sLocal.Buffer );
  2967. } else {
  2968. DebuggerOut( "NetbiosKey: NULL\n" );
  2969. }
  2970. DebuggerOut( "\n" );
  2971. }
  2972. VOID
  2973. ShowFtcTdoEntry(
  2974. IN PVOID TdoEntryAddr,
  2975. IN FTCache::TDO_ENTRY * TdoEntryData
  2976. )
  2977. {
  2978. ULONG Displayed;
  2979. PUCHAR ListEnd;
  2980. SECURITY_STRING sLocal;
  2981. DebuggerOut( "<------------------->\n" );
  2982. sLocal.Buffer = NULL;
  2983. MapString( &TdoEntryData->TrustedDomainName, &sLocal );
  2984. DebuggerOut( "TrustedDomainName: %ws\n", &TdoEntryData->TrustedDomainName, sLocal.Buffer );
  2985. FreeHeap( sLocal.Buffer );
  2986. DebuggerOut( "Record count: %lu\n\n", TdoEntryData->RecordCount );
  2987. DebuggerOut( "\n===> Top Level Name Entries <===\n\n" );
  2988. Displayed = 0;
  2989. ListEnd = ( PUCHAR )TdoEntryAddr + FIELD_OFFSET( FTCache::TDO_ENTRY, TlnList );
  2990. if ( TdoEntryData->TlnList.Flink == ( PLIST_ENTRY )ListEnd ) {
  2991. DebuggerOut( "<none>\n" );
  2992. } else {
  2993. FTCache::TLN_ENTRY TlnEntryData;
  2994. FTCache::TLN_ENTRY * TlnEntryAddr;
  2995. TlnEntryAddr = FTCache::TLN_ENTRY::EntryFromTdoEntry( TdoEntryData->TlnList.Flink );
  2996. do {
  2997. LsaReadMemory(
  2998. TlnEntryAddr,
  2999. sizeof( FTCache::TLN_ENTRY ),
  3000. &TlnEntryData
  3001. );
  3002. Displayed += 1;
  3003. DebuggerOut( "Entry #%lu\n", Displayed );
  3004. ShowTopLevelNameEntry( TlnEntryAddr, &TlnEntryData );
  3005. TlnEntryAddr = FTCache::TLN_ENTRY::EntryFromTdoEntry( TlnEntryData.TdoListEntry.Flink );
  3006. } while ( TlnEntryAddr != FTCache::TLN_ENTRY::EntryFromTdoEntry(( PLIST_ENTRY )ListEnd ));
  3007. }
  3008. DebuggerOut( "\n===> Domain Info Entries <===\n\n" );
  3009. Displayed = 0;
  3010. ListEnd = ( PUCHAR )TdoEntryAddr + FIELD_OFFSET( FTCache::TDO_ENTRY, DomainInfoList );
  3011. if ( TdoEntryData->DomainInfoList.Flink == ( PLIST_ENTRY )ListEnd ) {
  3012. DebuggerOut( "<none>\n" );
  3013. } else {
  3014. FTCache::DOMAIN_INFO_ENTRY DomainInfoData;
  3015. FTCache::DOMAIN_INFO_ENTRY * DomainInfoAddr;
  3016. DomainInfoAddr = FTCache::DOMAIN_INFO_ENTRY::EntryFromTdoEntry( TdoEntryData->DomainInfoList.Flink );
  3017. do {
  3018. LsaReadMemory(
  3019. DomainInfoAddr,
  3020. sizeof( FTCache::DOMAIN_INFO_ENTRY ),
  3021. &DomainInfoData
  3022. );
  3023. Displayed += 1;
  3024. DebuggerOut( "Entry #%lu\n", Displayed );
  3025. ShowDomainInfoEntry( DomainInfoAddr, &DomainInfoData );
  3026. DomainInfoAddr = FTCache::DOMAIN_INFO_ENTRY::EntryFromTdoEntry( DomainInfoData.TdoListEntry.Flink );
  3027. } while ( DomainInfoAddr != FTCache::DOMAIN_INFO_ENTRY::EntryFromTdoEntry(( PLIST_ENTRY )ListEnd ));
  3028. }
  3029. return;
  3030. }
  3031. VOID
  3032. ShowForestTrustCache(
  3033. IN FTCache * Ftc
  3034. )
  3035. {
  3036. DebuggerOut( "Forest Trust Cache si %s\n",
  3037. ( Ftc->m_Initialized ? "valid" : "invalid" ));
  3038. DebuggerOut( "Forest Trust Cache is %s\n",
  3039. ( Ftc->m_Valid ? "valid" : "invalid" ));
  3040. if ( !Ftc->m_Initialized || !Ftc->m_Valid ) {
  3041. return;
  3042. }
  3043. return;
  3044. }
  3045. VOID
  3046. DumpFtcTdoEntry(
  3047. HANDLE hProcess,
  3048. HANDLE hThread,
  3049. DWORD dwCurrentPc,
  3050. PNTSD_EXTENSION_APIS lpExt,
  3051. LPSTR pszCommand)
  3052. {
  3053. PVOID TdoEntryAddr;
  3054. FTCache::TDO_ENTRY TdoEntryData;
  3055. InitDebugHelp( hProcess,
  3056. hThread,
  3057. lpExt);
  3058. TdoEntryAddr = GetExpr( pszCommand );
  3059. if ( TdoEntryAddr == NULL ) {
  3060. return;
  3061. }
  3062. LsaReadMemory( TdoEntryAddr,
  3063. sizeof( FTCache::TDO_ENTRY ),
  3064. &TdoEntryData );
  3065. ShowFtcTdoEntry( TdoEntryAddr, &TdoEntryData );
  3066. }
  3067. VOID
  3068. DumpForestTrustCache(
  3069. HANDLE hProcess,
  3070. HANDLE hThread,
  3071. DWORD dwCurrentPc,
  3072. PNTSD_EXTENSION_APIS lpExt,
  3073. LPSTR pszCommand)
  3074. {
  3075. BYTE Ftc[sizeof(FTCache)];
  3076. PVOID Cache;
  3077. InitDebugHelp( hProcess,
  3078. hThread,
  3079. lpExt);
  3080. Cache = GetExpr( pszCommand );
  3081. if ( Cache == NULL ) {
  3082. return;
  3083. }
  3084. LsaReadMemory( Cache,
  3085. sizeof( FTCache ),
  3086. &Ftc );
  3087. ShowForestTrustCache( ( FTCache * )Ftc );
  3088. }
  3089. VOID
  3090. LocalPrintGuid(
  3091. GUID *Guid
  3092. )
  3093. {
  3094. if ( Guid ) {
  3095. DebuggerOut( "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
  3096. Guid->Data1, Guid->Data2, Guid->Data3, Guid->Data4[0],
  3097. Guid->Data4[1], Guid->Data4[2], Guid->Data4[3], Guid->Data4[4],
  3098. Guid->Data4[5], Guid->Data4[6], Guid->Data4[7] );
  3099. }
  3100. }
  3101. VOID
  3102. ReadAndDumpSid(
  3103. IN PVOID SidPtr
  3104. )
  3105. {
  3106. UNICODE_STRING StringSid;
  3107. SID Sid;
  3108. PSID ReadSid;
  3109. LsaReadMemory( SidPtr, sizeof( SID ), &Sid );
  3110. ReadSid = AllocHeap( RtlLengthRequiredSid( Sid.SubAuthorityCount ) );
  3111. if ( ReadSid ) {
  3112. LsaReadMemory( SidPtr, RtlLengthRequiredSid( Sid.SubAuthorityCount ), ReadSid );
  3113. RtlConvertSidToUnicodeString( &StringSid, ReadSid, TRUE );
  3114. DebuggerOut( "%wZ", &StringSid );
  3115. RtlFreeUnicodeString( &StringSid );
  3116. FreeHeap( ReadSid );
  3117. }
  3118. }
  3119. VOID
  3120. ShowAcl(
  3121. IN PVOID AclPtr
  3122. )
  3123. {
  3124. ULONG i, SkipSize;
  3125. PVOID AcePtr;
  3126. ACE_HEADER Ace;
  3127. KNOWN_ACE KnownAce;
  3128. KNOWN_OBJECT_ACE KnownObjectAce;
  3129. PSID SidStart = NULL, ReadSid;
  3130. SID Sid;
  3131. UNICODE_STRING StringSid;
  3132. GUID *DisplayGuid;
  3133. ACL ReadAcl;
  3134. PACL Acl = &ReadAcl;
  3135. LsaReadMemory( AclPtr, sizeof( ACL ), &ReadAcl );
  3136. DebuggerOut( "AclRevision %lu\n", ReadAcl.AclRevision );
  3137. DebuggerOut( "Sbz1 %lu\n", ReadAcl.Sbz1 );
  3138. DebuggerOut( "AclSize %lu\n", ReadAcl.AclSize );
  3139. DebuggerOut( "AceCount %lu\n", ReadAcl.AceCount );
  3140. DebuggerOut( "Sbz2 %lu\n", ReadAcl.Sbz2 );
  3141. AcePtr = ( PUCHAR )AclPtr + sizeof( ACL );
  3142. for ( i = 0; i < ReadAcl.AceCount; i++ ) {
  3143. //
  3144. // First, we need to read the Size/Type of the ace
  3145. //
  3146. LsaReadMemory( AcePtr, sizeof( ACE_HEADER ), &Ace );
  3147. DebuggerOut( "Ace[ %lu ]\n", i );
  3148. DebuggerOut( "\tAceType %lu\n", Ace.AceType );
  3149. DebuggerOut( "\tAceFlags %lu\n", Ace.AceFlags );
  3150. DebuggerOut( "\tAceSize %lu\n", Ace.AceSize );
  3151. switch ( Ace.AceType ) {
  3152. case ACCESS_ALLOWED_ACE_TYPE:
  3153. case ACCESS_DENIED_ACE_TYPE:
  3154. case SYSTEM_AUDIT_ACE_TYPE:
  3155. case SYSTEM_ALARM_ACE_TYPE:
  3156. LsaReadMemory( AcePtr, sizeof( KNOWN_ACE ), &KnownAce );
  3157. DebuggerOut( "\tAccessMask 0x%lx\n", KnownAce.Mask );
  3158. SidStart = ( PSID )( ( PUCHAR )AcePtr + sizeof( KNOWN_ACE ) - sizeof( ULONG ) );
  3159. break;
  3160. case ACCESS_ALLOWED_OBJECT_ACE_TYPE:
  3161. case ACCESS_DENIED_OBJECT_ACE_TYPE:
  3162. case SYSTEM_AUDIT_OBJECT_ACE_TYPE:
  3163. case SYSTEM_ALARM_OBJECT_ACE_TYPE:
  3164. SkipSize = sizeof( KNOWN_OBJECT_ACE );
  3165. LsaReadMemory( AcePtr, sizeof( KNOWN_OBJECT_ACE ) + 2 * sizeof( GUID ), &KnownObjectAce );
  3166. DebuggerOut( "\tAccessMask 0x%lx\n", KnownObjectAce.Mask );
  3167. DisplayGuid = RtlObjectAceObjectType( &KnownObjectAce );
  3168. if ( DisplayGuid ) {
  3169. DebuggerOut( "\tObjectGuid ");
  3170. LocalPrintGuid( DisplayGuid );
  3171. DebuggerOut( "\n");
  3172. SkipSize += sizeof( GUID );
  3173. }
  3174. DisplayGuid = RtlObjectAceInheritedObjectType( &KnownObjectAce );
  3175. if ( DisplayGuid ) {
  3176. DebuggerOut( "\tObjectGuid ");
  3177. LocalPrintGuid( DisplayGuid );
  3178. DebuggerOut( "\n");
  3179. SkipSize += sizeof( GUID );
  3180. }
  3181. SidStart = ( PSID )( ( PUCHAR )AcePtr + SkipSize - sizeof( ULONG ) );
  3182. break;
  3183. case ACCESS_ALLOWED_COMPOUND_ACE_TYPE:
  3184. default:
  3185. DebuggerOut( "Unsupported AceType %lu encountered... skipping\n", Ace.AceType );
  3186. break;
  3187. }
  3188. AcePtr = ( PUCHAR )AcePtr + Ace.AceSize;
  3189. LsaReadMemory( SidStart, sizeof( SID ), &Sid );
  3190. ReadSid = AllocHeap( RtlLengthRequiredSid( Sid.SubAuthorityCount ) );
  3191. if ( ReadSid ) {
  3192. LsaReadMemory( SidStart, RtlLengthRequiredSid( Sid.SubAuthorityCount ), ReadSid );
  3193. RtlConvertSidToUnicodeString( &StringSid, ReadSid, TRUE );
  3194. DebuggerOut( "\t%wZ\n", &StringSid );
  3195. RtlFreeUnicodeString( &StringSid );
  3196. FreeHeap( ReadSid );
  3197. }
  3198. }
  3199. }
  3200. VOID
  3201. DumpAcl(
  3202. HANDLE hProcess,
  3203. HANDLE hThread,
  3204. DWORD dwCurrentPc,
  3205. PNTSD_EXTENSION_APIS lpExt,
  3206. LPSTR pszCommand)
  3207. {
  3208. ACL Acl;
  3209. PVOID AclPtr;
  3210. InitDebugHelp( hProcess,
  3211. hThread,
  3212. lpExt);
  3213. AclPtr = GetExpr( pszCommand );
  3214. if ( AclPtr == NULL ) {
  3215. return;
  3216. }
  3217. ShowAcl( AclPtr );
  3218. }
  3219. VOID
  3220. ShowSD(
  3221. IN PVOID SDPtr
  3222. )
  3223. {
  3224. SECURITY_DESCRIPTOR SD;
  3225. PSID Owner = NULL, Group = NULL;
  3226. PACL Dacl = NULL, Sacl = NULL;
  3227. LsaReadMemory( SDPtr, sizeof( SECURITY_DESCRIPTOR ), &SD );
  3228. DebuggerOut( "Revision %lu\n", SD.Revision );
  3229. DebuggerOut( "Sbz1 %lu\n", SD.Sbz1 );
  3230. DebuggerOut( "Control 0x%lx\n", SD.Control );
  3231. if ( ( SD.Control & SE_SELF_RELATIVE ) == SE_SELF_RELATIVE ) {
  3232. if ( SD.Owner != 0 ) {
  3233. Owner = ( PSID )( ( PUCHAR )SDPtr + ( ULONG_PTR )SD.Owner );
  3234. }
  3235. if ( SD.Group != 0 ) {
  3236. Group = ( PSID )( ( PUCHAR )SDPtr + ( ULONG_PTR )SD.Group );
  3237. }
  3238. if ( SD.Dacl != 0 ) {
  3239. Dacl = ( PACL )( ( PUCHAR )SDPtr + ( ULONG_PTR )SD.Dacl );
  3240. }
  3241. if ( SD.Sacl != 0 ) {
  3242. Sacl = ( PACL )( ( PUCHAR )SDPtr + ( ULONG_PTR )SD.Sacl );
  3243. }
  3244. } else {
  3245. Owner = SD.Owner;
  3246. Group = SD.Group;
  3247. Dacl = SD.Dacl;
  3248. Sacl = SD.Sacl;
  3249. }
  3250. DebuggerOut( "Owner: ");
  3251. if ( Owner ) {
  3252. ReadAndDumpSid( Owner );
  3253. } else {
  3254. DebuggerOut( "<NULL>" );
  3255. }
  3256. DebuggerOut( "\n" );
  3257. DebuggerOut( "Group: ");
  3258. if ( Group ) {
  3259. ReadAndDumpSid( Group );
  3260. } else {
  3261. DebuggerOut( "<NULL>" );
  3262. }
  3263. DebuggerOut( "\n" );
  3264. DebuggerOut( "DACL:\n");
  3265. if ( Dacl ) {
  3266. ShowAcl( Dacl );
  3267. } else {
  3268. DebuggerOut( "<NULL>" );
  3269. }
  3270. DebuggerOut( "SACL:\n");
  3271. if ( Sacl ) {
  3272. ShowAcl( Sacl );
  3273. } else {
  3274. DebuggerOut( "<NULL>" );
  3275. }
  3276. DebuggerOut( "\n" );
  3277. }
  3278. VOID
  3279. DumpSD(
  3280. HANDLE hProcess,
  3281. HANDLE hThread,
  3282. DWORD dwCurrentPc,
  3283. PNTSD_EXTENSION_APIS lpExt,
  3284. LPSTR pszCommand)
  3285. {
  3286. PVOID SDPtr;
  3287. InitDebugHelp( hProcess,
  3288. hThread,
  3289. lpExt);
  3290. SDPtr = GetExpr( pszCommand );
  3291. if ( SDPtr == NULL ) {
  3292. return;
  3293. }
  3294. ShowSD( SDPtr );
  3295. }
  3296. VOID
  3297. setevent(
  3298. HANDLE hProcess,
  3299. HANDLE hThread,
  3300. DWORD dwCurrentPc,
  3301. PNTSD_EXTENSION_APIS lpExt,
  3302. LPSTR pszCommand)
  3303. {
  3304. HANDLE h ;
  3305. HANDLE hThere ;
  3306. InitDebugHelp( hProcess, hThread, lpExt );
  3307. hThere = GetExpr( pszCommand );
  3308. if ( DuplicateHandle( hProcess,
  3309. hThere,
  3310. GetCurrentProcess(),
  3311. &h,
  3312. 0,
  3313. FALSE,
  3314. DUPLICATE_SAME_ACCESS ) )
  3315. {
  3316. SetEvent( h );
  3317. CloseHandle( h );
  3318. }
  3319. }
  3320. /*
  3321. +-------------------------------------------------------------------+
  3322. NAME: DumpSID
  3323. FUNCTION: Prints out a SID, with the padding provided.
  3324. ARGS: pad -- Padding to print before the SID.
  3325. sid_to_dump -- Pointer to the SID to print.
  3326. Flag -- To control options.
  3327. RETURN: N/A
  3328. NOTE***: It right now, doesn't lookup the sid.
  3329. In future, you might want ot use the Flag
  3330. parameter to make that optional.
  3331. +-------------------------------------------------------------------+
  3332. */
  3333. VOID DumpSID(
  3334. CHAR *pad,
  3335. PSID sid_to_dump,
  3336. ULONG Flag
  3337. )
  3338. {
  3339. NTSTATUS ntstatus;
  3340. UNICODE_STRING us;
  3341. if (sid_to_dump)
  3342. {
  3343. ntstatus = RtlConvertSidToUnicodeString(&us, sid_to_dump, TRUE);
  3344. if (NT_SUCCESS(ntstatus))
  3345. {
  3346. DebuggerOut("%s%wZ\n", pad, &us);
  3347. RtlFreeUnicodeString(&us);
  3348. }
  3349. else
  3350. {
  3351. DebuggerOut("0x%08lx: Can't Convert SID to UnicodeString\n", ntstatus);
  3352. }
  3353. }
  3354. else
  3355. {
  3356. DebuggerOut("%s is NULL\n", pad);
  3357. }
  3358. }
  3359. /*
  3360. +-------------------------------------------------------------------+
  3361. NAME: DumpACL
  3362. FUNCTION: Prints out a ACL, with the padding provided.
  3363. ARGS: pad -- Padding to print before the ACL.
  3364. acl_to_dump -- Pointer to the ACL to print.
  3365. Flag -- To control options.
  3366. RETURN: N/A
  3367. +-------------------------------------------------------------------+
  3368. */
  3369. BOOL
  3370. DumpACL (
  3371. IN char *pad,
  3372. IN ACL *pacl,
  3373. IN ULONG Flags
  3374. )
  3375. {
  3376. USHORT x;
  3377. if (pacl == NULL)
  3378. {
  3379. DebuggerOut("%s is NULL\n", pad);
  3380. return FALSE;
  3381. }
  3382. DebuggerOut("%s\n", pad);
  3383. DebuggerOut("%s->AclRevision: 0x%x\n", pad, pacl->AclRevision);
  3384. DebuggerOut("%s->Sbz1 : 0x%x\n", pad, pacl->Sbz1);
  3385. DebuggerOut("%s->AclSize : 0x%x\n", pad, pacl->AclSize);
  3386. DebuggerOut("%s->AceCount : 0x%x\n", pad, pacl->AceCount);
  3387. DebuggerOut("%s->Sbz2 : 0x%x\n", pad, pacl->Sbz2);
  3388. for (x = 0; x < pacl->AceCount; x ++)
  3389. {
  3390. PACE_HEADER ace;
  3391. CHAR temp_pad[MAX_PATH];
  3392. NTSTATUS result;
  3393. sprintf(temp_pad, "%s->Ace[%u]: ", pad, x);
  3394. result = RtlGetAce(pacl, x, (PVOID *) &ace);
  3395. if (! NT_SUCCESS(result))
  3396. {
  3397. DebuggerOut("%sCan't GetAce, 0x%08lx\n", temp_pad, result);
  3398. return FALSE;
  3399. }
  3400. DebuggerOut("%s->AceType: ", temp_pad);
  3401. #define BRANCH_AND_PRINT(x) case x: DebuggerOut(#x "\n"); break
  3402. switch (ace->AceType)
  3403. {
  3404. BRANCH_AND_PRINT(ACCESS_ALLOWED_ACE_TYPE);
  3405. BRANCH_AND_PRINT(ACCESS_DENIED_ACE_TYPE);
  3406. BRANCH_AND_PRINT(SYSTEM_AUDIT_ACE_TYPE);
  3407. BRANCH_AND_PRINT(SYSTEM_ALARM_ACE_TYPE);
  3408. BRANCH_AND_PRINT(ACCESS_ALLOWED_COMPOUND_ACE_TYPE);
  3409. BRANCH_AND_PRINT(ACCESS_ALLOWED_OBJECT_ACE_TYPE);
  3410. BRANCH_AND_PRINT(ACCESS_DENIED_OBJECT_ACE_TYPE);
  3411. BRANCH_AND_PRINT(SYSTEM_AUDIT_OBJECT_ACE_TYPE);
  3412. BRANCH_AND_PRINT(SYSTEM_ALARM_OBJECT_ACE_TYPE);
  3413. default:
  3414. DebuggerOut("0x%08lx <-- *** Unknown AceType\n", ace->AceType);
  3415. continue; // With the next ace
  3416. }
  3417. #undef BRANCH_AND_PRINT
  3418. DebuggerOut("%s->AceFlags: 0x%x\n", temp_pad, ace->AceFlags);
  3419. #define BRANCH_AND_PRINT(x) if (ace->AceFlags & x){ DebuggerOut("%s %s\n", temp_pad, #x); }
  3420. BRANCH_AND_PRINT(OBJECT_INHERIT_ACE)
  3421. BRANCH_AND_PRINT(CONTAINER_INHERIT_ACE)
  3422. BRANCH_AND_PRINT(NO_PROPAGATE_INHERIT_ACE)
  3423. BRANCH_AND_PRINT(INHERIT_ONLY_ACE)
  3424. BRANCH_AND_PRINT(INHERITED_ACE)
  3425. BRANCH_AND_PRINT(SUCCESSFUL_ACCESS_ACE_FLAG)
  3426. BRANCH_AND_PRINT(FAILED_ACCESS_ACE_FLAG)
  3427. #undef BRANCH_AND_PRINT
  3428. DebuggerOut("%s->AceSize: 0x%x\n", temp_pad, ace->AceSize);
  3429. /*
  3430. From now on it is ace specific stuff.
  3431. Fortunately ACEs can be split into 3 groups,
  3432. with the ACE structure being the same within the group
  3433. */
  3434. switch (ace->AceType)
  3435. {
  3436. case ACCESS_ALLOWED_ACE_TYPE:
  3437. case ACCESS_DENIED_ACE_TYPE:
  3438. case SYSTEM_AUDIT_ACE_TYPE:
  3439. case SYSTEM_ALARM_ACE_TYPE:
  3440. {
  3441. CHAR more_pad[MAX_PATH];
  3442. SYSTEM_AUDIT_ACE *tace = (SYSTEM_AUDIT_ACE *) ace;
  3443. DebuggerOut("%s->Mask : 0x%08lx\n", temp_pad, tace->Mask);
  3444. sprintf(more_pad, "%s->SID: ", temp_pad);
  3445. DumpSID(more_pad, &(tace->SidStart), Flags);
  3446. }
  3447. break;
  3448. case ACCESS_ALLOWED_COMPOUND_ACE_TYPE:
  3449. {
  3450. CHAR more_pad[MAX_PATH];
  3451. COMPOUND_ACCESS_ALLOWED_ACE *tace = (COMPOUND_ACCESS_ALLOWED_ACE *) ace;
  3452. PBYTE ptr;
  3453. DebuggerOut("%s->Mask : 0x%08lx\n", temp_pad, tace->Mask);
  3454. DebuggerOut("%s->CompoundAceType : 0x%08lx\n", temp_pad, tace->CompoundAceType);
  3455. DebuggerOut("%s->Reserved : 0x%08lx\n", temp_pad, tace->Reserved);
  3456. sprintf(more_pad, "%s->SID(1) : ", temp_pad);
  3457. DumpSID(more_pad, &(tace->SidStart), Flags);
  3458. ptr = (PBYTE)&(tace->SidStart);
  3459. ptr += RtlLengthSid((PSID)ptr); /* Skip this & get to next sid */
  3460. sprintf(more_pad, "%s->SID(2) : ", temp_pad);
  3461. DumpSID(more_pad, ptr, Flags);
  3462. }
  3463. break;
  3464. case ACCESS_ALLOWED_OBJECT_ACE_TYPE:
  3465. case ACCESS_DENIED_OBJECT_ACE_TYPE:
  3466. case SYSTEM_AUDIT_OBJECT_ACE_TYPE:
  3467. case SYSTEM_ALARM_OBJECT_ACE_TYPE:
  3468. {
  3469. CHAR more_pad[MAX_PATH];
  3470. ACCESS_ALLOWED_OBJECT_ACE *tace = (ACCESS_ALLOWED_OBJECT_ACE *) ace;
  3471. PBYTE ptr;
  3472. GUID *obj_guid = NULL, *inh_obj_guid = NULL;
  3473. DebuggerOut("%s->Mask : 0x%08lx\n", temp_pad, tace->Mask);
  3474. DebuggerOut("%s->Flags : 0x%08lx\n", temp_pad, tace->Flags);
  3475. ptr = (PBYTE)&(tace->ObjectType);
  3476. if (tace->Flags & ACE_OBJECT_TYPE_PRESENT)
  3477. {
  3478. DebuggerOut("%s : ACE_OBJECT_TYPE_PRESENT\n", temp_pad);
  3479. obj_guid = &(tace->ObjectType);
  3480. ptr = (PBYTE)&(tace->InheritedObjectType);
  3481. }
  3482. if (tace->Flags & ACE_INHERITED_OBJECT_TYPE_PRESENT)
  3483. {
  3484. DebuggerOut("%s : ACE_INHERITED_OBJECT_TYPE_PRESENT\n", temp_pad);
  3485. inh_obj_guid = &(tace->InheritedObjectType);
  3486. ptr = (PBYTE)&(tace->SidStart);
  3487. }
  3488. if (obj_guid)
  3489. {
  3490. DebuggerOut("%s->ObjectType : (in HEX)", temp_pad);
  3491. DebuggerOut("(%08lx-%04x-%04x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x)\n",
  3492. obj_guid->Data1,
  3493. obj_guid->Data2,
  3494. obj_guid->Data3,
  3495. obj_guid->Data4[0],
  3496. obj_guid->Data4[1],
  3497. obj_guid->Data4[2],
  3498. obj_guid->Data4[3],
  3499. obj_guid->Data4[4],
  3500. obj_guid->Data4[5],
  3501. obj_guid->Data4[6],
  3502. obj_guid->Data4[7]
  3503. );
  3504. }
  3505. if (inh_obj_guid)
  3506. {
  3507. DebuggerOut("%s->InhObjTYpe : (in HEX)", temp_pad);
  3508. DebuggerOut("(%08lx-%04x-%04x-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x)\n",
  3509. inh_obj_guid->Data1,
  3510. inh_obj_guid->Data2,
  3511. inh_obj_guid->Data3,
  3512. inh_obj_guid->Data4[0],
  3513. inh_obj_guid->Data4[1],
  3514. inh_obj_guid->Data4[2],
  3515. inh_obj_guid->Data4[3],
  3516. inh_obj_guid->Data4[4],
  3517. inh_obj_guid->Data4[5],
  3518. inh_obj_guid->Data4[6],
  3519. inh_obj_guid->Data4[7]
  3520. );
  3521. }
  3522. sprintf(more_pad, "%s->SID : ", temp_pad);
  3523. DumpSID(more_pad, ptr, Flags);
  3524. }
  3525. }
  3526. DebuggerOut("\n");
  3527. }
  3528. return TRUE;
  3529. }
  3530. VOID
  3531. objsec(
  3532. HANDLE hProcess,
  3533. HANDLE hThread,
  3534. DWORD dwCurrentPc,
  3535. PNTSD_EXTENSION_APIS lpExt,
  3536. LPSTR pszCommand)
  3537. {
  3538. HANDLE h ;
  3539. HANDLE hThere ;
  3540. NTSTATUS Status ;
  3541. ULONG Length ;
  3542. PVOID SecurityDescriptor ;
  3543. PACL Acl ;
  3544. InitDebugHelp( hProcess, hThread, lpExt );
  3545. hThere = GetExpr( pszCommand );
  3546. if ( DuplicateHandle( hProcess,
  3547. hThere,
  3548. GetCurrentProcess(),
  3549. &h,
  3550. 0,
  3551. FALSE,
  3552. DUPLICATE_SAME_ACCESS ) )
  3553. {
  3554. Status = NtQuerySecurityObject(
  3555. h,
  3556. DACL_SECURITY_INFORMATION,
  3557. NULL,
  3558. 0,
  3559. &Length );
  3560. SecurityDescriptor = LocalAlloc( LMEM_FIXED, Length );
  3561. if ( SecurityDescriptor )
  3562. {
  3563. Status = NtQuerySecurityObject(
  3564. h,
  3565. DACL_SECURITY_INFORMATION,
  3566. SecurityDescriptor,
  3567. Length,
  3568. &Length );
  3569. if ( NT_SUCCESS( Status ) )
  3570. {
  3571. BOOLEAN Present, defaulted;
  3572. RtlGetDaclSecurityDescriptor( SecurityDescriptor,
  3573. &Present,
  3574. &Acl,
  3575. &defaulted );
  3576. DumpACL( "", Acl, 0);
  3577. }
  3578. LocalFree( SecurityDescriptor );
  3579. }
  3580. }
  3581. }
  3582. void
  3583. Help( HANDLE hProcess,
  3584. HANDLE hThread,
  3585. DWORD dwCurrentPc,
  3586. PNTSD_EXTENSION_APIS lpExt,
  3587. LPSTR pszCommand)
  3588. {
  3589. InitDebugHelp(hProcess, hThread, lpExt);
  3590. DebuggerOut("SPM Debug Help\n");
  3591. DebuggerOut(" DumpPackage [-v][-b]] [id | addr]\tDump Package Control\n");
  3592. DebuggerOut(" DumpSessionList <addr> \tDump Session List\n");
  3593. DebuggerOut(" DumpThreadSession \tDump Thread's session\n");
  3594. DebuggerOut(" DumpLogonSession <addr> \tDump Logon Session list\n");
  3595. DebuggerOut(" DumpSession <addr> \tDump Session\n");
  3596. DebuggerOut(" DumpHandleList <addr> \tDump a Handle List from a session\n");
  3597. DebuggerOut(" DumpBlock <addr> \tDump a memory block (DBGMEM only)\n");
  3598. DebuggerOut(" DumpScavList [<addr>[+]] \tDump the scavenger list\n");
  3599. DebuggerOut(" DumpToken <handle> \tDump a token\n");
  3600. DebuggerOut(" DumpThreadToken \tDump token of thread\n");
  3601. DebuggerOut(" DumpActives [-p|a|t] [file] \tDump active memory to file\n");
  3602. DebuggerOut(" DumpFastMem \tDump FastMem usage\n");
  3603. DebuggerOut(" Except \tShow exception for thread\n");
  3604. DebuggerOut(" DumpLpc \tDump Lpc Dispatch record\n");
  3605. DebuggerOut(" DumpLpcMessage <addr> \tDump Lpc Message at address\n");
  3606. DebuggerOut(" DumpThreadTask <addr> \tDump thread pool\n");
  3607. DebuggerOut(" DumpQueue [<addr>] \tDump Queue\n");
  3608. DebuggerOut(" DumpSecBuffer <addr> \tDump SecBuffer struct\n");
  3609. DebuggerOut(" DumpSecBufferDesc <addr> \tDump SecBufferDesc struct \n");
  3610. DebuggerOut(" DumpThreadLpc \tDump thread's LPC message\n");
  3611. DebuggerOut(" DumpNegContext <addr> \tDump NEG_CONTEXT structure\n");
  3612. DebuggerOut(" DumpNegCred <addr> \tDump NEG_CRED structure\n");
  3613. DebuggerOut(" BERDecode <addr> \tDecode BER-encoded data\n");
  3614. DebuggerOut(" GetTls <slot> \tGet the TLS value from slot\n");
  3615. DebuggerOut(" DumpHandleTable <addr> \tDump handle table at addr\n");
  3616. DebuggerOut(" DumpLsaHandle <addr> \tDump the Lsa policy handle at addr\n");
  3617. DebuggerOut(" DumpLsaHandleTable <addr> \tDump the Lsa policy handle table at addr\n");
  3618. DebuggerOut(" DumpLsaHandleTableEx <addr> \tDump the Lsa policy handle table at addr\n");
  3619. DebuggerOut(" DumpSD <addr> \tDump a security descriptor\n");
  3620. DebuggerOut(" DumpAcl <addr> \tDump the ACL at addr\n" );
  3621. DebuggerOut(" DumpSid <addr> \tDump the SID at addr\n" );
  3622. DebuggerOut(" DumpLsaSidCache [<addr>] \tDump the LSA sid cache\n" );
  3623. DebuggerOut(" DumpFtcTdoEntry <addr> \tDump the LSA FTC TDO entry\n" );
  3624. DebuggerOut(" DumpForestTrustCache <addr> \tDump the LSA forest trust cache\n");
  3625. DebuggerOut("\n\nShortcuts\n");
  3626. DebuggerOut(" sb DumpSecBuffer\n");
  3627. DebuggerOut(" sbd DumpSecBufferDesc\n");
  3628. DebuggerOut(" lpc DumpLpcMessage\n");
  3629. DebuggerOut(" sess DumpSession\n");
  3630. DebuggerOut(" ber BERDecode\n");
  3631. DebuggerOut(" q DumpQueue\n");
  3632. DebuggerOut(" task DumpThreadTask\n");
  3633. }