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.

256 lines
6.2 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. jitdump.cxx
  5. Abstract:
  6. This file contains routines to dump typelib generated proxy information.
  7. Author:
  8. Yong Qu (yongqu) August 24 1999
  9. Revision History:
  10. --*/
  11. #include <ole2.h>
  12. #include <oleauto.h>
  13. #include <oaidl.h>
  14. #include <windows.h>
  15. #include <malloc.h>
  16. #include <stdio.h>
  17. #include "jitdump.h"
  18. // CreateStubFromTypeInfo is a private export. We have to LoadLibrary to
  19. // retrieve it.
  20. PFNCREATESTUBFROMTYPEINFO pfnCreateStubFromTypeInfo = NULL;
  21. void PrintHelp()
  22. {
  23. printf("usage: jitdump <tlbname> [{iid} [<procnum>]]\n");
  24. printf("Arguments:\n");
  25. printf("\t<tlbname> typelibrary filename.\n");
  26. printf("\t[{iid}] when presented, jitdump will dump all proc info of the interface \n");
  27. printf("\t[<procnum>] when presented, jitdump will dump only the specified proc info\n");
  28. }
  29. //+---------------------------------------------------------------------------
  30. //
  31. // Function: PrintStubInfo
  32. //
  33. // Synopsis: Create a proxy from given type library name and IID, then
  34. // dump the specified procedure information accordingly.
  35. // NdrpDumpStubProc is exported from ndrexts.dll. The debug
  36. // extension needs to be presented during runtime.
  37. // Dump all the methods if nProcNum is 0.
  38. //
  39. // Returns:
  40. // S_OK if everything is fine.
  41. // error code if error occur somewhere.
  42. //
  43. //----------------------------------------------------------------------------
  44. HRESULT PrintStubInfo(LPOLESTR wszFile, REFIID riid, unsigned long nProcNum)
  45. {
  46. HRESULT hr;
  47. ITypeLib *pTypeLib = NULL;
  48. ITypeInfo *pTypeInfo = NULL;
  49. IRpcStubBuffer *pStub;
  50. hr = LoadTypeLib(wszFile,&pTypeLib);
  51. if (SUCCEEDED(hr))
  52. {
  53. hr = pTypeLib->GetTypeInfoOfGuid(riid,&pTypeInfo);
  54. }
  55. if (SUCCEEDED(hr))
  56. {
  57. hr = (*pfnCreateStubFromTypeInfo)(pTypeInfo,riid,NULL, &pStub);
  58. }
  59. if (SUCCEEDED(hr))
  60. {
  61. if (nProcNum > 0)
  62. NdrpDumpStubProc(pStub,nProcNum);
  63. else
  64. NdrpDumpStub(pStub);
  65. pStub->Release();
  66. }
  67. if (pTypeLib)
  68. pTypeLib->Release();
  69. return hr;
  70. }
  71. // dump all the interface defined in the tlb.
  72. HRESULT PrintAllStubInfo(LPOLESTR wszFile)
  73. {
  74. int nCount = 0;
  75. HRESULT hr = S_OK;
  76. ITypeLib *pTypeLib = NULL;
  77. ITypeInfo *pTypeInfo = NULL;
  78. IRpcStubBuffer *pStub = NULL;
  79. TYPEATTR *pTypeAttr = NULL;
  80. TYPEKIND tkind;
  81. hr = LoadTypeLib(wszFile,&pTypeLib);
  82. if (SUCCEEDED(hr))
  83. {
  84. nCount = pTypeLib->GetTypeInfoCount();
  85. }
  86. for (int i = 0; ( i < nCount ) ; i++)
  87. {
  88. hr = pTypeLib->GetTypeInfoType(i,&tkind);
  89. if (FAILED(hr))
  90. break;
  91. // we need to process interface only.
  92. if (tkind == TKIND_INTERFACE ||
  93. tkind == TKIND_DISPATCH )
  94. {
  95. hr = pTypeLib->GetTypeInfo(i,&pTypeInfo);
  96. if (SUCCEEDED(hr))
  97. {
  98. hr = pTypeInfo->GetTypeAttr(&pTypeAttr);
  99. if (SUCCEEDED(hr))
  100. {
  101. hr = (*pfnCreateStubFromTypeInfo)(pTypeInfo,pTypeAttr->guid,NULL, &pStub);
  102. // IDispatch, IUnknown etc. would show up here also. We'll continue without
  103. // dumping those interface.
  104. if (SUCCEEDED(hr))
  105. {
  106. NdrpDumpStub(pStub);
  107. pStub->Release();
  108. }
  109. pTypeInfo->ReleaseTypeAttr(pTypeAttr);
  110. }
  111. pTypeInfo->Release();
  112. }
  113. }
  114. }
  115. if (pTypeLib)
  116. pTypeLib->Release();
  117. return hr;
  118. }
  119. void __cdecl main(int argc, char *argv[])
  120. {
  121. HRESULT ret;
  122. GUID riid;
  123. unsigned long nProcNum,dwlen = 0;
  124. WCHAR *wszGUID = NULL, *wszFile = NULL;
  125. char *szTLB;
  126. if ( argc < 2 || argc > 4)
  127. {
  128. PrintHelp();
  129. return;
  130. }
  131. ret = CoInitialize(NULL);
  132. if (FAILED (ret) )
  133. {
  134. printf("CoInitialize failed 0x%x\n",ret);
  135. return;
  136. }
  137. // load rpcrt4!CreateStubFromTypeInfo. It's not in .lib file
  138. if (NULL == pfnCreateStubFromTypeInfo )
  139. {
  140. HMODULE hMod = LoadLibraryA("rpcrt4.dll");
  141. if (hMod)
  142. {
  143. pfnCreateStubFromTypeInfo = (PFNCREATESTUBFROMTYPEINFO)GetProcAddress(hMod,
  144. "CreateStubFromTypeInfo");
  145. }
  146. if (NULL == hMod || NULL == pfnCreateStubFromTypeInfo )
  147. {
  148. printf("can't load rpcrt4.dll\n");
  149. return;
  150. }
  151. }
  152. // covert the filename to LPOLESTR to be used in LoadTypeLib
  153. dwlen = ( strlen(argv[1]) + 1 ) * sizeof(OLECHAR) ;
  154. wszFile = (LPOLESTR)alloca( dwlen );
  155. memset( wszFile , 0 , dwlen );
  156. dwlen /= sizeof(OLECHAR); // MultiByteTo wants a char count
  157. if ( !MultiByteToWideChar(CP_ACP, 0, argv[1], -1, wszFile, dwlen ) )
  158. {
  159. printf("Can't process iid, error is 0x%x \n", GetLastError() );
  160. return;
  161. }
  162. if ( argc == 2 )
  163. {
  164. // dump all interfaces if only tlb name is provided.
  165. ret = PrintAllStubInfo(wszFile);
  166. }
  167. else
  168. {
  169. // convert iid string into real iid.
  170. dwlen = ( strlen(argv[2]) + 1 ) * sizeof(OLECHAR) ;
  171. wszGUID = (LPOLESTR)alloca( dwlen );
  172. memset( wszGUID , 0 , dwlen );
  173. dwlen /= sizeof(OLECHAR);
  174. if ( !MultiByteToWideChar(CP_ACP, 0, argv[2], -1, wszGUID, dwlen ) )
  175. {
  176. printf("Can't process iid, error is 0x%x \n", GetLastError() );
  177. return;
  178. }
  179. ret = IIDFromString(wszGUID, &riid );
  180. if ( FAILED (ret) )
  181. {
  182. printf("can't convert iid %S 0x%x\n",wszGUID,ret);
  183. PrintHelp();
  184. return;
  185. }
  186. if ( argc == 3 )
  187. {
  188. ret = PrintStubInfo(wszFile,riid,0);
  189. }
  190. else
  191. {
  192. nProcNum = atol(argv[3]);
  193. ret = PrintStubInfo(wszFile,riid,nProcNum);
  194. }
  195. }
  196. if ( ret != S_OK )
  197. {
  198. printf("failed to dump the proxy 0x%x \n",ret);
  199. }
  200. CoUninitialize();
  201. }