Skip to content

Commit

Permalink
Don't hard fail on bad export info, other minor bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
0cyn committed Aug 4, 2024
1 parent fff766b commit 07c7e8f
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .legacy_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name = 'k2l',
version = "1.4.0",
version = "2.1.1",
description = 'Static MachO/ObjC Reverse Engineering Toolkit',
long_description = long_description,
long_description_content_type = 'text/markdown',
Expand Down
2 changes: 1 addition & 1 deletion dev_install.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
rm -rf dist/*
poetry build
python3 -m pip install $(ls dist/*.tar.gz | xargs)
python3 -m pip install $(ls dist/*.tar.gz | xargs) --break-system-packages
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "k2l"
version = "2.1.0"
version = "2.1.1"
description = "Static MachO/ObjC Reverse Engineering Toolkit"
authors = ["cynder <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion src/ktool/ktool.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def load_objc_metadata(image: Image) -> ObjCImage:
data_io.write(image.slice.file.read_bytes(0, image.slice.file.size))
data_io.seek(0)
for rebase in image.chained_fixups.rebases.items():
data_io.seek(image.vm.translate(rebase[0]) + image.slice.offset)
data_io.seek(image.vm.translate(rebase[0]))
data_io.write(rebase[1].to_bytes(8, 'little'))
data_io.seek(0)
image = load_image(data_io)
Expand Down
4 changes: 2 additions & 2 deletions src/ktool/ktool_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,11 @@ def symbols(args):

for addr, sym in image.import_table.items():
try:
import_symbols[sym.fullname] = symbol(hex(addr), sym.fullname,
import_symbols[hex(addr)] = symbol(hex(addr), sym.fullname,
image.linked_images[int(sym.ordinal) - 1].install_name,
sym.attr)
except IndexError:
import_symbols[sym.fullname] = symbol(hex(addr), sym.fullname,
import_symbols[hex(addr)] = symbol(hex(addr), sym.fullname,
"ordinal: " + str(int(sym.ordinal)), sym.attr)

table = Table()
Expand Down
13 changes: 12 additions & 1 deletion src/ktool/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from collections import namedtuple
from typing import List, Union, Dict

import ktool
from ktool_macho import (MH_FLAGS, MH_FILETYPE, LOAD_COMMAND, BINDING_OPCODE, LOAD_COMMAND_MAP,
BIND_SUBOPCODE_THREADED_SET_BIND_ORDINAL_TABLE_SIZE_ULEB, BIND_SUBOPCODE_THREADED_APPLY,
MH_MAGIC_64, CPUType, CPUSubTypeARM64, MH_MAGIC)
Expand Down Expand Up @@ -117,7 +118,11 @@ def _parse_load_commands(cls, image: Image, load_symtab=True, load_imports=True,

if load_exports:
log.info("Loading Export Trie")
image.export_trie = ExportTrie.from_image(image, cmd.export_off, cmd.export_size)
try:
image.export_trie = ExportTrie.from_image(image, cmd.export_off, cmd.export_size)
except Exception as e:
log.error(f'Error loading export trie: {e}')
image.export_trie = None

elif load_command == LOAD_COMMAND.FUNCTION_STARTS:
fs_start = cmd.dataoff
Expand Down Expand Up @@ -743,6 +748,12 @@ def _load_binding_info(self, table_start: int, table_size: int) -> List[record]:
cmd_start_addr = read_address
read_address += 1

# this is a strenuous calc to be running rn, so only do it if we HAVE TO
if log.LOG_LEVEL == ktool.LogLevel.DEBUG_TOO_MUCH:
segment = list(self.image.segments.values())[seg_index]
vm_address = segment.vm_address + seg_offset
log.debug_tm(f'@ {hex(cmd_start_addr)} (-> {hex(vm_address)}) op->{BINDING_OPCODE(binding_opcode).name} current->{name}')

if binding_opcode == BINDING_OPCODE.THREADED:
if value == BIND_SUBOPCODE_THREADED_SET_BIND_ORDINAL_TABLE_SIZE_ULEB:
a_table_size, read_address = self.image.read_uleb128(read_address)
Expand Down

0 comments on commit 07c7e8f

Please sign in to comment.