goblin icon indicating copy to clipboard operation
goblin copied to clipboard

Change debug prints to show "strings" as strings

Open mitsuhiko opened this issue 6 years ago • 9 comments

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.

mitsuhiko avatar Oct 11 '17 17:10 mitsuhiko

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

m4b avatar Oct 11 '17 17:10 m4b

Yeah. Doesn't seem massive amounts of work. It also affects UUIDs. I will send a PR when I find some time for it.

mitsuhiko avatar Oct 11 '17 18:10 mitsuhiko

@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?

xiongmao86 avatar May 25 '19 17:05 xiongmao86

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.

m4b avatar May 25 '19 19:05 m4b

Sorry, @m4b, I don't have a Mac available. So perhaps I should probably withdraw. Thank you for your reply.

xiongmao86 avatar May 26 '19 05:05 xiongmao86

@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 avatar May 26 '19 06:05 m4b

@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

xiongmao86 avatar May 26 '19 14:05 xiongmao86

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?

m4b avatar May 27 '19 19:05 m4b

Ok, thanks for replying.

xiongmao86 avatar May 29 '19 05:05 xiongmao86