|
1 | | -use anyhow::{anyhow, bail, Result}; |
| 1 | +use anyhow::{anyhow, Result}; |
2 | 2 |
|
3 | 3 | use crate::{ |
4 | 4 | analysis::{ |
@@ -272,21 +272,21 @@ fn apply_ctors_signatures(obj: &mut ObjInfo) -> Result<()> { |
272 | 272 | } |
273 | 273 |
|
274 | 274 | fn apply_dtors_signatures(obj: &mut ObjInfo) -> Result<()> { |
275 | | - let Some((_, symbol)) = obj.symbols.by_name("_dtors")? else { |
276 | | - for symbol in obj.symbols.iter() { |
277 | | - println!("{:?} {:#010X} {}", symbol.section, symbol.address, symbol.name); |
278 | | - } |
279 | | - bail!("Missing _dtors symbol"); |
280 | | - // return Ok(()); |
281 | | - }; |
282 | | - let dtors_section_index = |
283 | | - symbol.section.ok_or_else(|| anyhow!("Missing _dtors symbol section"))?; |
284 | | - let dtors_section = &obj.sections[dtors_section_index]; |
| 275 | + let (dtors_section_index, dtors_section) = |
| 276 | + if let Some((_, symbol)) = obj.symbols.by_name("_dtors")? { |
| 277 | + let section_index = |
| 278 | + symbol.section.ok_or_else(|| anyhow!("Missing _dtors symbol section"))?; |
| 279 | + (section_index, &obj.sections[section_index]) |
| 280 | + } else if let Some((section_index, section)) = obj.sections.by_name(".dtors")? { |
| 281 | + (section_index, section) |
| 282 | + } else { |
| 283 | + return Ok(()); |
| 284 | + }; |
285 | 285 | // __destroy_global_chain_reference + null pointer |
286 | 286 | if dtors_section.size < 8 { |
287 | 287 | return Ok(()); |
288 | 288 | } |
289 | | - let address = symbol.address; |
| 289 | + let address = dtors_section.address; |
290 | 290 | let dgc_target = read_address(obj, dtors_section, address as u32).ok(); |
291 | 291 | let fce_target = read_address(obj, dtors_section, address as u32 + 4).ok(); |
292 | 292 | let mut found_dgc = false; |
@@ -319,7 +319,7 @@ fn apply_dtors_signatures(obj: &mut ObjInfo) -> Result<()> { |
319 | 319 | )?; |
320 | 320 | found_dgc = true; |
321 | 321 | } else { |
322 | | - log::warn!("Failed to match __destroy_global_chain signature ({:#010X})", dgc_target); |
| 322 | + log::debug!("Failed to match __destroy_global_chain signature ({:#010X})", dgc_target); |
323 | 323 | } |
324 | 324 | } |
325 | 325 |
|
@@ -445,3 +445,40 @@ pub fn apply_signatures_post(obj: &mut ObjInfo) -> Result<()> { |
445 | 445 | } |
446 | 446 | Ok(()) |
447 | 447 | } |
| 448 | + |
| 449 | +/// Create _ctors and _dtors symbols if missing |
| 450 | +pub fn update_ctors_dtors(obj: &mut ObjInfo) -> Result<()> { |
| 451 | + if obj.symbols.by_name("_ctors")?.is_none() { |
| 452 | + if let Some((section_index, section)) = obj.sections.by_name(".ctors")? { |
| 453 | + obj.symbols.add_direct(ObjSymbol { |
| 454 | + name: "_ctors".to_string(), |
| 455 | + demangled_name: None, |
| 456 | + address: section.address, |
| 457 | + section: Some(section_index), |
| 458 | + size: 0, |
| 459 | + size_known: true, |
| 460 | + flags: ObjSymbolFlagSet(ObjSymbolFlags::Global.into()), |
| 461 | + kind: ObjSymbolKind::Unknown, |
| 462 | + align: None, |
| 463 | + data_kind: Default::default(), |
| 464 | + })?; |
| 465 | + } |
| 466 | + } |
| 467 | + if obj.symbols.by_name("_dtors")?.is_none() { |
| 468 | + if let Some((section_index, section)) = obj.sections.by_name(".dtors")? { |
| 469 | + obj.symbols.add_direct(ObjSymbol { |
| 470 | + name: "_dtors".to_string(), |
| 471 | + demangled_name: None, |
| 472 | + address: section.address, |
| 473 | + section: Some(section_index), |
| 474 | + size: 0, |
| 475 | + size_known: true, |
| 476 | + flags: ObjSymbolFlagSet(ObjSymbolFlags::Global.into()), |
| 477 | + kind: ObjSymbolKind::Unknown, |
| 478 | + align: None, |
| 479 | + data_kind: Default::default(), |
| 480 | + })?; |
| 481 | + } |
| 482 | + } |
| 483 | + Ok(()) |
| 484 | +} |
0 commit comments