-
-
Notifications
You must be signed in to change notification settings - Fork 746
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
skipi
command to skip N instructions (#964)
- Loading branch information
1 parent
7fd94ab
commit 577ad02
Showing
3 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
## Command `skipi` | ||
|
||
The `skipi` command allows you to easily skip instructions execution. | ||
|
||
``` | ||
skipi [LOCATION] [--n NUM_INSTRUCTIONS] | ||
``` | ||
|
||
`LOCATION` address/symbol from where to skip (default is `$pc`) | ||
|
||
`--n NUM_INSTRUCTIONS` Skip the specified number of instructions instead of the default 1. | ||
|
||
```bash | ||
gef➤ skipi | ||
gef➤ skipi --n 3 | ||
gef➤ skipi 0x69696969 | ||
gef➤ skipi 0x69696969 --n 6 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
""" | ||
`skipi` command test module | ||
""" | ||
|
||
import pytest | ||
|
||
from tests.utils import (ARCH, GefUnitTestGeneric, _target, findlines, | ||
gdb_run_cmd, gdb_run_silent_cmd, gdb_start_silent_cmd) | ||
|
||
|
||
class SkipiCommand(GefUnitTestGeneric): | ||
"""`skipi` command test module""" | ||
|
||
|
||
cmd = "skipi" | ||
|
||
|
||
def test_cmd_nop_inactive(self): | ||
res = gdb_run_cmd(f"{self.cmd}") | ||
self.assertFailIfInactiveSession(res) | ||
|
||
|
||
@pytest.mark.skipif(ARCH not in ("i686", "x86_64"), reason=f"Skipped for {ARCH}") | ||
def test_cmd_skipi_no_arg(self): | ||
|
||
res = gdb_start_silent_cmd( | ||
"pi gef.memory.write(gef.arch.pc, p32(0x9090feeb))", # 1 short jumps to pc + 2 nops | ||
after=( | ||
self.cmd, | ||
"pi print(gef.memory.read(gef.arch.pc, 2))", # read 2 bytes | ||
) | ||
) | ||
self.assertNoException(res) | ||
self.assertIn(r"\x90\x90", res) # 2 nops | ||
|
||
|
||
@pytest.mark.skipif(ARCH not in ("i686", "x86_64"), reason=f"Skipped for {ARCH}") | ||
def test_cmd_skipi_skip_two_instructions(self): | ||
|
||
res = gdb_start_silent_cmd( | ||
"pi gef.memory.write(gef.arch.pc, p64(0x90909090feebfeeb))", # 2 short jumps to pc + 4 nops | ||
after=( | ||
f"{self.cmd} --n 2", | ||
"pi print(gef.memory.read(gef.arch.pc, 4))", # read 4 bytes | ||
) | ||
) | ||
self.assertNoException(res) | ||
self.assertIn(r"\x90\x90\x90\x90", res) # 4 nops | ||
|
||
|
||
@pytest.mark.skipif(ARCH not in ("i686", "x86_64"), reason=f"Skipped for {ARCH}") | ||
def test_cmd_skipi_two_instructions_from_location(self): | ||
|
||
res = gdb_start_silent_cmd( | ||
"pi gef.memory.write(gef.arch.pc, p64(0x9090feebfeebfeeb))", # 2 short jumps to pc + 2 nops | ||
after=( | ||
f"{self.cmd} $pc+2 --n 2", # from the second short jump | ||
"pi print(gef.memory.read(gef.arch.pc, 2))", # read 2 bytes | ||
) | ||
) | ||
self.assertNoException(res) | ||
self.assertIn(r"\x90\x90", res) # 2 nops | ||
|