Skip to content

Commit

Permalink
Compatibility with lief 0.15.0 (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
sledgeh4w authored Jul 21, 2024
1 parent 92d3c53 commit e93d6ca
Showing 1 changed file with 35 additions and 36 deletions.
71 changes: 35 additions & 36 deletions src/chomper/os/ios/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Dict, List, Tuple, Optional

import lief
from lief.MachO import BIND_TYPES, ARM64_RELOCATION
from lief.MachO import ARM64_RELOCATION

from chomper.base import BaseLoader
from chomper.types import Module, Symbol, Binding
Expand Down Expand Up @@ -118,50 +118,49 @@ def _process_symbol_relocation(
lazy_bindings = []

for binding in binary.dyld_info.bindings:
if binding.binding_type == BIND_TYPES.POINTER:
symbol = binding.symbol
symbol_name = str(symbol.name)
symbol = binding.symbol
symbol_name = str(symbol.name)

reloc_addr = self._get_symbol_reloc_addr(symbol_map, symbol_name)
reloc_addr = self._get_symbol_reloc_addr(symbol_map, symbol_name)

if not reloc_addr:
lazy_binding = Binding(
symbol=symbol_name,
address=binding.address,
addend=binding.addend,
)
lazy_bindings.append(lazy_binding)
if not reloc_addr:
lazy_binding = Binding(
symbol=symbol_name,
address=binding.address,
addend=binding.addend,
)
lazy_bindings.append(lazy_binding)

# Hook imports
if self.emu.hooks.get(symbol_name):
if not hooks_map.get(symbol_name):
reloc_addr = self.emu.create_buffer(self.emu.arch.addr_size)
hooks_map[symbol_name] = reloc_addr
# Hook imports
if self.emu.hooks.get(symbol_name):
if not hooks_map.get(symbol_name):
reloc_addr = self.emu.create_buffer(self.emu.arch.addr_size)
hooks_map[symbol_name] = reloc_addr

self.emu.add_interceptor(
reloc_addr, self.emu.hooks[symbol_name]
)
self.emu.add_interceptor(
reloc_addr, self.emu.hooks[symbol_name]
)

else:
reloc_addr = hooks_map[symbol_name]
else:
reloc_addr = hooks_map[symbol_name]

self.emu.logger.info(
'Hook import symbol "{}" at 0x{:x}'.format(
symbol_name, symbol.binding_info.address
)
self.emu.logger.info(
'Hook import symbol "{}" at 0x{:x}'.format(
symbol_name, symbol.binding_info.address
)
)

else:
# self.emu.add_hook(
# reloc_addr,
# self._missing_symbol_required_callback,
# user_data={"symbol_name": symbol.name},
# )
continue
else:
# self.emu.add_hook(
# reloc_addr,
# self._missing_symbol_required_callback,
# user_data={"symbol_name": symbol.name},
# )
continue

if reloc_addr:
value = (reloc_addr + binding.addend) & 0xFFFFFFFFFFFFFFFF
self.emu.write_pointer(module_base + binding.address, value)
if reloc_addr:
value = (reloc_addr + binding.addend) & 0xFFFFFFFFFFFFFFFF
self.emu.write_pointer(module_base + binding.address, value)

return lazy_bindings

Expand Down

0 comments on commit e93d6ca

Please sign in to comment.