Skip to content

Commit

Permalink
Merge branch 'dev' into gdb_8_py36_code_refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hugsy committed Jan 12, 2022
2 parents 1683fcb + 08f4b28 commit bf70642
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 35 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,13 @@ jobs:
echo "source $(pwd)/gef.py" > ~/.gdbinit
gdb -q -ex 'gef missing' -ex 'gef help' -ex 'gef config' -ex start -ex continue -ex quit /bin/pwd
- name: Run linter
run: |
make lint
- name: Run Tests
env:
GEF_CI_ARCH: ${{ steps.set-arch-properties.outputs.arch }}
run: |
make test
- name: Run linter
run: |
make lint
17 changes: 1 addition & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,26 +83,11 @@ Unlike other GDB plugins, GEF has an extensive and up-to-date [documentation](ht
## Contribute ##
[ ![contributors-img](https://contrib.rocks/image?repo=hugsy/gef) ](https://github.com/hugsy/gef/graphs/contributors)
To get involved, refer to the [Contribution documentation](https://gef.readthedocs.io/en/master/#contribution) and the [guidelines](https://github.com/hugsy/gef/blob/dev/.github/CONTRIBUTING.md) to start.
## Sponsors ##
We would like to thank in particular the following people who've been sponsoring GEF allowing us to dedicate more time and resources to the project:

[<img src="https://github.com/nkaretnikov.png" height="50px" width="50px" style="border-radius: 50%">](https://github.com/nkaretnikov)
[<img src="https://github.com/R3zk0n.png" height="50px" width="50px" style="border-radius: 50%">](https://github.com/r3zk0n)
[<img src="https://github.com/merces.png" height="50px" width="50px" style="border-radius: 50%">](https://github.com/merces)
[<img src="https://github.com/nbars.png" height="50px" width="50px" style="border-radius: 50%">](https://github.com/nbars)
[<img src="https://github.com/maycon.png" height="50px" width="50px" style="border-radius: 50%">](https://github.com/maycon)
[<img src="https://github.com/jespinhara.png" height="50px" width="50px" style="border-radius: 50%">](https://github.com/jespinhara)
[<img src="https://github.com/therealdreg.png" height="50px" width="50px" style="border-radius: 50%">](https://github.com/therealdreg)
[<img src="https://github.com/mikesart.png" height="50px" width="50px" style="border-radius: 50%">](https://github.com/mikesart)


Want to be part of this list of amazing people? [Jump here!](https://github.com/sponsors/hugsy)
Another way to contribute to keeping the project alive is by sponsoring it! Check out [the sponsoring documentation](https://gef.readthedocs.io/en/master/#sponsors) for details so you can be part of the list of those [awesome sponsors](https://github.com/sponsors/hugsy).
## Happy Hacking ##
1 change: 1 addition & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ improve it.
|`pattern` | This command will create or search a De Bruijn cyclic pattern to facilitate determining the offset in memory. The algorithm used is the same as the one used by pwntools, and can therefore be used in conjunction.|
|`pcustom` | Dump user defined structure. This command attempts to reproduce WinDBG awesome `dt` command for GDB and allows to apply structures (from symbols or custom) directly to an address. Custom structures can be defined in pure Python using ctypes, and should be stored in a specific directory, whose path must be stored in the `pcustom.struct_path` configuration setting. (alias: `dt`)|
|`pie` | Base command to support PIE breakpoints. PIE breakpoints is that you can set to a PIE binary, and use pie series commands to attach or create a new process, and it will automatically set the real breakpoint when the binary is running.
|`print-format` | Command to dump memory in a variety of formats, such as programming language array literals. (alias: `pf`)|
|`process-search` | List and filter process. (alias: `ps`)|
|`process-status` | Extends the info given by GDB `info proc`, by giving an exhaustive description of the process status.|
|`registers` | Display full details on one, many or all registers value from current architecture.|
Expand Down
6 changes: 3 additions & 3 deletions docs/commands/dereference.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ gef➤ dereference
Here is an example with arguments:

```
gef➤ telescope $rbp+0x10 8
gef➤ telescope $rbp+0x10 -l 8
0x00007fffffffdf40│+0x0000: 0x00007ffff7fa5760 → 0x00000000fbad2887
0x00007fffffffdf48│+0x0008: 0x00000001f7e65b63
0x00007fffffffdf50│+0x0010: 0x0000000000000004
Expand All @@ -49,7 +49,7 @@ context (on a 64bit architecture):
```
gef➤ p ($rbp - $rsp)/8
$3 = 4
gef➤ dereference 5
gef➤ dereference -l 5
0x00007fffffffe170│+0x0000: 0x0000000000400690 → push r15 ← $rsp
0x00007fffffffe178│+0x0008: 0x0000000000400460 → xor ebp, ebp
0x00007fffffffe180│+0x0010: 0x00007fffffffe270 → 0x1
Expand All @@ -61,7 +61,7 @@ It is possible to change the offset calculation to use a different address than
the start address:

```
gef➤ dereference $sp l7 r$rbp
gef➤ dereference $sp -l 7 -r $rbp
0x00007ffe6ddaa3e0│-0x0030: 0x0000000000000000 ← $rsp
0x00007ffe6ddaa3e8│-0x0028: 0x0000000000400970 → <__libc_csu_init+0> push r15
0x00007ffe6ddaa3f0│-0x0020: 0x0000000000000000
Expand Down
5 changes: 3 additions & 2 deletions docs/commands/print-format.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
## Command print-format ##

The command `print-format` (alias `pf`) will dump an arbitrary location as an array of bytes following the syntax of the programming language specified. Currently, the output language supported are
The command `print-format` (alias `pf`) will dump an arbitrary location as an array of bytes following the format specified. Currently, the output formats supported are

- Python (`py` - default)
- C (`c`)
- Assembly (`asm`)
- Javascript (`js`)
- Hex string (`hex`)


```
gef➤ print-format -h
[+] print-format [--lang LANG] [--bitlen SIZE] [(--length,-l) LENGTH] [--clip] LOCATION
--lang LANG specifies the output format for programming language (available: ['py', 'c', 'js', 'asm'], default 'py').
--lang LANG specifies the output format for programming language (available: ['py', 'c', 'js', 'asm', 'hex'], default 'py').
--bitlen SIZE specifies size of bit (possible values: [8, 16, 32, 64], default is 8).
--length LENGTH specifies length of array (default is 256).
--clip The output data will be copied to clipboard
Expand Down
14 changes: 13 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,21 @@ _Side Note_: `GEF` fully relies on the GDB API and other Linux-specific sources

[ ![contributors-img](https://contrib.rocks/image?repo=hugsy/gef) ](https://github.com/hugsy/gef/graphs/contributors)


Or if you just like the tool, feel free to drop a simple *"thanks"* on Discord, Twitter or other, it is **always** very appreciated.

## Sponsors ##

We would like to thank in particular the following people who've been sponsoring GEF allowing us to dedicate more time and resources to the project:

[<img src="https://github.com/nkaretnikov.png" height="50px" width="50px" style="border-radius: 50%">](https://github.com/nkaretnikov)
[<img src="https://github.com/R3zk0n.png" height="50px" width="50px" style="border-radius: 50%">](https://github.com/r3zk0n)
[<img src="https://github.com/merces.png" height="50px" width="50px" style="border-radius: 50%">](https://github.com/merces)
[<img src="https://github.com/nbars.png" height="50px" width="50px" style="border-radius: 50%">](https://github.com/nbars)
[<img src="https://github.com/maycon.png" height="50px" width="50px" style="border-radius: 50%">](https://github.com/maycon)
[<img src="https://github.com/jespinhara.png" height="50px" width="50px" style="border-radius: 50%">](https://github.com/jespinhara)
[<img src="https://github.com/therealdreg.png" height="50px" width="50px" style="border-radius: 50%">](https://github.com/therealdreg)
[<img src="https://github.com/mikesart.png" height="50px" width="50px" style="border-radius: 50%">](https://github.com/mikesart)


### Extra Credits ###

Expand Down
22 changes: 13 additions & 9 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ class Elf:
AARCH64 = 0xb7
RISCV = 0xf3
IA64 = 0x32
M68K = 0x04

ET_RELOC = 1
ET_EXEC = 2
Expand Down Expand Up @@ -4587,7 +4588,7 @@ def do_invoke(self, argv: List) -> None:

@register_command
class PrintFormatCommand(GenericCommand):
"""Print bytes format in high level languages."""
"""Print bytes format in commonly used formats, such as literals in high level languages."""

valid_formats = ("py", "c", "js", "asm")
valid_bitness = (8, 16, 32, 64)
Expand All @@ -4602,7 +4603,6 @@ class PrintFormatCommand(GenericCommand):
"\tLOCATION specifies where the address of bytes is stored.")
_example_ = f"{_cmdline_} --lang py -l 16 $rsp"


def __init__(self) -> None:
super().__init__(complete=gdb.COMPLETE_LOCATION)
return
Expand Down Expand Up @@ -4653,7 +4653,9 @@ def do_invoke(self, argv: List, *args: Tuple[Any, ...], **kwargs: Dict[str, Any]
out = f"var buf = [{sdata}]"
elif args.lang == "asm":
asm_type = self.format_matrix[args.bitlen][2]
out = f"buf {asm_type} {sdata}"
out = "buf {0} {1}".format(asm_type, sdata)
elif args.lang == "hex":
out = binascii.hexlify(read_memory(start_addr, end_addr-start_addr)).decode()

if args.clip:
if copy_to_clipboard(gef_pybytes(out)):
Expand Down Expand Up @@ -7109,7 +7111,10 @@ def check_thread_ids(tids: List[int]) -> List[int]:
@staticmethod
def tcachebin(tcache_base: int, i: int) -> Tuple[Optional[GlibcChunk], int]:
"""Return the head chunk in tcache[i] and the number of chunks in the bin."""
assert i < GlibcHeapTcachebinsCommand.TCACHE_MAX_BINS, "index should be less then TCACHE_MAX_BINS"
if i >= GlibcHeapTcachebinsCommand.TCACHE_MAX_BINS:
err("Incorrect index value, index value must be between 0 and {}-1, given {}".format(GlibcHeapTcachebinsCommand.TCACHE_MAX_BINS, i))
return None, 0

tcache_chunk = GlibcChunk(tcache_base)

# Glibc changed the size of the tcache in version 2.30; this fix has
Expand Down Expand Up @@ -7822,6 +7827,7 @@ def do_invoke(self, argv: List, *args, **kwargs) -> None:
Elf.AARCH64 : "AArch64",
Elf.RISCV : "RISC-V",
Elf.IA64 : "IA-64",
Elf.M68K : "M68K",
}

filename = args.filename or get_filepath()
Expand Down Expand Up @@ -8494,12 +8500,10 @@ def __get_current_block_start_address() -> Optional[int]:
pass

if not nb_argument:
if not parameter_set:
nb_argument = 0
elif is_x86_32():
if is_x86_32():
nb_argument = len(parameter_set)
else:
nb_argument = max(function_parameters.index(p)+1 for p in parameter_set)
nb_argument = max([function_parameters.index(p)+1 for p in parameter_set], default=0)

args = []
for i in range(nb_argument):
Expand Down Expand Up @@ -10374,7 +10378,7 @@ def do_invoke(self, args: List) -> int:

@register_function
class GotBaseFunction(GenericFunction):
"""Return the current bss base address plus the given offset."""
"""Return the current GOT base address plus the given offset."""
_function_ = "_got"
_example_ = "deref $_got(0x20)"

Expand Down
3 changes: 3 additions & 0 deletions scripts/gef.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ if [ "$1" = "dev" ]; then
echo "set branch to dev"
fi

curl_found=0
wget_found=0

# check dependencies
if [ `which curl` ]; then
curl_found=1
Expand Down
3 changes: 3 additions & 0 deletions tests/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ def test_cmd_print_format(self):
res = gdb_start_silent_cmd("print-format --lang js $sp")
self.assertNoException(res)
self.assertTrue("var buf = [" in res)
res = gdb_start_silent_cmd("print-format --lang hex $sp")
self.assertNoException(res)
self.assertTrue("f7ff7f" in res)
res = gdb_start_silent_cmd("print-format --lang iDontExist $sp")
self.assertNoException(res)
self.assertTrue("Language must be in:" in res)
Expand Down

0 comments on commit bf70642

Please sign in to comment.