lief-project / LIEF

LIEF - Library to Instrument Executable Formats
https://lief.re
Apache License 2.0
4.43k stars 620 forks source link

use add_libray build fail? #1075

Closed dyq741 closed 2 months ago

dyq741 commented 2 months ago

When using LIEF to modify ELF format files, I successfully added another sample library using the add_library function. However, after using build or directly write, the resulting new file does not contain this library. Why is that?

    random_library = random.choice(benign_libraries)
    print(random_library)
    print(target_binary.libraries)
    lowerlibname = random_library.lower()
    lib = None
    for im in target_binary.libraries:
        if im == lowerlibname:
            lib = im
            break
    if lib is None:
        # add a new library
        target_binary.add_library(random_library)
    print(target_binary.libraries)

    builder = lief.ELF.Builder(target_binary)
    builder.build() # perform the build process

    # return bytestring
    return array.array('B', builder.get_build()).tobytes()

version: 0.12.3 and 0.14.1

romainthomas commented 2 months ago

Hi! I can reproduce the issue and I think you code is not correct. Please double your code and feel free to re-open the issue if you confirm the bug