Skip to content
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

Fixes issues with printing/serializing notes #301

Merged
merged 3 commits into from
Jun 8, 2019

Conversation

mackncheesiest
Copy link
Contributor

@mackncheesiest mackncheesiest commented Jun 7, 2019

Related issue:
#300

  • Adds ability to clone NoteDetails objects to fixe a potential segfault in LIEF::ELF::Note::dump
  • Adds the ability to write notes that are manually added by the user through lief.add(life.ELF.Note(...)) to resulting binary by fixing an alignment bug
  • Adds the ability to write NT_GNU_HWCAP and NT_UNKNOWN notes to resulting binary

Example that demonstrates updated functionality:

# mybin.bin only has a GNU ABI Tag note to begin with
mybin = lief.parse("mybin.bin")
mybin.add(lief.ELF.Note("GNU", lief.ELF.NOTE_TYPES.BUILD_ID, [0xb, 0xe, 0xe, 0xf]))
mybin.add(lief.ELF.Note("GNU", lief.ELF.NOTE_TYPES.HWCAP, [0, 0, 0, 0, 0, 0, 0, 0]))
mybin.add(lief.ELF.Note("CustomStr", lief.ELF.NOTE_TYPES.UNKNOWN, list(map(ord, "Str2"))))
print(mybin)
mybin.write("modified.bin")
modified = lief.parse("modified.bin")
print(modified)

Externally, readelf -n modified.bin also supports displaying the notes that are added

Subsequently, calling print(mybin) on an ELF binary that has a new note
added it no longer segfaults
@mackncheesiest mackncheesiest marked this pull request as ready for review June 7, 2019 17:30
@romainthomas
Copy link
Member

Thank you @mackncheesiest for the PR!
The copy implementation of note details is ok for me.

Adds support for serialization of hwcap and unknown notes through
Builder::build()

Gives unknown note types a default ".note" namespace rather than
potentially alias a ".note.unknown" type in the future
@mackncheesiest
Copy link
Contributor Author

Thanks @romainthomas !
I believe the other commits are finalized and able to be reviewed whenever you have the time.

@romainthomas romainthomas merged commit 9dd9ded into lief-project:master Jun 8, 2019
@romainthomas
Copy link
Member

Perfect!

romainthomas added a commit that referenced this pull request Jan 17, 2022
Fixes issues with printing/serializing notes
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.

None yet

2 participants