static object FormatValue(EtwPropertyInfo propertyInfo, object value) { if (propertyInfo.ValueMap != null) { var key = (uint)value; string name = null; if (!propertyInfo.ValueMap.TryGetValue(key, out name)) { name = value.ToString(); } return(name); } switch (propertyInfo.OutType) { case TdhOutType.SocketAddress: return(FormatAsIpAddress(value)); case TdhOutType.HexInt8: return("0x" + ((byte)value).ToString("X")); case TdhOutType.HexInt16: return("0x" + ((ushort)value).ToString("X")); case TdhOutType.HexInt32: return("0x" + ((uint)value).ToString("X")); case TdhOutType.HexInt64: return("0x" + ((ulong)value).ToString("X")); default: return(value); } }
/// <summary> /// This function copies the information from the native TRACE_EVENT_INFO structure /// to property information in this oject /// </summary> /// <param name="buffer">IntPtr to TRACE_EVENT_INFO structure</param> void CopyMetadata(IntPtr buffer, ref EtwNativeEvent e) { TRACE_EVENT_INFO *info = (TRACE_EVENT_INFO *)buffer; byte * start = (byte *)info; byte * end = start + sizeof(TRACE_EVENT_INFO); _template = new Dictionary <string, object>(); _template.Add("Provider", CopyString(start, info->ProviderNameOffset)); _template.Add("Level", CopyString(start, info->LevelNameOffset)); _template.Add("Task", CopyString(start, info->TaskNameOffset)); _template.Add("Opcode", CopyString(start, info->OpcodeNameOffset)); _template.Add("Channel", CopyString(start, info->ChannelNameOffset)); _formatString = TranslateFormatString(CopyString(start, info->EventMessageOffset)); EVENT_PROPERTY_INFO *prop = (EVENT_PROPERTY_INFO *)end; var propList = new List <EtwPropertyInfo>(); for (int i = 0; i < info->TopLevelPropertyCount; i++) { var propInfo = prop + i; var name = CopyString(start, propInfo->NameOffset); var type = (TdhInType)(*propInfo).NonStructTypeValue.InType; var outType = (TdhOutType)(*propInfo).NonStructTypeValue.OutType; EtwPropertyInfo property = null; if (propInfo->Flags == PROPERTY_FLAGS.PropertyParamLength) { string lenPropertyName = propList[(int)(propInfo->LengthPropertyIndex)].Name; property = new EtwPropertyInfo { Name = name, Type = type, OutType = outType, LengthPropertyName = lenPropertyName }; } else { ushort len = (*propInfo).LengthPropertyIndex; property = new EtwPropertyInfo { Name = name, Length = len, Type = type, OutType = outType }; } if (propInfo->NonStructTypeValue.MapNameOffset > 0) { string mapName = CopyString(start, propInfo->NonStructTypeValue.MapNameOffset); property.ValueMap = ReadTdhMap(mapName, ref e); } propList.Add(property); } _properties = propList.ToArray(); }