Skip to content

Commit da28ff1

Browse files
committed
Handle structs in property_map_info instead of asserting
Fixes mstange#10
1 parent 9b45887 commit da28ff1

File tree

1 file changed

+38
-34
lines changed

1 file changed

+38
-34
lines changed

‎etw-reader/src/etw_types.rs

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -163,43 +163,47 @@ impl TraceEventInfoRaw {
163163
+ (std::mem::size_of::<TraceEventInfo>() - std::mem::size_of::<EventPropertyInfo>());
164164

165165
let curr_prop = EventPropertyInfo::from(&self.info[curr_prop_offset..]);
166-
assert!((curr_prop.Flags.0 & PropertyStruct.0 == 0));
167-
unsafe {
168-
if curr_prop.Anonymous1.nonStructType.MapNameOffset != 0 {
169-
// build an empty event record that we can use to get the map info
170-
let mut event: Etw::EVENT_RECORD = std::mem::zeroed();
171-
event.EventHeader.ProviderId = self.provider_guid();
172-
173-
let mut buffer_size = 0;
174-
let map_name = PCWSTR(self.info[curr_prop.Anonymous1.nonStructType.MapNameOffset as usize..].as_ptr() as *mut u16);
175-
use windows::Win32::Foundation::ERROR_INSUFFICIENT_BUFFER;
176-
// println!("map_name {}", utils::parse_unk_size_null_utf16_string(&self.info[curr_prop.Anonymous1.nonStructType.MapNameOffset as usize..]));
177-
if Etw::TdhGetEventMapInformation(&event, map_name, None, &mut buffer_size) != ERROR_INSUFFICIENT_BUFFER.0 {
178-
panic!("expected this to fail");
179-
}
180-
181-
let mut buffer = vec![0; buffer_size as usize];
182-
if Etw::TdhGetEventMapInformation(&event, map_name, Some(buffer.as_mut_ptr() as *mut _), &mut buffer_size) != 0 {
183-
panic!();
184-
}
166+
if curr_prop.Flags.0 & PropertyStruct.0 == 0 {
167+
// This property is a struct so it has no map info
168+
return None;
169+
} else {
170+
unsafe {
171+
if curr_prop.Anonymous1.nonStructType.MapNameOffset != 0 {
172+
// build an empty event record that we can use to get the map info
173+
let mut event: Etw::EVENT_RECORD = std::mem::zeroed();
174+
event.EventHeader.ProviderId = self.provider_guid();
175+
176+
let mut buffer_size = 0;
177+
let map_name = PCWSTR(self.info[curr_prop.Anonymous1.nonStructType.MapNameOffset as usize..].as_ptr() as *mut u16);
178+
use windows::Win32::Foundation::ERROR_INSUFFICIENT_BUFFER;
179+
// println!("map_name {}", utils::parse_unk_size_null_utf16_string(&self.info[curr_prop.Anonymous1.nonStructType.MapNameOffset as usize..]));
180+
if Etw::TdhGetEventMapInformation(&event, map_name, None, &mut buffer_size) != ERROR_INSUFFICIENT_BUFFER.0 {
181+
panic!("expected this to fail");
182+
}
183+
184+
let mut buffer = vec![0; buffer_size as usize];
185+
if Etw::TdhGetEventMapInformation(&event, map_name, Some(buffer.as_mut_ptr() as *mut _), &mut buffer_size) != 0 {
186+
panic!();
187+
}
185188

186-
let map_info: &crate::Etw::EVENT_MAP_INFO = &*(buffer.as_ptr() as *const _);
187-
if map_info.Flag == crate::Etw::EVENTMAP_INFO_FLAG_MANIFEST_VALUEMAP || map_info.Flag == crate::Etw::EVENTMAP_INFO_FLAG_MANIFEST_BITMAP {
188-
let is_bitmap = map_info.Flag == crate::Etw::EVENTMAP_INFO_FLAG_MANIFEST_BITMAP;
189-
let mut map = crate::FastHashMap::default();
190-
assert!(map_info.Anonymous.MapEntryValueType == crate::Etw::EVENTMAP_ENTRY_VALUETYPE_ULONG);
191-
let entries = std::slice::from_raw_parts(map_info.MapEntryArray.as_ptr(), map_info.EntryCount as usize);
192-
for e in entries {
193-
let value = e.Anonymous.Value;
194-
let name = utils::parse_unk_size_null_utf16_string(&buffer[e.OutputOffset as usize..]);
195-
// println!("{} -> {:?}", value, name);
196-
map.insert(value, name);
189+
let map_info: &crate::Etw::EVENT_MAP_INFO = &*(buffer.as_ptr() as *const _);
190+
if map_info.Flag == crate::Etw::EVENTMAP_INFO_FLAG_MANIFEST_VALUEMAP || map_info.Flag == crate::Etw::EVENTMAP_INFO_FLAG_MANIFEST_BITMAP {
191+
let is_bitmap = map_info.Flag == crate::Etw::EVENTMAP_INFO_FLAG_MANIFEST_BITMAP;
192+
let mut map = crate::FastHashMap::default();
193+
assert!(map_info.Anonymous.MapEntryValueType == crate::Etw::EVENTMAP_ENTRY_VALUETYPE_ULONG);
194+
let entries = std::slice::from_raw_parts(map_info.MapEntryArray.as_ptr(), map_info.EntryCount as usize);
195+
for e in entries {
196+
let value = e.Anonymous.Value;
197+
let name = utils::parse_unk_size_null_utf16_string(&buffer[e.OutputOffset as usize..]);
198+
// println!("{} -> {:?}", value, name);
199+
map.insert(value, name);
200+
}
201+
return Some(Rc::new(PropertyMapInfo { is_bitmap, map }));
202+
} else {
203+
eprint!("unsupported map type {:?}", map_info.Flag);
197204
}
198-
return Some(Rc::new(PropertyMapInfo { is_bitmap, map }));
199-
} else {
200-
eprint!("unsupported map type {:?}", map_info.Flag);
201-
}
202205

206+
}
203207
}
204208
}
205209
return None;

0 commit comments

Comments
 (0)