Say for instance I have a 32 element unsigned char array at address 0xdeadbeef. I would like to overwrite the contents of the array in memory. I am not compiled with -g, and so cannot just do a "set [variable name] = [my value]".
Is it possible to set the contents of the memory all at once?
I've seen someone try
set *((unsigned char*) 0xdeadbeef) = "abcdefghijklmnop", but this doesn't appear to work.
Alternatively, if it isn't possible (for instance, because how would gdb know to convert that to the hex ascii representation?), is it possible to give multiple bytes, words, etc all at once? For example, I could just calculate the value in hex that I want the array to represent, but can I feed it all at once? Something like:
set 0xdeadbeef = 0x4142434445464748495051
(Posting this just so the question has an "official" answer)
Carl's statements in the comments are entirely correct. You can do the following in gdb:
call strcpy(0xdeadbeef, "mystring")
This works for any of the functions included in the statically linked C library (memset, strncpy, etc).
There's alternative of writing char array in one command, without standard functions like
set *(char [CHAR_ARRAY_SIZE] *) <WRITE_ADDRESS> = "YOUR_CHAR_ARRAY"
CHAR_ARRAY_SIZE is the size of
YOUR_CHAR_ARRAY, plus extra NULL byte.
set *(char  *) 0x20018000 = "Write a string"
User contributions licensed under CC BY-SA 3.0