Better COFF String Detection and Big Endian Wide Strings by HaydnTrigg · Pull Request #321 · encounter/objdiff

Conversation

@HaydnTrigg

Detect the $SG prefix for strings.
Wide strings decode the full string buffer but trims excess null terminators instead of trying to decode the ascii buffer with the null terminators already taken out. Fixes issue with big endian wide strings not working properly.

Before:
image

After:
image

LagoLunatic

Comment on lines +193 to +196

// Inline loop to strip all trailing "\0"
while let Some(stripped) = string.strip_suffix('\0') {
string = stripped.to_string();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would something like

// Inline loop to strip all trailing "\0"
while let Some(stripped) = string.strip_suffix('\0') {
string = stripped.to_string();
}
string = string.trim_end_matches('\0');

still work here? Might be able to remove the while loop if it does.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me give it a go ¯_(ツ)_/¯ My ability to code Rust is comparable to a child learning to walk at the moment.

@encounter

Thanks for the fix, I ended up reworking the function further, hopefully it's more robust now.