From 0f20b45a49d772f6ea7a069c944279a61485826e Mon Sep 17 00:00:00 2001 From: Luke Street Date: Wed, 23 Aug 2023 09:57:38 -0400 Subject: [PATCH] Handle trailing underscores in function name --- Cargo.toml | 2 +- src/lib.rs | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 69826d7..5558126 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cwdemangle" -version = "0.1.5" +version = "0.1.6" edition = "2018" authors = ["Luke Street "] license = "MIT OR Apache-2.0" diff --git a/src/lib.rs b/src/lib.rs index efcd314..ec9bf84 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -324,7 +324,11 @@ pub fn demangle(mut str: &str, options: &DemangleOptions) -> Option { str = &str[2..]; } { - let idx = str.find("__")?; + let mut idx = str.find("__")?; + // Handle any trailing underscores in the function name + while str.chars().nth(idx + 2) == Some('_') { + idx += 1; + } let (fn_name_out, mut rest) = str.split_at(idx); if special { if fn_name_out == "init" { @@ -686,6 +690,10 @@ mod tests { ), Some("nw4r::ut::CharStrmReader::CharStrmReader(unsigned short (nw4r::ut::CharStrmReader::*)())".to_string()) ); + assert_eq!( + demangle("QuerySymbolToMapFile___Q24nw4r2dbFPUcPC12OSModuleInfoUlPUcUl", &options), + Some("nw4r::db::QuerySymbolToMapFile_(unsigned char*, const OSModuleInfo*, unsigned long, unsigned char*, unsigned long)".to_string()) + ); } #[test]