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

Unable to add custom note to ELF binary #1026

Open
aeldidi opened this issue Feb 26, 2024 · 1 comment
Open

Unable to add custom note to ELF binary #1026

aeldidi opened this issue Feb 26, 2024 · 1 comment

Comments

@aeldidi
Copy link

aeldidi commented Feb 26, 2024

Describe the bug
LIEF cannot insert a note into a binary which is not of a predefined format. When trying to create the note, I get the error:

Can't determine the raw type of note 'UNKNOWN' for the owner 'Custom'
Traceback (most recent call last):
  File "/home/aeldidi/src/aeldidi/manifest/./tools/add_manifest.py", line 23, in <module>
    binary.add(manifest)
TypeError: add(): incompatible function arguments. The following argument types are supported:
    1. add(self, arg: lief._lief.ELF.DynamicEntry, /) -> lief._lief.ELF.DynamicEntry
    2. add(self, section: lief._lief.ELF.Section, loaded: bool = True) -> lief._lief.ELF.Section
    3. add(self, segment: lief._lief.ELF.Segment, base: int = 0) -> lief._lief.ELF.Segment
    4. add(self, note: lief._lief.ELF.Note) -> lief._lief.ELF.Note

Invoked with types: lief._lief.ELF.Binary, NoneType

To Reproduce

import lief
import sys

binary = lief.ELF.parse(sys.argv[1])
note = lief.ELF.Note.create(
    name="Custom",
    type=lief.ELF.Note.TYPE.UNKNOWN,
    description=list(
        map(
            ord,
            """
I passed through the seven levels of the Candy Cane forest,
through the sea of swirly twirly gum drops,
and then I walked through the Lincoln Tunnel.
""",
        )
    ),
)

binary.add(note)
binary.write(sys.argv[1] + ".edited")

Expected behavior
A copy of the binary specified by sys.argv[1] now contains the custom note.

Environment (please complete the following information):

  • System and Version : Ubuntu 22.04.3
  • Target format ELF
  • LIEF commit version: 0.14.1-bae887e0

Additional context
I'm playing around with adding a custom note to an ELF file which would contain some metadata about the program and wanted to try injecting this note into existing ELF files to test it out. The metadata is currently just unstructured and the format isn't set in stone so I want to just add a note with arbitrary text data.

This capability seemed to be added in #301, but doesn't work currently.

Also, manually specifying the type as original_type=0 doesn't work either and gives this error:

Note type: 0x0 is not supported for owner: 'Custom'
Note type: UNKNOWN ('Custom') is not supported

NOTICE

If the issue does not contain enough information to be reproduced,
it will be flagged as incomplete
and closed.

/NOTICE

@romainthomas
Copy link
Member

Indeed, it's a regression from the refactoring of the ELF Notes processing. I'll look for a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants