Ответ 1
Вы можете использовать команду memory write {address}
lldb, чтобы перезаписать память и изменить значение строки. Мне удалось сделать это по одному адресу за раз, но похоже, что memory write
способен сделать это один раз.
(lldb) help memory write
Write to the memory of the process being debugged.
Syntax: memory write <cmd-options> <address> <value> [<value> [...]]
Command Options Usage:
memory write [-f <format>] [-s <byte-size>] <address> <value> [<value> [...]]
memory write -i <filename> [-s <byte-size>] [-o <offset>] <address> <value> [<value> [...]]
-f <format> ( --format <format> )
Specify a format to be used for display.
-i <filename> ( --infile <filename> )
Write memory using the contents of a file.
-o <offset> ( --offset <offset> )
Start writing bytes from an offset within the input file.
-s <byte-size> ( --size <byte-size> )
The size in bytes to use when displaying with the selected format.
This command takes options and free-form arguments. If your arguments
resemble option specifiers (i.e., they start with a - or --), you must use
' -- ' between the end of the command options and the beginning of the
arguments.
Вот пример (надеюсь, кто-то с большим пониманием lldb и внутренних компонентов Swift может обеспечить лучший метод):
Это показывает перезапись памяти по одному байту за раз. po "Tom".dataUsingEncoding(NSUTF8StringEncoding)!
получает шестнадцатеричное представление, которое используется для перехода и перезаписывания памяти object.name. Я уверен, что есть более простой способ сделать это (в одной команде), но я не мог понять правильные значения параметров, чтобы отключить его.