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.

390 lines
9.7 KiB

  1. #include "brian.h"
  2. PCHAR
  3. SwallowNonWhite (
  4. IN PCHAR Ptr,
  5. OUT PULONG Count
  6. )
  7. {
  8. ULONG LocalCount = 0;
  9. while (*Ptr) {
  10. if (*Ptr == ' ' || *Ptr == '\t' ) {
  11. break;
  12. }
  13. LocalCount += 1;
  14. Ptr++;
  15. }
  16. *Count = LocalCount;
  17. return Ptr;
  18. }
  19. PCHAR
  20. SwallowWhite (
  21. IN PCHAR Ptr,
  22. OUT PULONG Count
  23. )
  24. {
  25. ULONG LocalCount = 0;
  26. while (*Ptr != '\0') {
  27. if (*Ptr != ' ' && *Ptr != '\t') {
  28. break;
  29. }
  30. LocalCount += 1;
  31. Ptr++;
  32. }
  33. *Count = LocalCount;
  34. return Ptr;
  35. }
  36. ULONG
  37. AnalyzeBuffer (
  38. PCHAR *BuffPtr,
  39. PULONG ParamStringLen
  40. )
  41. {
  42. ULONG BytesSwallowed;
  43. ULONG Count;
  44. PCHAR CurrentChar;
  45. if (!ExtractCmd( BuffPtr, &BytesSwallowed )) {
  46. return SHELL_UNKNOWN;
  47. }
  48. //
  49. // Lower case the command string.
  50. //
  51. for (Count = 0, CurrentChar = *BuffPtr; Count < BytesSwallowed; Count++, CurrentChar++) {
  52. if ((*CurrentChar <= 'Z') && (*CurrentChar >= 'A')) {
  53. *CurrentChar += ('a' - 'A');
  54. }
  55. }
  56. *ParamStringLen = BytesSwallowed;
  57. if ((BytesSwallowed == 2) &&
  58. RtlEqualMemory( *BuffPtr, "op", 2 )) {
  59. return SHELL_OPEN;
  60. } else if ((BytesSwallowed == 3) &&
  61. RtlEqualMemory( *BuffPtr, "die", 3 )) {
  62. return SHELL_EXIT;
  63. } else if ((BytesSwallowed == 3) &&
  64. RtlEqualMemory( *BuffPtr, "clb", 3 )) {
  65. return SHELL_CLEAR_BUFFER;
  66. } else if ((BytesSwallowed == 2) &&
  67. RtlEqualMemory( *BuffPtr, "db", 2 )) {
  68. return SHELL_DISPLAY_BYTES;
  69. } else if ((BytesSwallowed == 2) &&
  70. RtlEqualMemory( *BuffPtr, "dw", 2 )) {
  71. return SHELL_DISPLAY_WORDS;
  72. } else if ((BytesSwallowed == 2) &&
  73. RtlEqualMemory( *BuffPtr, "dd", 2 )) {
  74. return SHELL_DISPLAY_DWORDS;
  75. } else if ((BytesSwallowed == 2) &&
  76. RtlEqualMemory( *BuffPtr, "cb", 2 )) {
  77. return SHELL_COPY_BUFFER;
  78. } else if ((BytesSwallowed == 2) &&
  79. RtlEqualMemory( *BuffPtr, "am", 2 )) {
  80. return SHELL_ALLOC_MEM;
  81. } else if ((BytesSwallowed == 2) &&
  82. RtlEqualMemory( *BuffPtr, "dm", 2 )) {
  83. return SHELL_DEALLOC_MEM;
  84. } else if ((BytesSwallowed == 2) &&
  85. RtlEqualMemory( *BuffPtr, "fb", 2 )) {
  86. return SHELL_FILL_BUFFER;
  87. } else if ((BytesSwallowed == 5) &&
  88. RtlEqualMemory( *BuffPtr, "fbusn", 5 )) {
  89. return SHELL_FILL_BUFFER_USN;
  90. } else if ((BytesSwallowed == 3) &&
  91. RtlEqualMemory( *BuffPtr, "pea", 3 )) {
  92. return SHELL_PUT_EA;
  93. } else if ((BytesSwallowed == 3) &&
  94. RtlEqualMemory( *BuffPtr, "fea", 3 )) {
  95. return SHELL_FILL_EA;
  96. } else if ((BytesSwallowed == 2) &&
  97. RtlEqualMemory( *BuffPtr, "di", 2 )) {
  98. return SHELL_DISPLAY_HANDLE;
  99. } else if ((BytesSwallowed == 2) &&
  100. RtlEqualMemory( *BuffPtr, "cl", 2 )) {
  101. return SHELL_CLOSE_HANDLE;
  102. } else if ((BytesSwallowed == 2) &&
  103. RtlEqualMemory( *BuffPtr, "rd", 2 )) {
  104. return SHELL_READ_FILE;
  105. } else if ((BytesSwallowed == 2) &&
  106. RtlEqualMemory( *BuffPtr, "pa", 2 )) {
  107. return SHELL_PAUSE;
  108. } else if ((BytesSwallowed == 3) &&
  109. RtlEqualMemory( *BuffPtr, "qea", 3 )) {
  110. return SHELL_QUERY_EAS;
  111. } else if ((BytesSwallowed == 3) &&
  112. RtlEqualMemory( *BuffPtr, "sea", 3 )) {
  113. return SHELL_SET_EAS;
  114. } else if ((BytesSwallowed == 2) &&
  115. RtlEqualMemory( *BuffPtr, "br", 2 )) {
  116. return SHELL_BREAK;
  117. } else if ((BytesSwallowed == 4) &&
  118. RtlEqualMemory( *BuffPtr, "oplk", 4 )) {
  119. return SHELL_OPLOCK;
  120. } else if ((BytesSwallowed == 4) &&
  121. RtlEqualMemory( *BuffPtr, "fsct", 4 )) {
  122. return SHELL_FSCTRL;
  123. } else if ((BytesSwallowed == 6) &&
  124. RtlEqualMemory( *BuffPtr, "sparse", 6 )) {
  125. return SHELL_SPARSE;
  126. } else if ((BytesSwallowed == 3) &&
  127. RtlEqualMemory( *BuffPtr, "usn", 3 )) {
  128. return SHELL_USN;
  129. } else if ((BytesSwallowed == 2) &&
  130. RtlEqualMemory( *BuffPtr, "rp", 2 )) {
  131. return SHELL_REPARSE;
  132. } else if ((BytesSwallowed == 5) &&
  133. RtlEqualMemory( *BuffPtr, "ioctl", 4 )) {
  134. return SHELL_IOCTL;
  135. } else if ((BytesSwallowed == 2) &&
  136. RtlEqualMemory( *BuffPtr, "wr", 2 )) {
  137. return SHELL_WRITE;
  138. } else if ((BytesSwallowed == 2) &&
  139. RtlEqualMemory( *BuffPtr, "qd", 2 )) {
  140. return SHELL_QDIR;
  141. } else if ((BytesSwallowed == 3) &&
  142. RtlEqualMemory( *BuffPtr, "dqd", 3 )) {
  143. return SHELL_DISPLAY_QDIR;
  144. } else if ((BytesSwallowed == 2) &&
  145. RtlEqualMemory( *BuffPtr, "qf", 2 )) {
  146. return SHELL_QFILE;
  147. } else if ((BytesSwallowed == 3) &&
  148. RtlEqualMemory( *BuffPtr, "dqf", 3 )) {
  149. return SHELL_DISPLAY_QFILE;
  150. } else if ((BytesSwallowed == 3) &&
  151. RtlEqualMemory( *BuffPtr, "ncd", 3 )) {
  152. return SHELL_NOTIFY_CHANGE;
  153. } else if ((BytesSwallowed == 2) &&
  154. RtlEqualMemory( *BuffPtr, "et", 2 )) {
  155. return SHELL_ENTER_TIME;
  156. } else if ((BytesSwallowed == 2) &&
  157. RtlEqualMemory( *BuffPtr, "dt", 2 )) {
  158. return SHELL_DISPLAY_TIME;
  159. } else if ((BytesSwallowed == 2) &&
  160. RtlEqualMemory( *BuffPtr, "sf", 2 )) {
  161. return SHELL_SETFILE;
  162. } else if ((BytesSwallowed == 2) &&
  163. RtlEqualMemory( *BuffPtr, "qv", 2 )) {
  164. return SHELL_QUERY_VOLUME;
  165. } else if ((BytesSwallowed == 3) &&
  166. RtlEqualMemory( *BuffPtr, "dqv", 3 )) {
  167. return SHELL_DISPLAY_QVOL;
  168. } else if ((BytesSwallowed == 2) &&
  169. RtlEqualMemory( *BuffPtr, "sv", 2 )) {
  170. return SHELL_SET_VOLUME;
  171. } else if ((BytesSwallowed == 3) &&
  172. RtlEqualMemory( *BuffPtr, "can", 2 )) {
  173. return SHELL_CANCEL_IO;
  174. }
  175. return SHELL_UNKNOWN;
  176. }
  177. BOOLEAN
  178. ExtractCmd (
  179. PCHAR *BufferPtr,
  180. PULONG BufferLen
  181. )
  182. {
  183. BOOLEAN Status;
  184. PCHAR CurrentLoc;
  185. PCHAR StartLoc;
  186. ULONG BytesSwallowed;
  187. //
  188. // Remember the total length and the starting position.
  189. // Bytes swallowed is zero.
  190. //
  191. CurrentLoc = *BufferPtr;
  192. BytesSwallowed = 0;
  193. Status = TRUE;
  194. //
  195. // Swallow leading white spaces.
  196. //
  197. CurrentLoc = SwallowWhite (CurrentLoc, &BytesSwallowed);
  198. //
  199. // If first character is NULL, then there was no command.
  200. //
  201. if (!*CurrentLoc) {
  202. Status = FALSE;
  203. //
  204. // Else find the next white space.
  205. //
  206. } else {
  207. StartLoc = CurrentLoc;
  208. CurrentLoc = SwallowNonWhite (CurrentLoc, &BytesSwallowed);
  209. }
  210. //
  211. // Update the passed in values.
  212. // Return the status of this operation.
  213. //
  214. *BufferPtr = StartLoc;
  215. *BufferLen = BytesSwallowed;
  216. return Status;
  217. }
  218. VOID
  219. CommandSummary ()
  220. {
  221. printf( "\nBSHELL Command Summary" );
  222. printf( "\n\tdie Exit BSHELL" );
  223. printf( "\n\tpa Pause input" );
  224. printf( "\n\tbr Break into debugger" );
  225. printf( "\n" );
  226. printf( "\n\top Open a file, directory or volume" );
  227. printf( "\n\tcan Cancel IO on a handle" );
  228. printf( "\n\tcl Close a file handle" );
  229. printf( "\n" );
  230. printf( "\n\tqd Query directory operation" );
  231. printf( "\n\tdqd Disply query directory buffer" );
  232. printf( "\n\tncd Notify change directory" );
  233. printf( "\n" );
  234. printf( "\n\trd Read from a file" );
  235. printf( "\n\twr Write to a file" );
  236. printf( "\n" );
  237. printf( "\n\tqf Query file information" );
  238. printf( "\n\tdqf Display query file buffer" );
  239. printf( "\n\tsf Set file information" );
  240. printf( "\n" );
  241. printf( "\n\tqv Query volume information" );
  242. printf( "\n\tdqv Display volume informatin" );
  243. printf( "\n\tsv Set volume information" );
  244. printf( "\n" );
  245. printf( "\n\tfsct Fsctrl operation" );
  246. printf( "\n\tsparse Sparse file operation" );
  247. printf( "\n\tusn Usn operation" );
  248. printf( "\n\trp Reparse operation" );
  249. printf( "\n\toplk Oplock operation" );
  250. printf( "\n\tioctl Ioctl operation" );
  251. printf( "\n" );
  252. printf( "\n\tclb Clear a buffer" );
  253. printf( "\n\tdb Display a buffer in bytes" );
  254. printf( "\n\tdw Display a buffer in words" );
  255. printf( "\n\tdd Display a buffer in dwords" );
  256. printf( "\n\tcb Copy a buffer" );
  257. printf( "\n\tfb Fill a buffer" );
  258. printf( "\n\tfbusn Fill a usn fsctl buffer" );
  259. printf( "\n" );
  260. printf( "\n\tam Allocate memory" );
  261. printf( "\n\tdm Deallocate memory" );
  262. printf( "\n" );
  263. printf( "\n\tdi Display information on an index" );
  264. printf( "\n" );
  265. printf( "\n\tqea Query the ea's for a file" );
  266. printf( "\n\tsea Set the ea's for a file" );
  267. printf( "\n\tpea Store an ea name in a buffer for query ea" );
  268. printf( "\n\tfea Store an ea name in a buffer to set an ea" );
  269. printf( "\n" );
  270. printf( "\n\tet Enter a time value into a buffer" );
  271. printf( "\n\tdt Display a buffer as a time value" );
  272. printf( "\n\n" );
  273. return;
  274. }