goblin
goblin copied to clipboard
Change debug prints to show "strings" as strings
Right now some of the debug prints are hard to read because they spit out the byte arrays as arrays instead of something more byte readable. In particular this affects things like section names.
Should be easy for section names (iirc only segment is like that); just do name.pread::<&str>
and unwrap_or if the utf8 is bad
Yeah. Doesn't seem massive amounts of work. It also affects UUIDs. I will send a PR when I find some time for it.
@m4b, do you mean changing the unified SectionHeader's sh_name from u32 to string? In that case, if I convert ElfSectionHeader to SectionHeader the origin u32 is lost, and how can I change back SectionHeader to ElfSectionHeader?
No I believe we were talking about the mach-o segname/sectname, which are byte arrays of 16. Was suggesting just changing the debug print to unwrap or on them using a pread so it was printed better.
Sorry, @m4b, I don't have a Mac available. So perhaps I should probably withdraw. Thank you for your reply.
@xiongmao86 It's ok! I don't think you'd strictly need a mac to close this issue, primarily a matter of fixing byte arrays being printed when debug {:?}
is used, but appears also I was wrong, that segname
is already stringified, so i'm not sure what this issue is about so much anymore :)
https://github.com//m4b/goblin/blob/779d0ce835bb325327f39157ea8fdb8882daa171/src/mach/segment.rs#L126
@m4b, would it be Elf format perhaps? The name part of section header is an u32, a index of string table. It's possible to look it up and store the result string into a field, but in that way the string couldn't convert back.
https://github.com/m4b/goblin/blob/eb7e5f449d35aea0eb77a3c6d418c6c8888094b1/src/elf/section_header.rs#L380-L382
No we want that; it's just for anything that has a byte array/slice, and we have a Debug
derive, and/or the byte array is debug printed; @mitsuhiko maybe the issue can be closed, haven't checked in a while?
Ok, thanks for replying.