Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 667 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to modify memory contents using GDB?

#1
I know that we can use several commands to access and read memory: for example, print, p, x...

But how can I change the contents of memory at any specific location (while debugging in GDB)?
Reply

#2
As Nikolai has said you can use the gdb 'set' command to change the value of a variable.

You can also use the 'set' command to change memory locations.
eg. Expanding on Nikolai's example:

(gdb) l
6 {
7 int i;
8 struct file *f, *ftmp;
9
(gdb) set variable i = 10
(gdb) p i
$1 = 10

(gdb) p &i
$2 = (int *) 0xbfbb0000
(gdb) set *((int *) 0xbfbb0000) = 20
(gdb) p i
$3 = 20

This should work for any valid pointer, and can be cast to any appropriate data type.

Reply

#3
Expanding on the answers provided here.

You can just do `set idx = 1` to set a variable, but that syntax is not recommended because the variable name may clash with a set sub-command. As an example `set w=1` would not be valid.

This means that you should prefer the syntax: `set variable idx = 1` or `set var idx = 1`.


Last but not least, you can just use your trusty old print command, since it evaluates an expression. The only difference being that he also prints the result of the expression.

(gdb) p idx = 1
$1 = 1

You can read more about gdb [here][1].


[1]:

[To see links please register here]

Reply

#4
The easiest is setting a program variable (see <a href="http://sourceware.org/gdb/current/onlinedocs/gdb/Assignment.html#Assignment">GDB: assignment</a>):

(gdb) l
6 {
7 int i;
8 struct file *f, *ftmp;
9
(gdb) set variable i = 10
(gdb) p i
$1 = 10

Or you can just update arbitrary (writable) location by address:

(gdb) set {int}0x83040 = 4

There's more. Read <a href="http://sourceware.org/gdb/current/onlinedocs/gdb/">the manual</a>.

Reply

#5
One of the most useful things is to change the value of Registers directly.

0x000000000800088e <+67>: lea rdi,[rip+0x118] # 0x80009ad

To change the value of rdi register:

set $rdi = 0x8201010
Reply

#6
Writing memory:

(gdb) set *0x20001234 = 0xABABABAB

Reading memory:

(gdb) x 0x20001234
0x20001234: 0xabababab
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through