Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GDB : changing the assembly code of a running program

Tags:

assembly

gdb

I successfuly changed an instruction to a NOP since it is pretty basic:

set *0x08048e3a = 0x90

But I'm trying to change this address 0x08048e3a which has je 0x8048e52. I would like to change it to je 0x8048ea8.

But when I do set *0x08048e3a = 0x74168048ea8 it does not work. (0x7416 = je instruction)

Thank you

like image 958
Francois Valiquette Avatar asked Dec 10 '11 07:12

Francois Valiquette


People also ask

How do I edit a program in gdb?

You can customize GDB to use any editor you want 10. By default, it is /bin/ex , but you can change this by setting the environment variable EDITOR before using GDB. For example, to configure GDB to use the vi editor, you could use these commands with the sh shell: EDITOR=/usr/bin/vi export EDITOR gdb …

Can you use gdb on assembly?

gdb is the GNU source-level debugger that is standard on linux (and many other unix) systems. It can be used both for programs written in high-level languages like C and C++ and for assembly code programs; this document concentrates on the latter.

How do I stop a program from running in gdb?

To stop your program while it is running, type "(ctrl) + c" (hold down the ctrl key and press c). gdb will stop your program at whatever line it has just executed. From here you can examine variables and move through your program. To specify other places where gdb should stop, see the section on breakpoints below.

How do I skip a gdb code?

So just type skip in gdb to skip a line. How to parametrize it to "skip(N)" ? @p2rkw. You can replace '1' with $arg0, as explained here: sourceware.org/gdb/onlinedocs/gdb/Define.html.


1 Answers

0x74168048ea8 is longer than a word. You should try setting bytes one by one, e.g.

  set *(char*)0x08048e3a = 0x74
  set *(char*)0x08048e3b = 0x16

etc

like image 98
Basile Starynkevitch Avatar answered Nov 15 '22 08:11

Basile Starynkevitch