How to modify memory contents using LLDB?
Asked Answered
M

2

8

What is the equivalent lldb command to the one shown below in GDB?

(gdb) set {char}0x02ae4=0x12

The values are arbitrary examples. With GDB I was able to easily edit the byte code at a given hex address while looking at dumps in terminal. Since I upgraded to mavericks I have been trying to fiddle around with lldb a little more but I am having a tough time in a few areas. Perhaps it doesn't even possess this functionality yet..

Mithridatism answered 30/5, 2014 at 18:38 Comment(0)
D
17

According to lldb-basics guide LLDB alternative is memory write.

Also (lldb) help memory write defines such an input format:

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 writng 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.

So, in Your case, something like (lldb) memory write 0x02ae4 0x12 should just work.

Duplicate answered 30/5, 2014 at 19:7 Comment(1)
If you need to write more than one byte use the -s option: (lldb) memory write 0x02ae4 -s 2 0xFFFFUgh
N
5

memory write works, but you can also use the expression engine with a C expression like

p *(char*)0x2ae4 = 0x12
Nathalie answered 20/6, 2021 at 19:31 Comment(1)
I assume this example should use 0x12 to be equivalent to the question's example.French

© 2022 - 2024 — McMap. All rights reserved.