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
COFF stringtable created with 'strings' function truncates the first 4 characters when used with symbol offset #373
Comments
Hmmm, thank you for the detailed writeup! Can you paste the binary by any chance with your fibonnaci function? I'm a little surprised this wouldn't have come up earlier, but it is possibly a regression since I know a change went in recently with pe and string table |
Yes of course! Here is the source code if you want to compile it yourself (but the binary is also attached, see below): fn main() {
println!("Here are some fibonacci numbers");
println!("Fib 50: {}", fibonacci(50));
}
#[no_mangle]
fn fibonacci(n: u64) -> u64 {
println!("addr of fib: {:#?}", fibonacci as *const u8);
let mut a = 0;
let mut b = 1;
if n == 0 {
return 0;
}
for _ in 1..n {
let tmp = a + b;
a = b;
b = tmp;
}
b
} (The program was called hash-test, but I stripped it of any meaningful computation. All that is left is a main function that calls a fibonacci calculation) |
if you |
Sadly not, undoing the changes from the specified commit does not resolve the issue. I ran the code I provided again (ofc. with the changed version of goblin), and the results are still the same. The name is still offset by 4 characters. |
hmmm, if i run In your example code could you try using the |
I suspect you needed this portion: https://github.com//m4b/goblin/blob/17a5c7cc992220cd72e349eddea99148f31c5e65/src/pe/symbol.rs#L240 |
I needed to change your suggested fix a bit (since the unwrap() would not work in the current context. But this is no meaningful change): let strtab_offset = match sym.name_offset() {
Some(val) => val,
None => continue,
}; The Problem still persists when testing the "fixed" code with my local version of goblin (the one with I also checked how the code would behave with the current release of goblin Running in release seems to "fix" the issue for version
|
This is wrong because it will try to parse auxiliary symbols as regular symbols. Use
Agreed. |
Detailed Problem Description with Example
A symbol with a name longer than 8 characters, will be stored in the string table, as per the PE File Format Documentation given by Microsoft. The offset to the string table can then be determined by the last 4 bytes of the 8 byte long name field if the first 4 bytes are 0 (see SymbolNameRepresentation).
This does not seem to work correctly in goblin. Take a look at this example:
The provided PE file contains a function called "fibonacci". This can easily be confirmed with
objdump -t <file> | grep fibonacci
.However when executing the provided Rust code on the same file, the output will stem from the second case (name == "nacci"). Here is the exact output:
This is also the same entry that was previously found by objdump.
Short Problem Description
It seems, that the strtab parsed by the
strings
function on aCoffHeader
accidentally offsets every string by 4 characters.Expected Output
I would have expected to receive the full name with the provided Rust code. Not a truncated Version.
I hope that I didn't do anything wrong when parsing the necessary information...
Other Information:
goblin-version:
0.7.1
rustc-version and cargo-version:
1.70.0
OS:
Windows 11 Pro Version 22H2
The text was updated successfully, but these errors were encountered: