-
Notifications
You must be signed in to change notification settings - Fork 32
Open
Labels
Description
In the parser code:
def get_string(self):
"""Read a null-terminated string from macho."""
string = bytearray()
c = self.__file.read(1)
while c not in (b'\x00', ''):
string += c
c = self.__file.read(1)
return string.decode('utf-8', errors='replace')
This row:
while c not in (b'\x00', ''):
should change to:
while c not in (b'\x00', b''):
Otherwise it won't stop when reaching EOF
Also after you fix this you need to fix:
while current_location < true_offset + lc_symtab['strsize']:
try:
string = self.get_string()
if string != '':
self.__macho['strtab'].append(string)
except:
break
because the headers are invalid true_offset + lc_symtab['strsize']
is bigger then file size so it will never stop.
Maybe something like :
current_location = self._file.tell()
while current_location < true_offset + lc_symtab['strsize'] and current_location != self.file_size:
try:
string = self.get_string()
current_location = self._file.tell()
if string != '':
self.__macho['strtab'].append(string)
except:
break