LIEF icon indicating copy to clipboard operation
LIEF copied to clipboard

Section address incorrect when adding inside DATA / DATA_CONST

Open AeonLucid opened this issue 2 years ago • 1 comments

Describe the bug The section is not placed correctly when adding a section inside __DATA or __DATA_CONST.

To Reproduce

data_segment = binary.get_segment('__DATA_CONST')

data_section = lief.MachO.Section("__lief_ptr")
data_section.alignment = 3
data_section.content = [0xFF] * 0x100
data_section.reserved1 = 19
data_section.type = lief.MachO.SECTION_TYPES.NON_LAZY_SYMBOL_POINTERS
data_section = binary.add_section(data_segment, data_section)

print(binary)

Expected behavior A clear and concise description of what you expected to happen.
In the case of this example, I would expect the section to be somewhere after 0x1000080a0 + 0x8 (the previous section).

Environment:

  • System and Version : Windows 10
  • Target format Mach-O
  • LIEF commit version: 0.12.0-717e4e9

Additional context

Command : SEGMENT_64
Offset  : 330
Size    : 228
__DATA_CONST   100008000      4000           8000           4000           3              3              6              10             
Sections in this segment :
	__got            __DATA_CONST     100008000 8         8000      3         NON_LAZY_SYMBOL_POINTERS      0                   0                   13        0         0                   
	__cfstring       __DATA_CONST     100008008 60        8008      3         REGULAR                       0                   0                   0         0         0                   
	__objc_classlist __DATA_CONST     100008068 18        8068      3         REGULAR                       0                   0                   0         0         0         NO_DEAD_STRIP
	__objc_protolist __DATA_CONST     100008080 20        8080      3         REGULAR                       0                   0                   0         0         0                   
	__objc_imageinfo __DATA_CONST     1000080a0 8         80a0      2         REGULAR                       0                   0                   0         0         0                   
	__lief_ptr       __DATA_CONST     10000d14c 100       514c      3         NON_LAZY_SYMBOL_POINTERS      0                   0                   13        0         0

image

AeonLucid avatar Oct 03 '21 14:10 AeonLucid

Ack

romainthomas avatar Oct 07 '21 04:10 romainthomas