Skip to content

Commit

Permalink
MachO unwind fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sevaa committed Sep 1, 2024
1 parent 760a3de commit dbf0830
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dwex/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .frames import FramesDlg

# Sync with version in setup.py
version = (4, 10)
version = (4, 11)

# TODO:
# On MacOS, start without a main window, instead show the Open dialog
Expand Down
29 changes: 27 additions & 2 deletions dwex/patch.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import os
from struct import Struct
from ctypes import c_ubyte, sizeof
from types import MethodType
from io import BytesIO

import elftools.dwarf.enums
import elftools.dwarf.dwarf_expr
import elftools.dwarf.locationlists
import elftools.elf.elffile
import elftools.dwarf.dwarfinfo
import filebytes.mach_o
import filebytes.pe
from elftools.common.utils import struct_parse
from elftools.common.exceptions import DWARFError
Expand All @@ -14,8 +18,7 @@
from elftools.elf.relocation import RelocationHandler
from elftools.dwarf.locationlists import LocationLists, LocationListsPair
from elftools.construct.core import StaticField
from types import MethodType
from io import BytesIO
from filebytes.mach_o import LSB_64_Section, MH, SectionData

# Good reference on DWARF extensions here:
# https://sourceware.org/elfutils/DwarfExtensions
Expand Down Expand Up @@ -209,3 +212,25 @@ def _create_structs(self):

# Short out import directory parsing for now
filebytes.pe.PE._parseDataDirectory = lambda self,a,b,c: None

# Expand the logic in DSYM bundle loading to load the unwind sections too
def __parseSections(self, data, segment, offset):
sections = []
for i in range(segment.nsects):
sec = self._classes.Section.from_buffer(data, offset)
if self._classes.Section == LSB_64_Section:
offset += 80
else:
offset += sizeof(self._classes.Section)

if sec.offset > 0:
raw = (c_ubyte * sec.size).from_buffer(data, sec.offset)
bytes = bytearray(raw)
else:
raw = None
bytes = None
sections.append(SectionData(header=sec, name=sec.sectname.decode('ASCII'), bytes=bytes, raw=raw))

return sections

filebytes.mach_o.MachO._MachO__parseSections = __parseSections
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def run(self):

setup(
name='dwex',
version='4.10', # Sync with version in __main__
version='4.11', # Sync with version in __main__
packages=['dwex'],
url="https://github.com/sevaa/dwex/",
entry_points={"gui_scripts": ["dwex = dwex.__main__:main"]},
Expand Down

0 comments on commit dbf0830

Please sign in to comment.