Skip to content

[Bug] Python api add_library is not working #1268

@KateWasHere001

Description

@KateWasHere001

Describe the bug
add_library is not working

To Reproduce
pip install lief==0.17.0

  1. Patch target so with python api
import lief

libnative = lief.parse("libsqlcipher.so")
libnative.add_library("libgadget32.so") # Injection!
libnative.write("libsqlcipher_patched.so")

  1. Check
    python ../src/api/python/examples/elf_reader.py -d libsqlcipher_patched.so

output:

== Information ==

Address base:                  0x0                           
Virtual size:                  0x618000                      
PIE:                           False                         
NX:                            False                         
== Dynamic entries ==

|Tag              | Value     | Info                |
|NEEDED           | 0x37c6    | libdl.so            |
|NEEDED           | 0x37cf    | liblog.so           |
|NEEDED           | 0x37d9    | libc.so             |
|NEEDED           | 0x37e1    | libm.so             |
|SONAME           | 0x381e    | libsqlcipher.so     |
|INIT_ARRAY       | 0x20a1a4  | 0xdc784             |
|INIT_ARRAYSZ     | 0x4       |                     |
|FINI_ARRAY       | 0x20a1a8  | 0x1f514, 0x1f500    |
|FINI_ARRAYSZ     | 0x8       |                     |
|HASH             | 0x158     |                     |
|GNU_HASH         | 0x1264    |                     |
|STRTAB           | 0x4288    |                     |
|SYMTAB           | 0x1f08    |                     |
|STRSZ            | 0x3833    |                     |
|SYMENT           | 0x10      |                     |
|PLTGOT           | 0x21e5f4  |                     |
|PLTRELSZ         | 0xb18     |                     |
|PLTREL           | 0x11      |                     |
|JMPREL           | 0x1d82c   |                     |
|REL              | 0x7f8c    |                     |
|RELSZ            | 0x158a0   |                     |
|RELENT           | 0x8       |                     |
|FLAGS            | 0x8       | BIND_NOW            |
|FLAGS_1          | 0x1       | NOW                 |
|VERNEED          | 0x7f2c    |                     |
|VERNEEDNUM       | 0x3       |                     |
|VERSYM           | 0x7abc    |                     |
|RELCOUNT         | 0x29ea    |                     |
|INIT             | 0x22652c  |                     |
  1. After patching, libgadget32.so is not in the list.

  2. Also tried lief==0.17.1, which cause random string.

== Information ==

Address base:                  0x0                           
Virtual size:                  0x618000                      
PIE:                           False                         
NX:                            False                         
== Dynamic entries ==

|Tag              | Value     | Info                |
|NEEDED           | 0x37c6    | jjd                 |
|NEEDED           | 0x37cf    | qlcipher22get_window_from_objectEP7_JNIEnvP8_jobject|
|NEEDED           | 0x37d9    | get_window_from_objectEP7_JNIEnvP8_jobject|
|NEEDED           | 0x37e1    | ow_from_objectEP7_JNIEnvP8_jobject|
|SONAME           | 0x381e    | w10initBufferEb     |
|INIT_ARRAY       | 0x20a1a4  |                     |
|INIT_ARRAYSZ     | 0x4       |                     |
|FINI_ARRAY       | 0x20a1a8  |                     |
|FINI_ARRAYSZ     | 0x8       |                     |
|HASH             | 0x158     |                     |
|GNU_HASH         | 0x1264    |                     |
|STRTAB           | 0x4288    |                     |
|SYMTAB           | 0x1f08    |                     |
|STRSZ            | 0x3833    |                     |
|SYMENT           | 0x10      |                     |
|PLTGOT           | 0x21e5f4  |                     |
|PLTRELSZ         | 0xb18     |                     |
|PLTREL           | 0x11      |                     |
|JMPREL           | 0x1d82c   |                     |
|REL              | 0x7f8c    |                     |
|RELSZ            | 0x158a0   |                     |
|RELENT           | 0x8       |                     |
|FLAGS            | 0x8       | BIND_NOW            |
|FLAGS_1          | 0x1       | NOW                 |
|VERNEED          | 0x7f2c    |                     |
|VERNEEDNUM       | 0x3       |                     |
|VERSYM           | 0x7abc    |                     |
|RELCOUNT         | 0x29ea    |                     |
|INIT             | 0x22652c  |                     |

Expected behavior
After patching, libgadget32.so should be in the list.

Environment (please complete the following information):

  • System and Version : [macOS]
  • Target format (ELF)
  • LIEF commit version: 0.17.0 and 0.17.1

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions