Source code of Windows XP (NT5)
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.

195 lines
4.4 KiB

  1. //
  2. // NDS File Stream Cat
  3. // Cory West
  4. //
  5. #include "ndsapi32.h"
  6. #include <nds.h>
  7. int
  8. _cdecl main(
  9. int argc,
  10. char **argv
  11. ) {
  12. NTSTATUS Status;
  13. //
  14. // For NwNdsOpenTreeHandle
  15. //
  16. HANDLE hRdr;
  17. OEM_STRING oemStr;
  18. UNICODE_STRING ObjectName;
  19. WCHAR NdsStr[1024];
  20. //
  21. // For NwNdsResolveName
  22. //
  23. PNDS_RESPONSE_RESOLVE_NAME psResolveName;
  24. DWORD dwOid;
  25. HANDLE hReferredServer;
  26. DWORD dwHandleType;
  27. UNICODE_STRING ReferredServer;
  28. WCHAR ServerName[48];
  29. //
  30. // For ReadFile of an open stream.
  31. //
  32. DWORD dwBytesRead, dwFileLength, dwBytesShown;
  33. BOOL bRead;
  34. BYTE RawResponse[1024];
  35. /**************************************************/
  36. //
  37. // Examine the argument count and hope for the best.
  38. //
  39. if ( argc < 3 ) {
  40. printf( "Usage: rdstrm <tree name> <ds object path> <file stream>\n" );
  41. printf( "For example, rdstrm tree user.orgunit.org \"Login Script\"\n");
  42. return -1;
  43. }
  44. //
  45. // Convert the tree name string to unicode.
  46. //
  47. oemStr.Length = strlen( argv[1] );
  48. oemStr.MaximumLength = oemStr.Length;
  49. oemStr.Buffer = argv[1];
  50. ObjectName.Length = 0;
  51. ObjectName.MaximumLength = sizeof( NdsStr );
  52. ObjectName.Buffer = NdsStr;
  53. RtlOemStringToUnicodeString( &ObjectName, &oemStr, FALSE );
  54. //
  55. // Get a handle to the redirector.
  56. //
  57. Status = NwNdsOpenTreeHandle( &ObjectName, &hRdr );
  58. if ( !NT_SUCCESS( Status ) ) {
  59. printf( "The tree is not available. Status was %08lx.\n", Status );
  60. return -1;
  61. }
  62. //
  63. // Resolve the name that we have to an object id.
  64. //
  65. oemStr.Length = strlen(argv[2]);
  66. oemStr.MaximumLength = oemStr.Length;
  67. oemStr.Buffer = argv[2];
  68. ObjectName.Length = 0;
  69. ObjectName.MaximumLength = sizeof(NdsStr);
  70. ObjectName.Buffer = NdsStr;
  71. RtlOemStringToUnicodeString( &ObjectName, &oemStr, FALSE );
  72. ReferredServer.Buffer = ServerName;
  73. ReferredServer.MaximumLength = sizeof( ServerName );
  74. ReferredServer.Length = 0;
  75. Status = NwNdsResolveName ( hRdr,
  76. &ObjectName,
  77. &dwOid,
  78. &ReferredServer,
  79. NULL,
  80. 0 );
  81. if ( !NT_SUCCESS( Status ) ) {
  82. printf( "The object is not available. Status = %08lx.\n", Status );
  83. goto Exit;
  84. }
  85. if ( ReferredServer.Length != 0 ) {
  86. Status = NwNdsOpenGenericHandle( &ReferredServer,
  87. &dwHandleType,
  88. &hReferredServer );
  89. if ( !NT_SUCCESS( Status ) ) {
  90. printf( "The object's referred server is not available. Status = %08lx.\n", Status );
  91. goto Exit;
  92. }
  93. CloseHandle( hRdr );
  94. hRdr = hReferredServer;
  95. }
  96. //
  97. // Try to open a file stream for read access.
  98. //
  99. oemStr.Length = strlen(argv[3]);
  100. oemStr.MaximumLength = oemStr.Length;
  101. oemStr.Buffer = argv[3];
  102. ObjectName.Length = 0;
  103. ObjectName.MaximumLength = sizeof(NdsStr);
  104. ObjectName.Buffer = NdsStr;
  105. RtlOemStringToUnicodeString( &ObjectName, &oemStr, FALSE );
  106. Status = NwNdsOpenStream( hRdr,
  107. dwOid,
  108. &ObjectName,
  109. 1,
  110. &dwFileLength );
  111. if ( !NT_SUCCESS( Status ) ) {
  112. printf( "The file stream is not available. Status = %08lx.\n", Status );
  113. goto Exit;
  114. }
  115. //
  116. // Dump the file stream.
  117. //
  118. printf( "---------- There are %d bytes in file stream %s ----------\n", dwFileLength, argv[3] );
  119. while ( dwFileLength ) {
  120. bRead = ReadFile( hRdr,
  121. RawResponse,
  122. sizeof( RawResponse ),
  123. &dwBytesRead,
  124. NULL );
  125. if ( !bRead ) {
  126. printf( "*** Couldn't read data from file stream.\n" );
  127. goto Exit;
  128. }
  129. dwFileLength -= dwBytesRead;
  130. dwBytesShown = 0;
  131. while ( dwBytesRead-- ) {
  132. printf( "%c", RawResponse[dwBytesShown++] );
  133. }
  134. }
  135. printf( "\n-----------------------------------------------------------------------\n" );
  136. Exit:
  137. CloseHandle( hRdr );
  138. if ( !NT_SUCCESS( Status )) {
  139. return -1;
  140. } else {
  141. return 0;
  142. }
  143. }