Skip to content

PPC: Detect unpooled string literal references #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 17, 2025

Conversation

LagoLunatic
Copy link
Contributor

objdiff already supports detected pooled PPC strings (@stringBase), this PR adds support for unpooled ones as well:

image

It assumes that a data symbol is an unpooled string if it's at least 2 bytes long and it contains exactly 1 null byte at the end of the symbol. I didn't check that all the bytes are displayable ASCII characters because I didn't want to exclude non-ASCII strings. This might have false positives but I haven't run into any in testing yet.

// Numeric type.
return Some(ty);
}
if bytes.len() >= 2 && bytes.iter().position(|&c| c == b'\0') == Some(bytes.len() - 1) {
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
if bytes.len() >= 2 && bytes.iter().position(|&c| c == b'\0') == Some(bytes.len() - 1) {
if bytes.len() >= 2 && bytes.iter().position(|&c| c == b'\0') == bytes.last() {

I think this should work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

last would return the last byte in the slice, I think? This is comparing to the last index (len-1), not the value, since all the values were already read inside the loop.

The compiler also doesn't like last for some reason:

can't compare `std::option::Option<usize>` with `std::option::Option<&u8>`
the trait `PartialEq<std::option::Option<&u8>>` is not implemented for `std::option::Option<usize>`
but trait `PartialEq<deranged::OptionRangedUsize<_, _>>` is implemented for it
for that trait implementation, expected `deranged::OptionRangedUsize<_, _>`, found `std::option::Option<&u8>`

Copy link
Owner

Choose a reason for hiding this comment

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

I think my brain was melted by C++ iterators, nevermind

return Some(ty);
}
if bytes.len() >= 2 && bytes.iter().position(|&c| c == b'\0') == Some(bytes.len() - 1) {
// It may be an unpooled string if the symbol contains exactly one null byte at the end of the symbol.
Copy link
Owner

Choose a reason for hiding this comment

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

Doesn't have to be this PR, just thinking aloud, this logic could easily live in common arch code.

@encounter
Copy link
Owner

Thanks!

@encounter encounter merged commit fbf8563 into encounter:main Apr 17, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants