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.

318 lines
5.4 KiB

  1. #####################################################################
  2. #
  3. #
  4. #
  5. # Perl script to process structures/classes and output
  6. # a debugger extension function
  7. #
  8. # Usage:
  9. # perl process.pl < <header-file>
  10. #
  11. # Output:
  12. # Code to dump structures/classes contained in header files (dumped to stdout)
  13. #
  14. # Function prototypes for the created functions in "prototypes.txt"
  15. #
  16. # Gotchas:
  17. # Works good when the header file does not contain embedded structure
  18. # definitions inside class/struct declarations. All bets are off if this
  19. # occurs
  20. #
  21. # Change History
  22. #
  23. # 01-26-97:
  24. # Feroze Daud ( ferozed ) created
  25. #
  26. #
  27. #
  28. #
  29. #####################################################################
  30. $|=1;
  31. $debug = 0;
  32. $full_code = 1;
  33. %typemap = (
  34. DWORD, "%d",
  35. VOID, "",
  36. LPVOID, "0X%X",
  37. int, "%d",
  38. char, "%c",
  39. LPSTR, "%s",
  40. LPTSTR, "%s",
  41. HINTERNET, "0X%X",
  42. BOOL, "%d",
  43. ICSTRING, "STRUCT",
  44. XSTRING, "STRUCT",
  45. PROXY_INFO, "STRUCT",
  46. RESOURCE_LOCK, "STRUCT",
  47. LONG, "%d",
  48. CSOCKET, "STRUCT",
  49. ICSocket, "STRUCT",
  50. INTERNET_PORT, "%d",
  51. INTERNET_SCHEME,"%d",
  52. CServerInfo, "STRUCT",
  53. HEADER_STRING, "STRUCT",
  54. CHUNK_TRANSFER, "STRUCT",
  55. HTTPREQ_STATE, "%d",
  56. HTTP_HEADERS, "0X%X",
  57. HTTP_METHOD_TYPE, "%d",
  58. LPBYTE, "0X%X",
  59. FILETIME, "%d",
  60. LPCACHE_ENTRY_INFO, "STRUCT",
  61. AUTHCTX, "STRUCT",
  62. SECURITY_CACHE_LIST_ENTRY, "STRUCT",
  63. RESOURCE_LOCK, "STRUCT",
  64. RESOURCE_INFO,"STRUCT",
  65. LIST_ENTRY, "STRUCT",
  66. SERIALIZED_LIST, "STRUCT",
  67. PROXY_SERVER_LIST,"STRUCT",
  68. PROXY_SERVER_LIST_ENTRY,"STRUCT",
  69. PROXY_BYPASS_LIST, "STRUCT",
  70. PROXY_BYPASS_LIST_ENTRY,"STRUCT",
  71. BAD_PROXY_LIST,"STRUCT",
  72. BAD_PROXY_LIST_ENTRY,"STRUCT",
  73. PROXY_INFO, "STRUCT"
  74. );
  75. open( PROTOTYPES, ">prototypes.txt" ) || die ("Couldnt open prototypes file\n");
  76. while(<STDIN>) {
  77. #////////////////////////
  78. # Skip comments
  79. #////////////////////////
  80. if(/^\s*\/\/.*/) {
  81. next;
  82. }
  83. #////////////////////////
  84. # Skip friends and forward class declarations
  85. #////////////////////////
  86. if(
  87. /class\s+\w+\s*;/
  88. || /friend/
  89. ) {
  90. next;
  91. }
  92. #////////////////////////
  93. # Seeing a class or struct typedef
  94. #////////////////////////
  95. if(
  96. /(class)\s+(\w+)\s+\{/
  97. || /\s+(struct)\s+(\w+)\{/
  98. || /(typedef\s+struct)\s+(\w+)\{/
  99. ) {
  100. # print "<<$2>>\n";
  101. # print;
  102. $class = 1;
  103. $type = $1;
  104. $name = $2;
  105. if( $full_code == 1 ) {
  106. &print_code_header($1,$2);
  107. print PROTOTYPES "DECLARE_API($name);\n";
  108. print PROTOTYPES "void do_$name( DWORD addr ); \n";
  109. }
  110. next;
  111. }
  112. #////////////////////////
  113. # Print all #ifdef/#endif
  114. #////////////////////////
  115. if(
  116. /#ifdef/
  117. || /#endif/
  118. || /#if/
  119. ) {
  120. print;
  121. next;
  122. }
  123. # If not inside a class or a struct, skip to next line
  124. if( $class == 0 ) {
  125. next;
  126. }
  127. # Seeing end of a class/struct
  128. if( /\s*\}.*;/ ) {
  129. &end_code($name);
  130. print "\n\n";
  131. # print //;
  132. # print;
  133. # print "//$name";
  134. # print "//------------------------------------\n";
  135. $class = 0;
  136. next;
  137. }
  138. # Skip all member/non-member functions
  139. if( /\(.*\)/ ) {
  140. next;
  141. }
  142. # print data types
  143. if(
  144. /DWORD/
  145. || /VOID/
  146. || /LPVOID/
  147. || /int/
  148. || /char/
  149. || /LPSTR/
  150. || /LPTSTR/
  151. || /HINTERNET/
  152. || /BOOL/
  153. || /ICSTRING/
  154. || /XSTRING/
  155. || /PROXY_INFO/
  156. || /RESOURCE_LOCK/
  157. || /LONG/
  158. || /CSOCKET/
  159. || /ICSocket/
  160. || /INTERNET_PORT/
  161. || /INTERNET_SCHEME/
  162. || /CServerInfo/
  163. || /HEADER_STRING/
  164. || /CHUNK_TRANSFER/
  165. || /HTTPREQ_STATE/
  166. || /HTTP_HEADERS/
  167. || /HTTP_METHOD_TYPE/
  168. || /LPBYTE/
  169. || /FILETIME/
  170. || /LPCACHE_ENTRY_INFO/
  171. || /AUTHCTX/
  172. || /SECURITY_CACHE_LIST_ENTRY/
  173. || /RESOURCE_INFO/
  174. || /LIST_ENTRY/
  175. || /SERIALIZED_LIST/
  176. || /PROXY_SERVER_LIST/
  177. || /PROXY_SERVER_LIST_ENTRY/
  178. || /PROXY_BYPASS_LIST/
  179. || /PROXY_BYPASS_LIST_ENTRY/
  180. || /BAD_PROXY_LIST/
  181. || /BAD_PROXY_LIST_ENTRY/
  182. || /PROXY_INFO/
  183. ) {
  184. /(\w+)\s*(\*)?\s*(\w+)\s*;/;
  185. if( $debug == 1) {
  186. print "$1 - $2 - $3\n";
  187. }
  188. if (
  189. ( $1 eq "" )
  190. || ( $3 eq "" )
  191. ) {
  192. next;
  193. }
  194. $fmt = $typemap{$1};
  195. if( $fmt eq "" ) {
  196. $fmt = "%d"
  197. }
  198. print "\t//$1 $2 $3\n";
  199. if( $2 eq "*" ) {
  200. print "\td_printf(\"\\t$1 $2 $3 0x%x\\n\", obj -> $3);\n";
  201. } else {
  202. if( $fmt eq "STRUCT" ) {
  203. print "\td_printf(\"\\t$1 (*) $3 0x%x\\n\", OFFSET( $name, $3) );\n";
  204. } else {
  205. print "\td_printf(\"\\t$1 $3 $fmt\\n\", obj -> $3);\n";
  206. }
  207. }
  208. print "\n";
  209. }
  210. }
  211. close( PROTOTYPES );
  212. exit;
  213. sub print_code_header {
  214. #
  215. # $type = "class" | "struct"
  216. #
  217. $type = shift;
  218. #
  219. # The name of the structure being dumped
  220. #
  221. $name = shift;
  222. print <<EOL;
  223. /////////////////////////////////////////////////
  224. //
  225. // $name structure
  226. //
  227. /////////////////////////////////////////////////
  228. DECLARE_API( $name )
  229. {
  230. DWORD dwAddr;
  231. INIT_DPRINTF();
  232. dwAddr = d_GetExpression(lpArgumentString);
  233. if ( !dwAddr )
  234. {
  235. return;
  236. }
  237. do_$name(dwAddr);
  238. }
  239. VOID
  240. do_$name(
  241. DWORD addr
  242. )
  243. {
  244. BOOL b;
  245. char block[ sizeof( $name ) ];
  246. PROXY_INFO * obj = ($name *) &block;
  247. b = GetData(
  248. addr,
  249. block,
  250. sizeof( $name ),
  251. NULL);
  252. if ( !b ) {
  253. d_printf("couldn't read $name at 0x%x; sorry.\\n", addr);
  254. return;
  255. }
  256. d_printf("$name @ 0x%x \\n\\n", addr);
  257. EOL
  258. }
  259. sub end_code {
  260. $name = shift;
  261. print <<'EOL';
  262. d_printf("\n");
  263. EOL
  264. print "} // $name\n";
  265. }