File: test.py

package info (click to toggle)
lief 0.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 16,036 kB
  • sloc: cpp: 76,013; python: 6,167; ansic: 3,355; pascal: 404; sh: 98; makefile: 32
file content (30 lines) | stat: -rw-r--r-- 970 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import lief

from lief import Logger
Logger.set_level(lief.LOGGING_LEVEL.DEBUG)
from lief.ELF import Section

ls   = lief.parse("/home/romain/dev/LIEF/lief-samples/ELF/ELF64_x86-64_binary_static-binary.bin")
stub = lief.parse("hello_lief.bin")

#section            = Section()
#section.name       = "test"
#section.type       = lief.ELF.SECTION_TYPES.PROGBITS
#section.content    = stub.segments[0].content # First LOAD segment which holds payload (bytes)
#section = ls.add(section, loaded=True)
#ls.header.entrypoint = section.virtual_address + stub.header.entrypoint
#
#ep = ls.header.entrypoint

for i in range(10):
    segment                 = stub.segments[0]
    original_va             = segment.virtual_address
    segment.virtual_address = 0
    segment                 = ls.add(segment)
    new_ep                  = (stub.header.entrypoint - original_va) + segment.virtual_address

    ls.header.entrypoint = new_ep

ls.write("lst.section")

#print(hex(ep))