How to run build in gdb directly?

I can use callto run c-functions, but how to run assembly or even shell code directly?

+5
source share
2 answers

To execute shell code, you can directly edit the contents of a function:

(gdb) b foo
Breakpoint 1 at 0x400608
(gdb) run
Breakpoint 1, 0x0000000000400608 in foo ()
(gdb) x/16bx foo
0x400604 <foo>:        0x55    0x48    0x89    0xe5    0x53    0x48    0x81   0xec
(gdb) set ((unsigned char *)foo)[6] = 0x85
(gdb) x/16bx foo
0x400604 <foo>:        0x55    0x48    0x89    0xe5    0x53    0x48    0x85   0xec
(gdb) cont

I don’t know how to execute opcodes from gdb, but you can certainly do whatever you want with registers. For example, instead mov %rbx, %raxyou can use set $rax = $rbx:

(gdb) p $rax
$1 = 3671197290184
(gdb) set $rax = $rbx
(gdb) p $rax
$2 = 0
(gdb)
+6
source

I don't think gdb includes assembler, so I did not expect you to be able to directly enter the assembly.

You can use the shellgdb command to run shell commands:

(gdb) shell uname -m
x86_64
-1

All Articles