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.

1001 lines
33 KiB

  1. #include <wmiexts.h>
  2. #include <oleauto.h>
  3. #ifndef COREPROX_POLARITY
  4. #define COREPROX_POLARITY
  5. #endif
  6. #include <arena.h>
  7. #include <faster.h>
  8. #include <faststr.h>
  9. #include <wbemint.h>
  10. #include <fastcls.h>
  11. #include <var.h>
  12. #include <fastinst.h>
  13. #include <wbemdatapacket.h>
  14. //#include <smartnextpacket.h>
  15. #pragma pack( push )
  16. #pragma pack( 1 )
  17. // IWbemWCOSmartEnum::Next() Header. Changing this will
  18. // cause the main version to change
  19. typedef struct tagWBEM_DATAPACKET_SMARTENUM_NEXT
  20. {
  21. DWORD dwSizeOfHeader; // Size of the header struct. Data immediately follows header.
  22. DWORD dwDataSize; // Size of Data following header.
  23. } WBEM_DATAPACKET_SMARTENUM_NEXT;
  24. typedef WBEM_DATAPACKET_SMARTENUM_NEXT* PWBEM_DATAPACKET_SMARTENUM_NEXT;
  25. // restore packing
  26. #pragma pack( pop )
  27. //#include <objarraypacket.h>
  28. #pragma pack( push )
  29. #pragma pack( 1 )
  30. // IWbemClassObject Array Header. Changing this will
  31. // cause the main version to change
  32. typedef struct tagWBEM_DATAPACKET_OBJECT_ARRAY
  33. {
  34. DWORD dwSizeOfHeader; // Size of the header struct. Data immediately follows header.
  35. DWORD dwDataSize; // Size of Data following header.
  36. DWORD dwNumObjects; // Number of objects in the array
  37. } WBEM_DATAPACKET_OBJECT_ARRAY;
  38. typedef WBEM_DATAPACKET_OBJECT_ARRAY* PWBEM_DATAPACKET_OBJECT_ARRAY;
  39. // restore packing
  40. #pragma pack( pop )
  41. #pragma pack( push )
  42. #pragma pack( 1 )
  43. // IWbemObjectSink::Indicate() Header. Changing this will
  44. // cause the main version to change
  45. typedef struct tagWBEM_DATAPACKET_OBJECTSINK_INDICATE
  46. {
  47. DWORD dwSizeOfHeader; // Size of the header struct. Data immediately follows header.
  48. DWORD dwDataSize; // Size of Data following header.
  49. } WBEM_DATAPACKET_OBJECTSINK_INDICATE;
  50. typedef WBEM_DATAPACKET_OBJECTSINK_INDICATE* PWBEM_DATAPACKET_OBJECTSINK_INDICATE;
  51. // restore packing
  52. #pragma pack( pop )
  53. #pragma pack( push )
  54. #pragma pack( 1 )
  55. // IWbemObjectSink::Indicate() Header. Changing this will
  56. // cause the main version to change
  57. typedef struct tagWBEM_DATAPACKET_UNBOUNDSINK_INDICATE
  58. {
  59. DWORD dwSizeOfHeader; // Size of the header struct. Data immediately follows header.
  60. DWORD dwDataSize; // Size of Data following header.
  61. DWORD dwLogicalConsumerSize; // Size of Logical Consumer Object
  62. } WBEM_DATAPACKET_UNBOUNDSINK_INDICATE;
  63. #ifdef _WIN64
  64. typedef UNALIGNED WBEM_DATAPACKET_UNBOUNDSINK_INDICATE * PWBEM_DATAPACKET_UNBOUNDSINK_INDICATE;
  65. #else
  66. typedef WBEM_DATAPACKET_UNBOUNDSINK_INDICATE * PWBEM_DATAPACKET_UNBOUNDSINK_INDICATE;
  67. #endif
  68. // restore packing
  69. #pragma pack( pop )
  70. #include <wbemobjpacket.h>
  71. #include <malloc.h>
  72. #ifndef HEAP_ENTRY
  73. typedef struct _HEAP_ENTRY
  74. {
  75. USHORT Size;
  76. USHORT PreviousSize;
  77. UCHAR SegmentIndex;
  78. UCHAR Flags;
  79. UCHAR UnusedBytes;
  80. UCHAR SmallTagIndex;
  81. #if defined(_WIN64)
  82. ULONGLONG Reserved1;
  83. #endif
  84. } HEAP_ENTRY, *PHEAP_ENTRY;
  85. #endif
  86. void GetCompressedString(ULONG_PTR pRemoteAddr,
  87. BYTE * pBuff,
  88. DWORD Size){
  89. if (pRemoteAddr) {
  90. CCompressedString * pCS = (CCompressedString *)_alloca(Size*2);
  91. ReadMemory(pRemoteAddr,pCS,Size*2,0);
  92. pBuff[Size-2]=0;
  93. pBuff[Size-1]=0;
  94. if (pCS->m_fFlags == STRING_FLAG_UNICODE){
  95. WideCharToMultiByte(CP_ACP,0,(WCHAR *)&(pCS->m_cFirstByte),-1,(LPSTR)pBuff,Size-2,NULL,NULL);
  96. } else {
  97. memcpy(pBuff,&(pCS->m_cFirstByte),Size-2);
  98. }
  99. } else {
  100. lstrcpyA((LPSTR)pBuff,"<NULL>");
  101. }
  102. }
  103. /*
  104. protected:
  105. length_t m_nTotalLength;
  106. //CDecorationPart m_DecorationPart;
  107. CClassAndMethods m_ParentPart;
  108. CClassAndMethods m_CombinedPart;
  109. int m_nCurrentMethod;
  110. CLimitationMapping* m_pLimitMapping;
  111. friend class CWbemInstance;
  112. */
  113. /*
  114. CClassPart m_ClassPart;
  115. CMethodPart m_MethodPart;
  116. CWbemClass* m_pClass;
  117. */
  118. void
  119. DumpClass(CClassPart * pCls){
  120. BYTE pBuff[256];
  121. dprintf(" m_pContainer %p m_pParent %p m_pHeader %p\n",pCls->m_pContainer,pCls->m_pParent,pCls->m_pHeader);
  122. DEFINE_CPP_VAR(CClassPart::CClassPartHeader,varHeader);
  123. CClassPart::CClassPartHeader * pHeader = GET_CPP_VAR_PTR( CClassPart::CClassPartHeader , varHeader );
  124. if (pCls->m_pHeader){
  125. ReadMemory((ULONG_PTR)pCls->m_pHeader,pHeader,sizeof(CClassPart::CClassPartHeader),0);
  126. dprintf(" nLength %x fFlags %02x ptrClassName %08x nDataLength %x\n",pHeader->nLength,pHeader->fFlags,pHeader->ptrClassName,pHeader->nDataLength);
  127. }
  128. dprintf(" DL m_nNumStrings %x %08x\n",pCls->m_Derivation.m_nNumStrings,pCls->m_Derivation.m_pnLength);
  129. dprintf(" QS m_nLength %x m_pOthers %08x m_pHeap %08x\n",pCls->m_Qualifiers.m_nLength,pCls->m_Qualifiers.m_pOthers,pCls->m_Qualifiers.m_pHeap);
  130. DEFINE_CPP_VAR(CFastHeap,varCFastHeap);
  131. CFastHeap * pFHeap = GET_CPP_VAR_PTR( CFastHeap , varCFastHeap );
  132. ReadMemory((ULONG_PTR)pCls->m_Qualifiers.m_pHeap,pFHeap,sizeof(CFastHeap),0);
  133. dprintf(" FH m_pHeapData %08x m_pHeapHeader %08x m_pContainer %08x\n",pFHeap->m_pHeapData,pFHeap->m_pHeapHeader,pFHeap->m_pContainer);
  134. dprintf(" m_nPropagationFlag %x m_nRef %x\n",pCls->m_Qualifiers.m_nPropagationFlag,pCls->m_Qualifiers.m_nRef);
  135. dprintf(" m_pControl %08x m_pContainer %08x m_pSecondarySet %08x\n",pCls->m_Qualifiers.m_pControl,pCls->m_Qualifiers.m_pContainer,pCls->m_Qualifiers.m_pSecondarySet);
  136. dprintf(" BA m_nSize %x m_astrStrings %08x\n",pCls->m_Qualifiers.m_astrCurrentNames.m_nSize,pCls->m_Qualifiers.m_astrCurrentNames.m_astrStrings);
  137. int nProp;
  138. if (pCls->m_Properties.m_pnProps) {
  139. ReadMemory((ULONG_PTR)pCls->m_Properties.m_pnProps,&nProp,sizeof(int),0);
  140. dprintf(" PR m_pnProps %08x %x m_pContainer %08x\n",pCls->m_Properties.m_pnProps,nProp,pCls->m_Properties.m_pContainer);
  141. CPropertyLookup * pPropLook = (CPropertyLookup *)_alloca(nProp*sizeof(CPropertyLookup));
  142. ReadMemory((ULONG_PTR)pCls->m_Properties.m_pnProps+sizeof(int),pPropLook,nProp*sizeof(CPropertyLookup),0);
  143. DWORD i;
  144. for (i=0;i<nProp;i++){
  145. pBuff[0]=0;
  146. if ((ULONG_PTR)(pCls->m_Heap.m_pHeapData+pPropLook[i].ptrName) != 0xffffffff){
  147. GetCompressedString((ULONG_PTR)(pCls->m_Heap.m_pHeapData+pPropLook[i].ptrName),pBuff,sizeof(pBuff));
  148. }
  149. DEFINE_CPP_VAR(CPropertyInformation,varCPropertyInformation);
  150. CPropertyInformation * pPropInfo = GET_CPP_VAR_PTR( CPropertyInformation , varCPropertyInformation );
  151. ReadMemory((ULONG_PTR)pCls->m_Heap.m_pHeapData+pPropLook[i].ptrInformation,pPropInfo ,sizeof(CPropertyInformation),0);
  152. dprintf(" prop %d %s Type %08x DataIdx %04x DataOff %08x Origin %08x\n",i,
  153. pBuff,
  154. pPropInfo->nType,
  155. pPropInfo->nDataIndex,
  156. pPropInfo->nDataOffset,
  157. pPropInfo->nOrigin);
  158. if (CheckControlC())
  159. break;
  160. }
  161. } else {
  162. dprintf(" PR m_pnProps %08x m_pContainer %08x\n",pCls->m_Properties.m_pnProps,pCls->m_Properties.m_pContainer);
  163. }
  164. CDataTable * pCData = &pCls->m_Defaults;
  165. dprintf(" DT m_pNullness %08x m_pData %08x m_nLength %x m_nProps %x m_pContainer %08x\n",pCData->m_pNullness,pCData->m_pData,pCData->m_nLength,pCData->m_nProps,pCData->m_pContainer);
  166. dprintf(" FH m_pHeapData %08x m_pHeapHeader %08x m_pContainer %08x\n",pCls->m_Heap.m_pHeapData,pCls->m_Heap.m_pHeapHeader,pCls->m_Heap.m_pContainer);
  167. //CHeapHeader m_LocalHeapHeader;
  168. BYTE * pHeap = pCls->m_Heap.m_pHeapData;
  169. pBuff[0]=0;
  170. if ((DWORD)(pHeader->ptrClassName) != 0xffffffff){
  171. GetCompressedString((ULONG_PTR)(pHeap+pHeader->ptrClassName),pBuff,sizeof(pBuff));
  172. }
  173. dprintf(" __RELPATH %s\n",pBuff);
  174. }
  175. DECLARE_API(wc) {
  176. INIT_API();
  177. DEFINE_CPP_VAR( CWbemClass, varCWbemClass);
  178. CWbemClass * pCls = GET_CPP_VAR_PTR( CWbemClass , varCWbemClass );
  179. ULONG_PTR pByte = 0;
  180. pByte = GetExpression(args);
  181. if (pByte){
  182. ReadMemory(pByte,pCls,sizeof(CWbemClass),0);
  183. dprintf(" m_nRef %d m_bOwnMemory %d\n",pCls->m_nRef,pCls->m_bOwnMemory);
  184. dprintf(" m_nCurrentProp %08x m_lEnumFlags %08x m_lExtEnumFlags %08x\n",pCls->m_nCurrentProp,pCls->m_lEnumFlags,pCls->m_lExtEnumFlags);
  185. dprintf(" m_dwInternalStatus %08x m_pMergedClassObject %08x\n",pCls->m_dwInternalStatus,pCls->m_pMergedClassObject);
  186. BYTE * pData = pCls->m_DecorationPart.m_pfFlags;
  187. BYTE pBuff1[256];
  188. GetCompressedString((ULONG_PTR)pCls->m_DecorationPart.m_pcsServer,pBuff1,sizeof(pBuff1));
  189. BYTE pBuff2[256];
  190. GetCompressedString((ULONG_PTR)pCls->m_DecorationPart.m_pcsNamespace,pBuff2,sizeof(pBuff2));
  191. BYTE b=0xff;
  192. if (pData){
  193. ReadMemory((ULONG_PTR)pData,&b,sizeof(b),0);
  194. }
  195. dprintf(" m_DecorationPart.m_pfFlags %p FLAG %02x\n",pData,b);
  196. dprintf(" Server: %s Namespace: %s\n",pBuff1,pBuff2);
  197. dprintf(" m_LockData: m_lLock %d m_lLockCount %d m_dwThreadId %x\n",pCls->m_LockData.m_lLock,pCls->m_LockData.m_lLockCount,pCls->m_LockData.m_dwThreadId);
  198. dprintf(" m_Lock.m_pData %p\n",pCls->m_Lock.m_pData);
  199. //dprintf(" m_pBlobControl %08x m_refDataTable %08x m_refDataHeap %08x m_refDerivationList %08x\n",pCls->m_pBlobControl,((void *)&pCls->m_refDataTable),((void *)&pCls->m_refDataHeap),((void *)&pCls->m_refDerivationList));
  200. dprintf(" m_pBlobControl %p\n",pCls->m_pBlobControl);
  201. DEFINE_CPP_VAR( CDataTable,varCDataTable);
  202. CDataTable * pCData = GET_CPP_VAR_PTR(CDataTable,varCDataTable);
  203. if(pCData){
  204. ReadMemory((ULONG_PTR)(&(pCls->m_refDataTable)),pCData,sizeof(CDataTable),0);
  205. dprintf(" m_pNullness %p m_pData %p m_nLength %x m_nProps %x m_pContainer %08x\n",pCData->m_pNullness,pCData->m_pData,pCData->m_nLength,pCData->m_nProps,pCData->m_pContainer);
  206. }
  207. DEFINE_CPP_VAR(CFastHeap,varCFastHeap);
  208. CFastHeap * pFHeap = GET_CPP_VAR_PTR( CFastHeap , varCFastHeap );
  209. DWORD * pFoo = (DWORD *)&(pCls->m_refDataHeap);
  210. ReadMemory((ULONG_PTR )pFoo,pFHeap,sizeof(CFastHeap),0);
  211. dprintf(" FH m_pHeapData %p m_pHeapHeader %p m_pContainer %p\n",pFHeap->m_pHeapData,pFHeap->m_pHeapHeader,pFHeap->m_pContainer);
  212. dprintf(" m_nTotalLength %x\n",pCls->m_nTotalLength);
  213. dprintf(" m_ParentPart at offset %x\n",(ULONG_PTR)&pCls->m_ParentPart-(ULONG_PTR)pCls);
  214. dprintf(" m_ParentPart.m_pClassPart at offset %x\n",(ULONG_PTR)&(pCls->m_ParentPart.m_ClassPart)-(ULONG_PTR)pCls);
  215. DumpClass(&(pCls->m_ParentPart.m_ClassPart));
  216. dprintf(" m_CombinedPart at offset %x\n",(ULONG_PTR)&pCls->m_CombinedPart-(ULONG_PTR)pCls);
  217. DumpClass(&(pCls->m_CombinedPart.m_ClassPart));
  218. dprintf(" m_pClass %08x\n",pCls->m_ParentPart.m_pClass);
  219. } else {
  220. dprintf("invalid address %s\n",args);
  221. }
  222. }
  223. void
  224. DumpInstance(CInstancePart * pIns){
  225. BYTE pBuff[256];
  226. dprintf(" m_pContainer %08x m_pHeader %08x\n",pIns->m_pContainer,pIns->m_pHeader);
  227. dprintf(" DT m_DataTable m_pNullness %08x m_pData %08x\n",pIns->m_DataTable.m_pNullness,pIns->m_DataTable.m_pData);
  228. dprintf(" m_nLength %x m_nProps %x m_pContainer %08x\n",pIns->m_DataTable.m_nLength,pIns->m_DataTable.m_nProps,pIns->m_DataTable.m_pContainer);
  229. dprintf(" Q m_Qualifiers m_nPropagationFlag %08x m_nRef %x m_pControl %08x\n",pIns->m_Qualifiers.m_nPropagationFlag,pIns->m_Qualifiers.m_nRef,pIns->m_Qualifiers.m_pControl);
  230. dprintf(" m_pContainer %08x m_pSecondarySet %08x\n",pIns->m_Qualifiers.m_pContainer,pIns->m_Qualifiers.m_pSecondarySet);
  231. CFixedBSTRArray * pArr = &(pIns->m_Qualifiers.m_astrCurrentNames);
  232. dprintf(" m_nCurrentIndex %x\n",pIns->m_Qualifiers.m_nCurrentIndex);
  233. DEFINE_CPP_VAR(CInstancePart::CInstancePartHeader,varHeader);
  234. CInstancePart::CInstancePartHeader * pHeader = GET_CPP_VAR_PTR( CInstancePart::CInstancePartHeader , varHeader );
  235. if (pIns->m_pHeader){
  236. ReadMemory((ULONG_PTR)pIns->m_pHeader,pHeader,sizeof(CInstancePart::CInstancePartHeader),0);
  237. dprintf(" nLength %x fFlags %02x ptrClassName %08x \n",pHeader->nLength,pHeader->fFlags,pHeader->ptrClassName);
  238. }
  239. dprintf(" FH m_pHeapData %08x m_pHeapHeader %08x m_pContainer %08x\n",pIns->m_Heap.m_pHeapData,pIns->m_Heap.m_pHeapHeader,pIns->m_Heap.m_pContainer);
  240. }
  241. DECLARE_API(wi) {
  242. INIT_API();
  243. DEFINE_CPP_VAR( CWbemInstance, varCWbemInstance);
  244. CWbemInstance * pCls = GET_CPP_VAR_PTR( CWbemInstance , varCWbemInstance );
  245. ULONG_PTR pByte = 0;
  246. pByte = GetExpression(args);
  247. if (pByte){
  248. ReadMemory(pByte,pCls,sizeof(CWbemInstance),0);
  249. //length_t m_nTotalLength;
  250. //dprintf(" m_nTotalLength %08x\n",pCls->m_nTotalLength);
  251. BYTE * pData = pCls->m_DecorationPart.m_pfFlags;
  252. BYTE pBuff1[256];
  253. GetCompressedString((ULONG_PTR)pCls->m_DecorationPart.m_pcsServer,pBuff1,sizeof(pBuff1));
  254. BYTE pBuff2[256];
  255. GetCompressedString((ULONG_PTR)pCls->m_DecorationPart.m_pcsNamespace,pBuff2,sizeof(pBuff2));
  256. BYTE b=0xff;
  257. if (pData){
  258. ReadMemory((ULONG_PTR)pData,&b,sizeof(b),0);
  259. }
  260. dprintf(" m_DecorationPart.m_pfFlags %p FLAG %02x\n",pData,b);
  261. dprintf(" Server: %s Namespace: %s\n",pBuff1,pBuff2);
  262. //CClassPart m_ClassPart;
  263. DumpClass(&(pCls->m_ClassPart));
  264. //CInstancePart m_InstancePart;
  265. DumpInstance(&(pCls->m_InstancePart));
  266. //CVar m_CachedKey;
  267. dprintf(" m_vt %08x m_value %08x m_nStatus %08x m_bCanDelete %08x\n",pCls->m_CachedKey.m_vt,pCls->m_CachedKey.m_value.pUnk,pCls->m_CachedKey.m_nStatus,pCls->m_CachedKey.m_bCanDelete);
  268. } else {
  269. dprintf("invalid address %s\n",args);
  270. }
  271. }
  272. DECLARE_API(cp) {
  273. INIT_API();
  274. DEFINE_CPP_VAR( CClassPart, varCClassPart);
  275. CClassPart * pCls = GET_CPP_VAR_PTR( CClassPart , varCClassPart );
  276. ULONG_PTR pByte = 0;
  277. pByte = GetExpression(args);
  278. if (pByte){
  279. ReadMemory(pByte,pCls,sizeof(CClassPart),0);
  280. DumpClass(pCls);
  281. } else {
  282. dprintf("invalid address %s\n",args);
  283. }
  284. }
  285. /*
  286. typedef union
  287. {
  288. char cVal; // VT_I1
  289. BYTE bVal; // VT_UI1
  290. SHORT iVal; // VT_I2
  291. WORD wVal; // VT_UI2
  292. LONG lVal; // VT_I4
  293. DWORD dwVal; // VT_UI4
  294. VARIANT_BOOL boolVal; // VT_BOOL
  295. float fltVal; // VT_R4
  296. double dblVal; // VT_R8
  297. LPSTR pStr; // VT_LPSTR
  298. LPWSTR pWStr; // VT_LPWSTR
  299. BSTR Str; // VT_BSTR (stored as VT_LPWSTR)
  300. FILETIME Time; // VT_FILETIME
  301. BLOB Blob; // VT_BLOB
  302. LPCLSID pClsId; // VT_CLSID
  303. IUnknown* pUnk; // VT_UNKNOWN
  304. IDispatch* pDisp; // VT_DISPATCH
  305. CVarVector *pVarVector; // VT_EX_CVARVECTOR
  306. } METAVALUE;
  307. int m_vt;
  308. METAVALUE m_value;
  309. int m_nStatus;
  310. BOOL m_bCanDelete;
  311. */
  312. DECLARE_API(cvar) {
  313. INIT_API();
  314. DEFINE_CPP_VAR( CVar, varCVar);
  315. CVar * pVar = GET_CPP_VAR_PTR( CVar , varCVar );
  316. WCHAR pwBuff[128];
  317. CHAR pBuff[128];
  318. ULONG_PTR pByte = 0;
  319. pByte = GetExpression(args);
  320. if (pByte){
  321. ReadMemory(pByte,pVar,sizeof(CVar),0);
  322. switch(pVar->m_vt){
  323. case VT_I1:
  324. dprintf("VT_I1 %02x\n",pVar->m_value.cVal);
  325. break;
  326. case VT_UI1:
  327. dprintf("VT_UI1 %02x\n",pVar->m_value.bVal);
  328. break;
  329. case VT_I2:
  330. dprintf("VT_I2 %04x\n",pVar->m_value.iVal);
  331. break;
  332. case VT_UI2:
  333. dprintf("VT_UI2 %04x\n",pVar->m_value.wVal);
  334. break;
  335. case VT_I4:
  336. dprintf("VT_I4 %08x\n",pVar->m_value.lVal);
  337. break;
  338. case VT_UI4:
  339. dprintf("VT_UI4 %08x\n",pVar->m_value.dwVal);
  340. break;
  341. case VT_BOOL:
  342. dprintf("VT_BOOL %04x\n",pVar->m_value.boolVal);
  343. break;
  344. case VT_R4:
  345. dprintf("VT_R4 %f\n",pVar->m_value.fltVal);
  346. break;
  347. case VT_R8:
  348. dprintf("VT_R8 %e\n",pVar->m_value.dblVal);
  349. break;
  350. case VT_LPSTR:
  351. ReadMemory((ULONG_PTR)pVar->m_value.pStr,pBuff,sizeof(pBuff),0);
  352. pBuff[sizeof(pBuff)-1]=0;
  353. dprintf("VT_LPSTR %s\n",pBuff);
  354. break;
  355. case VT_LPWSTR:
  356. case VT_BSTR:
  357. ReadMemory((ULONG_PTR)pVar->m_value.pWStr,pwBuff,sizeof(pwBuff),0);
  358. pwBuff[sizeof(pwBuff)-1]=0;
  359. WideCharToMultiByte(CP_ACP,0,pwBuff,-1,pBuff,sizeof(pBuff),NULL,NULL);
  360. pBuff[sizeof(pBuff)-1]=0;
  361. dprintf("VT_BSTR %s\n",pBuff);
  362. break;
  363. /*
  364. FILETIME Time; // VT_FILETIME
  365. BLOB Blob; // VT_BLOB
  366. LPCLSID pClsId; // VT_CLSID
  367. IUnknown* pUnk; // VT_UNKNOWN
  368. IDispatch* pDisp; // VT_DISPATCH
  369. */
  370. case VT_EX_CVARVECTOR:
  371. //CVarVector *pVarVector; // VT_EX_CVARVECTOR
  372. dprintf("VT_EX_CVARVECTOR %08x\n",pVar->m_value.pVarVector);
  373. break;
  374. default:
  375. dprintf("m_vt %08x\n",pVar->m_vt);
  376. }
  377. } else {
  378. dprintf("invalid address %s\n",args);
  379. }
  380. }
  381. /*
  382. class POLARITY CVarVector
  383. {
  384. int m_nType;
  385. CFlexArray m_Array;
  386. int m_nStatus;
  387. */
  388. LPSTR g_QualStrings[] = {
  389. "", // nothing for index 0
  390. "key",
  391. "",
  392. "read",
  393. "write",
  394. "volatile",
  395. "provider",
  396. "dynamic",
  397. "cimwin32",
  398. "DWORD",
  399. "CIMTYPE"
  400. };
  401. DWORD g_ValLengths[128] =
  402. {
  403. /* 0*/ 0, 0, 2, 4, 4, 8, 0, 0, 4, 0,
  404. /*10*/ 0, 2, 0, 4, 0, 0, 1, 1, 2, 4,
  405. /*20*/ 8, 8, 0, 0, 0, 0, 0, 0, 0, 0,
  406. /*30*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  407. /*40*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  408. /*50*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  409. /*60*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  410. /*70*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  411. /*80*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  412. /*90*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  413. /*100*/0, 4, 4, 2, 0, 0, 0, 0, 0, 0,
  414. /*110*/0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  415. /*120*/0, 0, 0, 0, 0, 0, 0, 0
  416. };
  417. int lstrlenWunal( WCHAR UNALIGNED * pStr)
  418. {
  419. int ret = 0;
  420. while (*pStr++) ret++;
  421. return ret;
  422. };
  423. VOID
  424. ParseBlob(BYTE * pMemOrg,ULONG_PTR Addr)
  425. {
  426. DWORD ClassPartLength = 0;
  427. DWORD i;
  428. BYTE * pMem = pMemOrg;
  429. BYTE Flags;
  430. BOOL IsInstance = FALSE;
  431. BOOL SkipDecoration = TRUE;
  432. BYTE BFlags = *pMem;
  433. pMem++;
  434. if (WBEM_GENUS_CLASS & BFlags )
  435. {
  436. dprintf("CLASS\n");
  437. }
  438. if (WBEM_GENUS_INSTANCE & BFlags )
  439. {
  440. dprintf("INSTANCE\n");
  441. IsInstance = TRUE;
  442. }
  443. if (OBJECT_FLAG_LIMITED & BFlags)
  444. {
  445. dprintf("LIMITED\n");
  446. }
  447. if (OBJECT_FLAG_CLIENT_ONLY & BFlags)
  448. {
  449. dprintf("CLIENT_ONLY\n");
  450. }
  451. if (BFlags & OBJECT_FLAG_DECORATED)
  452. {
  453. SkipDecoration = FALSE;
  454. //dprintf("decoration:\n");
  455. Flags = *pMem;
  456. pMem++;
  457. if (Flags == STRING_FLAG_UNICODE)
  458. {
  459. dprintf("SERVER : %S\n",pMem);
  460. pMem+=(1+2*lstrlenWunal((WCHAR UNALIGNED *)pMem));
  461. }
  462. else
  463. {
  464. dprintf("SERVER : %s\n",pMem);
  465. pMem+=(1+lstrlenA((CHAR *)pMem));
  466. }
  467. Flags = *pMem;
  468. pMem++;
  469. if (Flags == STRING_FLAG_UNICODE)
  470. {
  471. dprintf("namespace: %S\n",pMem);
  472. pMem+=(1+2*lstrlenWunal((WCHAR UNALIGNED *)pMem));
  473. }
  474. else
  475. {
  476. dprintf("NAMESPACE: %s\n",pMem);
  477. pMem+=(1+lstrlenA((CHAR *)pMem));
  478. }
  479. };
  480. ClassPartLength = *((DWORD UNALIGNED *)pMem);
  481. pMem += sizeof(DWORD);
  482. BYTE Unused = *pMem;
  483. pMem++;
  484. DWORD HeapPtrName = *((DWORD UNALIGNED *)pMem);
  485. pMem += sizeof(DWORD);
  486. DWORD NullDefaultSize = *((DWORD UNALIGNED *)pMem);
  487. pMem += sizeof(DWORD);
  488. DWORD DerivationSize = *((DWORD UNALIGNED *)pMem);
  489. DerivationSize &= 0xFFFF;
  490. //dprintf("D %08x\n",DerivationSize);
  491. DWORD QualSetSize = *((DWORD UNALIGNED *)(pMem+DerivationSize));
  492. //dprintf("Q %08x\n",QualSetSize);
  493. QualSetSize &= 0xFFFF;
  494. DWORD NumProps = *((DWORD UNALIGNED *)(pMem+DerivationSize+QualSetSize));
  495. DWORD UNALIGNED * pPropLookup = (DWORD UNALIGNED *)(pMem+DerivationSize+QualSetSize+sizeof(DWORD));
  496. BYTE * pPropLookup_OOP = (BYTE *)Addr + (pMem - pMemOrg) + DerivationSize+QualSetSize;
  497. BYTE * HeapPtr = pMem + DerivationSize + QualSetSize + sizeof(DWORD) + NumProps*(2*sizeof(DWORD)) + NullDefaultSize;
  498. BYTE * HeapPtr_OOP = (BYTE *)Addr + (pMem - pMemOrg) + DerivationSize + QualSetSize + sizeof(DWORD) + NumProps*(2*sizeof(DWORD)) + NullDefaultSize;
  499. //dprintf("CPLen %p N %p D %p Q %p Prop %p Heap %p\n",
  500. // ClassPartLength,
  501. // NullDefaultSize,
  502. // DerivationSize,QualSetSize,NumProps,*((DWORD UNALIGNED *)HeapPtr));
  503. dprintf(" class_and_method\n");
  504. dprintf(" class_Part\n");
  505. if (0xFFFFFFFF != HeapPtrName)
  506. {
  507. BYTE * pName = HeapPtr + sizeof(DWORD) + HeapPtrName;
  508. Flags = *pName;
  509. pName++;
  510. if (Flags == STRING_FLAG_UNICODE)
  511. {
  512. dprintf(" class : %S\n",pName);
  513. }
  514. else
  515. {
  516. dprintf(" class : %s\n",pName);
  517. }
  518. }
  519. else
  520. {
  521. dprintf(" class : %08x\n",HeapPtrName);
  522. }
  523. // QualSet
  524. dprintf(" qualifierset %p\n",Addr+(pMem + DerivationSize - pMemOrg));
  525. ULONG_PTR pEndQualSet = (ULONG_PTR)pMem + DerivationSize + QualSetSize;
  526. BYTE * pQualSet = pMem + DerivationSize + sizeof(DWORD);
  527. //dprintf(" %p %p\n",pQualSet,pEndQualSet);
  528. while((ULONG_PTR)pQualSet < pEndQualSet)
  529. {
  530. DWORD dwHeapPtr = (*((DWORD UNALIGNED *)pQualSet));
  531. pQualSet += sizeof(DWORD);
  532. BYTE Flavor = *pQualSet;
  533. pQualSet += sizeof(BYTE);
  534. DWORD Type = (*((DWORD UNALIGNED *)pQualSet));
  535. pQualSet += sizeof(DWORD);
  536. BYTE * pData = pQualSet;
  537. pQualSet += g_ValLengths[Type&0x7F];
  538. if (dwHeapPtr & 0x80000000)
  539. {
  540. dprintf(" %s %02x %08x %p\n",g_QualStrings[dwHeapPtr&0x7fffffff],Flavor,Type,*(DWORD UNALIGNED *)pData);
  541. }
  542. else
  543. {
  544. dprintf(" %s %02x %08x %p\n",HeapPtr+dwHeapPtr+1+sizeof(DWORD),Flavor,Type,*(DWORD UNALIGNED *)pData);
  545. }
  546. if (CheckControlC())
  547. break;
  548. }
  549. // property lookup table
  550. dprintf(" propertylookup %p\n",pPropLookup_OOP);
  551. for (i=0;i<NumProps;i++)
  552. {
  553. WORD UNALIGNED * pPropInfo = (WORD UNALIGNED *)(HeapPtr+sizeof(DWORD)+pPropLookup[1]);
  554. dprintf(" %08x %08x %s %08x %04x %08x %08x\n",
  555. pPropLookup[0],pPropLookup[1],
  556. HeapPtr+pPropLookup[0]+1+sizeof(DWORD),
  557. *((DWORD UNALIGNED *)pPropInfo),
  558. *(pPropInfo+2),
  559. *(DWORD UNALIGNED *)(pPropInfo+3),
  560. *(DWORD UNALIGNED *)(pPropInfo+5));
  561. pPropLookup += 2;
  562. }
  563. DWORD dwHeapSize_ClassPart = (*((DWORD UNALIGNED *)HeapPtr))&0x7FFFFFFF;
  564. dprintf(" Heap %p size %08x\n",HeapPtr_OOP,dwHeapSize_ClassPart);
  565. dprintf(" method_Part\n");
  566. BYTE * pMethodPart = HeapPtr + sizeof(DWORD) + dwHeapSize_ClassPart;
  567. BYTE * pMethodPart_OOP = HeapPtr_OOP + sizeof(DWORD) + dwHeapSize_ClassPart;
  568. DWORD dwSizeMethodPart = *((DWORD UNALIGNED *)pMethodPart);
  569. DWORD NumMethods = *((DWORD UNALIGNED *)(pMethodPart+sizeof(DWORD)));
  570. BYTE * pMethodDescription= pMethodPart + 2*sizeof(DWORD);
  571. BYTE * pMethodDescription_OOP = pMethodPart_OOP + 2*sizeof(DWORD);
  572. //BYTE * pHeapMethod_OOP = ;
  573. dprintf(" num_methods : %08x\n",NumMethods);
  574. dprintf(" methods_descr : %p\n",pMethodDescription_OOP);
  575. //dprintf(" heap : %p\n");
  576. BYTE * pCombinedPart = pMethodPart + dwSizeMethodPart;
  577. BYTE * pCombinedPart_OOP = pMethodPart_OOP + dwSizeMethodPart;
  578. if (IsInstance)
  579. {
  580. dprintf(" instance\n");
  581. DWORD dwHeapSize = 4 + (*((DWORD UNALIGNED *)HeapPtr)) & 0x7fffffff;
  582. //BYTE * HeapPtr_OOP
  583. BYTE * pInstancePart = HeapPtr+dwHeapSize;
  584. BYTE * pInstancePart_OOP = HeapPtr_OOP+dwHeapSize;
  585. DWORD dwSize = *((DWORD UNALIGNED *)pInstancePart);
  586. pInstancePart += sizeof(DWORD);
  587. BYTE IFlag = *pInstancePart;
  588. pInstancePart++;
  589. DWORD dwClassNameOffset = *((DWORD UNALIGNED *)pInstancePart);
  590. pInstancePart += sizeof(DWORD);
  591. BYTE * pDataTable = pInstancePart;
  592. BYTE * pDataTable_OOP = pInstancePart_OOP + 2*sizeof(DWORD) + sizeof(BYTE);
  593. DWORD NumBytedNullNess = ((NumProps*2)%8)?(1+((NumProps*2)/8)):((NumProps*2)/8);
  594. BYTE * pDataTableData = pInstancePart + NumBytedNullNess;
  595. BYTE * pDataTableData_OOP = pDataTable_OOP + NumBytedNullNess;
  596. pInstancePart += NullDefaultSize; // this is crucial
  597. BYTE * pQualSet = pInstancePart;
  598. BYTE * pQualSet_OOP = pDataTable_OOP + NullDefaultSize;
  599. DWORD dwQualSetSize = *((DWORD UNALIGNED *)pQualSet);
  600. pInstancePart += dwQualSetSize;
  601. BYTE * pQualSetList = pInstancePart;
  602. BYTE * pInstanceHeap;
  603. BYTE * pInstanceHeap_OOP;
  604. if (0x01 == *pQualSetList)
  605. {
  606. // empty qual set OK
  607. pInstancePart++;
  608. pInstanceHeap = pInstancePart;
  609. pInstanceHeap_OOP = pQualSet_OOP+dwQualSetSize+sizeof(BYTE);
  610. }
  611. else if (0x02 == *pQualSetList)
  612. {
  613. // multiple qualifier set
  614. dprintf("unimplemented");
  615. return;
  616. }
  617. else
  618. {
  619. // invalid qualset
  620. }
  621. //NullDefaultSize
  622. dprintf(" begin %p\n",pInstancePart_OOP);
  623. dprintf(" data_table: null %p data %p\n",pDataTable_OOP,pDataTableData_OOP);
  624. dprintf(" qual_set %p\n",pQualSet_OOP);
  625. dprintf(" heap %p\n",pInstanceHeap_OOP);
  626. }
  627. else
  628. {
  629. dprintf(" class_and_method\n");
  630. dprintf(" start : %p\n",pCombinedPart_OOP);
  631. }
  632. }
  633. DECLARE_API(blob)
  634. {
  635. INIT_API();
  636. char * pArgs = (char *)_alloca(strlen(args)+1);
  637. lstrcpy(pArgs,args);
  638. ULONG_PTR pByte = 0;
  639. ULONG_PTR Size = 0;
  640. while (isspace(*pArgs)) pArgs++;
  641. char * pAddress = pArgs;
  642. // skip good chars
  643. while(!isspace(*pArgs)) pArgs++;
  644. if(*pArgs) // if there are more chars
  645. {
  646. *pArgs = 0; //terminate string
  647. pArgs++;
  648. // skip spaces
  649. while(isspace(*pArgs)) pArgs++;
  650. Size = GetExpression(pArgs);
  651. }
  652. pByte = GetExpression(pAddress);
  653. if (pByte)
  654. {
  655. if (Size)
  656. {
  657. BYTE * pHereMem = (BYTE *)HeapAlloc(GetProcessHeap(),0,Size*2);
  658. ReadMemory(pByte,pHereMem,Size*2,0); // to be safe on the size
  659. //dprintf(" object @ %p size %x\n",pByte,Size);
  660. ParseBlob(pHereMem,pByte);
  661. HeapFree(GetProcessHeap(),0,pHereMem);
  662. }
  663. else
  664. {
  665. HEAP_ENTRY HeapEntry;
  666. ReadMemory(pByte-(sizeof(HEAP_ENTRY)),&HeapEntry,sizeof(HEAP_ENTRY),0);
  667. Size = HeapEntry.Size*sizeof(HEAP_ENTRY);
  668. BYTE * pHereMem = (BYTE *)HeapAlloc(GetProcessHeap(),0,Size);
  669. ReadMemory(pByte,pHereMem,Size,0);
  670. ParseBlob(pHereMem,pByte);
  671. HeapFree(GetProcessHeap(),0,pHereMem);
  672. }
  673. }
  674. }
  675. DECLARE_API(datap)
  676. {
  677. INIT_API();
  678. ULONG_PTR Addr = GetExpression(args);
  679. if (Addr)
  680. {
  681. DWORD dwSize = 256; // and let's hope
  682. //sizeof(WBEM_DATAPACKET_HEADER) +
  683. //sizeof(WBEM_DATAPACKET_SMARTENUM_NEXT) +
  684. //sizeof(WBEM_DATAPACKET_OBJECT_ARRAY) +
  685. //sizeof(WBEM_DATAPACKET_OBJECT_HEADER);
  686. WBEM_DATAPACKET_HEADER * pData = (WBEM_DATAPACKET_HEADER *)_alloca(dwSize);
  687. if (ReadMemory(Addr,pData,dwSize,NULL))
  688. {
  689. dprintf(" Order %08x\n",pData->dwByteOrdering);
  690. dprintf(" Header %08x DSize %08x Flags %08x %02x ",
  691. pData->dwSizeOfHeader,
  692. pData->dwDataSize,
  693. pData->dwFlags,
  694. pData->bVersion);
  695. switch(pData->bPacketType)
  696. {
  697. case WBEM_DATAPACKETTYPE_OBJECTSINK_INDICATE:
  698. {
  699. dprintf("WBEM_DATAPACKETTYPE_OBJECTSINK_INDICATE\n");
  700. WBEM_DATAPACKET_OBJECTSINK_INDICATE UNALIGNED * pIndicate = (WBEM_DATAPACKET_OBJECTSINK_INDICATE UNALIGNED *)((BYTE *)pData + pData->dwSizeOfHeader);
  701. dprintf(" Header %08x Size %08x\n",pIndicate->dwSizeOfHeader,pIndicate->dwDataSize);
  702. WBEM_DATAPACKET_OBJECT_ARRAY UNALIGNED * pArrayPacket = (WBEM_DATAPACKET_OBJECT_ARRAY UNALIGNED *)((BYTE * )pIndicate+pIndicate->dwSizeOfHeader);
  703. dprintf(" Header %08x Size %08x NumObj %08x\n",
  704. pArrayPacket->dwSizeOfHeader,
  705. pArrayPacket->dwDataSize,
  706. pArrayPacket->dwNumObjects);
  707. WBEM_DATAPACKET_OBJECT_HEADER UNALIGNED * pObjHeader = (WBEM_DATAPACKET_OBJECT_HEADER UNALIGNED *)((BYTE*)pArrayPacket+pArrayPacket->dwSizeOfHeader);
  708. dprintf(" Header %08x dwSizeOfData %08x bObjectType ",pObjHeader->dwSizeOfHeader,pObjHeader->dwSizeOfData);
  709. switch(pObjHeader->bObjectType)
  710. {
  711. case WBEMOBJECT_NONE:
  712. dprintf("WBEMOBJECT_NONE\n");
  713. break;
  714. case WBEMOBJECT_CLASS_FULL:
  715. dprintf("WBEMOBJECT_CLASS_FULL\n");
  716. break;
  717. case WBEMOBJECT_INSTANCE_FULL:
  718. dprintf("WBEMOBJECT_INSTANCE_FULL\n");
  719. break;
  720. case WBEMOBJECT_INSTANCE_NOCLASS:
  721. dprintf("WBEMOBJECT_INSTANCE_NOCLASS\n");
  722. break;
  723. };
  724. dprintf(" data: %p\n",Addr+pData->dwSizeOfHeader+pIndicate->dwSizeOfHeader+pArrayPacket->dwSizeOfHeader+pObjHeader->dwSizeOfHeader);
  725. }
  726. break;
  727. case WBEM_DATAPACKETTYPE_SMARTENUM_NEXT:
  728. {
  729. dprintf("WBEM_DATAPACKETTYPE_SMARTENUM_NEXT\n");
  730. WBEM_DATAPACKET_SMARTENUM_NEXT UNALIGNED * pSNext = (WBEM_DATAPACKET_SMARTENUM_NEXT UNALIGNED *)((BYTE *)pData + pData->dwSizeOfHeader);
  731. dprintf(" Header %08x dwDataSize %08x\n",pSNext->dwSizeOfHeader,pSNext->dwDataSize);
  732. WBEM_DATAPACKET_OBJECT_ARRAY UNALIGNED * pArrayPacket = (WBEM_DATAPACKET_OBJECT_ARRAY UNALIGNED *)((BYTE * )pSNext+pSNext->dwSizeOfHeader);
  733. dprintf(" Header %08x Size %08x NumObj %08x\n",
  734. pArrayPacket->dwSizeOfHeader,
  735. pArrayPacket->dwDataSize,
  736. pArrayPacket->dwNumObjects);
  737. WBEM_DATAPACKET_OBJECT_HEADER UNALIGNED * pObjHeader = (WBEM_DATAPACKET_OBJECT_HEADER UNALIGNED *)((BYTE*)pArrayPacket+pArrayPacket->dwSizeOfHeader);
  738. dprintf(" Header %08x dwSizeOfData %08x bObjectType ",pObjHeader->dwSizeOfHeader,pObjHeader->dwSizeOfData);
  739. switch(pObjHeader->bObjectType)
  740. {
  741. case WBEMOBJECT_NONE:
  742. dprintf("WBEMOBJECT_NONE\n");
  743. break;
  744. case WBEMOBJECT_CLASS_FULL:
  745. dprintf("WBEMOBJECT_CLASS_FULL\n");
  746. break;
  747. case WBEMOBJECT_INSTANCE_FULL:
  748. dprintf("WBEMOBJECT_INSTANCE_FULL\n");
  749. break;
  750. case WBEMOBJECT_INSTANCE_NOCLASS:
  751. dprintf("WBEMOBJECT_INSTANCE_NOCLASS\n");
  752. break;
  753. };
  754. dprintf(" data: %p\n",Addr+pData->dwSizeOfHeader+pSNext->dwSizeOfHeader+pArrayPacket->dwSizeOfHeader+pObjHeader->dwSizeOfHeader);
  755. }
  756. break;
  757. case WBEM_DATAPACKETTYPE_UNBOUNDSINK_INDICATE:
  758. {
  759. dprintf("WBEM_DATAPACKETTYPE_UNBOUNDSINK_INDICATE\n");
  760. WBEM_DATAPACKET_UNBOUNDSINK_INDICATE UNALIGNED * pUnBoundI = (WBEM_DATAPACKET_UNBOUNDSINK_INDICATE UNALIGNED *)((BYTE *)pData + pData->dwSizeOfHeader);
  761. dprintf(" Header %08x dwDataSize %08x dwLogicalConsumerSize %08x\n",pUnBoundI->dwSizeOfHeader,pUnBoundI->dwDataSize,pUnBoundI->dwLogicalConsumerSize);
  762. }
  763. break;
  764. case WBEM_DATAPACKETTYPE_MULTITARGET_DELIVEREVENT:
  765. dprintf("WBEM_DATAPACKETTYPE_MULTITARGET_DELIVEREVENT\n");
  766. break;
  767. case WBEM_DATAPACKETTYPE_LAST:
  768. dprintf("WBEM_DATAPACKETTYPE_LAST\n");
  769. break;
  770. }
  771. }
  772. else
  773. {
  774. dprintf("RM %p\n",Addr);
  775. }
  776. }
  777. else
  778. {
  779. dprintf("unable to resolve %s\n",args);
  780. }
  781. }