2509 Commits
Author SHA1 Message Date
NaveenkumarandNK 49c07dc606 heap: support glibc >= 2.43 (fastbins were removed) (#1231)
Fixes #1225

## Problem

glibc 2.43 removed the fastbin infrastructure (upstream commit
`bb5a4f5`),
so `struct malloc_state` no longer contains `fastbinsY[NFASTBINS]` nor
`have_fastchunks`. GEF's `GlibcArena.malloc_state_t()` was still parsing
the old layout, so on glibc >= 2.43 every heap command reading the arena
showed garbage (`heap arenas` with wrong `top`/`last_remainder`, broken
`heap bins`, ...).

## Fix

Made the arena layout version-aware:

- `GlibcArena.has_fastbins()`: fastbins exist only on glibc < 2.43
- `GlibcArena.malloc_state_t()`: no longer defines `fastbinsY` /
  `have_fastchunks` on glibc >= 2.43
- `GlibcArena.fastbinsY` returns an empty array, `fastbin()` returns
  `None`, so existing callers behave safely
- `heap bins fast` exits with a clear message instead of parsing
  corrupted data

## Tests

Added `HeapCommandNoFastbins` (tests/commands/heap.py): it forces
`gef.libc._version = (2, 43)` regardless of the host glibc and verifies
the 2.43 arena layout has no fastbins and `heap bins fast` reports them
as unsupported.

The initial CI run failed on `fedora-rawhide` (glibc 2.44) for two
reasons, both fixed in the follow-up commit:

- `HeapCommandFastBins::test_cmd_heap_bins_fast` was missing the
  `skipif(is_glibc_ge(2, 43))` marker that all the other fastbin tests
  use, and failed on a real no-fastbins glibc
- `CanaryCommand::test_cmd_canary` asserted that the stack canary equals
  the `AT_RANDOM`-derived value; on glibc >= 2.44 the canary is no
  longer derived from `AT_RANDOM`, so the test is skipped there (the
  `canary` command itself still reads the right value from the TLS slot)

Verified locally against glibc 2.41 (Debian), 2.43 (fedora:44) and
2.44 (fedora:rawhide) containers, plus `pre-commit run --all-files`.

---------

Co-authored-by: NK <[email protected]>
2026-08-20 14:33:25 -07:00
Koutheir Attouchi 87f359ba27 Set Gray color as "Bright Black" (#1227)
## Description

Set Gray color as "Bright Black", judging from [Gentoo's documentation
about colors in terminal
emulators](https://wiki.gentoo.org/wiki/Terminal_emulator/Colors#Specifying_colors).

This has the nice effect of enabling custom theming of the gray color by
the terminal application (e.g., Konsole), so that the gray remains
readable with different themes.
2026-06-16 08:22:12 -07:00
crazy hugsy edbc7b8f07 Update PR template to add a Licensing section (#1224)
## Description

This PR adds a checkbox for LLM-generated code in the PR template.
2026-05-15 16:21:03 -07:00
crazy hugsy 90cced847b [Maintenance] Remove unmaintained commands, tests, and documentation, and moved to Ruff (#1222)
## Description

This PR  
 - removes unmaintained `shellcode` commands, tests, and documentation
- (finally) switches to Ruff instead of Pylint (still handled by
`pre-commit`)
 - fixes a few ruff/ty-found issues
2026-05-02 12:15:26 -07:00
qfalconer fd8ec6ff12 Don't assume the tcache is the first allocated chunk and handle the 12 extra bins since glibc 2.42 (#1221)
## Description

If gef cannot resolve a pointer to the tcache through symbol lookup it
will assume the tcache is on the first allocated chunk.
This is not true on glibc 2.42 (and possibly previous versions) since
dlmalloc will only allocate the tcache [if the allocation being served
has a size that fits the
tcache](https://github.com/bminor/glibc/blob/glibc-2.42/malloc/malloc.c#L3474).
This PR add a simple heuristic that checks if the first 64 bytes the
first chunks are all less or equal to 7 (the max number of chunks in a
tcache bins). If not, the next chunk is considered and the check
repeated until a valid candidate is found or an error is raised (in this
case the first chunk is used as a fallback, preserving legacy).

In glibc 2.42 the tcache also changed in number of bins, increasing from
64 to 64+12. **I didn't check if any other structural change was made,
it seems not**.
This PR introduces two new instance variables in
`GlibcHeapTcachebinsCommand`: `tcache_max_bins` and `tcache_count_size`.
These are initialised in the ctor if the glibc version is known,
otherwise the `find_tcache` method will set them based on the glibc
version range inferred from the tcache chunk size (pretty much how the
count size was determined).

This patch was created to address this PoC of a recent glibc
vulnerability and was tested with glibc 2.42.

```
#include <assert.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static void normal_func(void) {
    puts("We are safe :)");
}

static void malicious_func(void) {
    puts("Got hijacked!!");
}

#define width 0x409
int main(void) {
    __attribute__((aligned(16))) void (*func_ptr)(void) = normal_func;

    char *buf = NULL;
    char *input = malloc(width + 1);
    if (input == NULL)
        return 1;
    memset(input, 0x61, width);
    input[width] = '\0';

    // layout heap...
    size_t *chunk1 = malloc(0x408);
    size_t *chunk2 = malloc(0x28);
    size_t *chunk3 = malloc(0x28);
    size_t *chunk4 = malloc(0x28);
    free(chunk1);
    free(chunk4);

    // before off-by-one: [chunk2   ][chunk3   ]
    int rc = sscanf(input, "%1033mc", &buf);
    assert(rc != -1);

_b:
    // release [chunk2   [chunk3   ]]
    free(chunk2);
    free(chunk3);

    // now hijack chunk3->fd via chunk2
    chunk2 = malloc(0x58);
    chunk2[6] = (size_t)&func_ptr ^ ((size_t)chunk3 >> 12);

    // allocate chunk3 back, which is now at &func_ptr, write with another func
    size_t *chunk5 = malloc(0x28);
    chunk3 = malloc(0x28);
    *chunk3 = (size_t)malicious_func;

    func_ptr();

    free(buf);
    free(input);
    return 0;
}
```

```
gcc poc.c -g -o poc
gdb ./poc -ex 'b main:_b'  -ex 'r' -ex 'heap bins tcache'
```

You must **not** have debug symbols for glibc such that [`tcache_addr =
parse_address("(void *)
tcache")`](https://github.com/hugsy/gef/blob/main/gef.py#L6935) fails to
resolve.

When using the current version of gef:
<img width="751" height="430" alt="image"
src="https://github.com/user-attachments/assets/35daa681-1c75-4a41-a920-042f4da4b4ef"
/>
because `malloc(width + 1)` doesn't fit in the tcache range and it's the
first chunk allocated


When using the patched version of gef:

<img width="1171" height="83" alt="image"
src="https://github.com/user-attachments/assets/b4086e1e-1447-4d15-a80f-68cb7907e307"
/>
2026-05-02 11:55:37 -07:00
YuSung Han f55b81256a Fix: malloc_state padding on 32-bit glibc #1202 (#1220)
Fixes  #1202

## Description

This patch fixes the `malloc_state` layout used by
`GlibcArena.malloc_state_t()` on 32-bit glibc targets.

For glibc 2.27+, GEF currently adds the `UNUSED_c` padding field
unconditionally after `have_fastchunks`. That matches the expected
alignment on 64-bit targets, but it is incorrect on 32-bit targets such
as ARMv7. As a result, the parsed `malloc_state` layout is shifted by 4
bytes, and later fields such as `top`, `last_remainder`, `next`,
`system_mem`, and `max_system_mem` are read from incorrect offsets.

In practice, this breaks heap arena parsing on affected targets. For
example, `heap arenas` may show an invalid `next` pointer such as `0x0`,
fail to walk the arena list correctly, or display corrupted memory
statistics such as an invalid `mempeak` value.

This patch makes the padding conditional on pointer size and only
inserts `UNUSED_c` on 64-bit targets. This keeps the existing behavior
for 64-bit glibc while restoring the correct `malloc_state` layout on
32-bit glibc.

This change is required to make heap arena parsing work correctly on
32-bit ARM systems affected by #1202.

Reproduction environment reported in the issue:

* Debian bookworm
* glibc 2.36
* ARMv7 (32-bit)
* GDB 13.1

Observed behavior before this change:

* `heap arenas` reports an invalid `next` pointer
* arena traversal is broken
* `mempeak` and related fields may contain corrupted values

Expected behavior after this change:

* `heap arenas` parses `malloc_state` using the correct layout on 32-bit
targets
* `next` points to the correct arena
* arena traversal works as expected
* memory-related fields are read from the correct offsets
2026-04-26 16:18:10 -07:00
hugsy 0c95800c3a [Docs] Use only absolute URLs to githubusercontent instead 2026-02-15 14:09:04 -08:00
hugsy 0943a67916 Updated docs/ only for images links 2026-02-15 13:28:11 -08:00
crazy hugsy 015ab1f722 Restored all images (#1215)
## Description

Final followup to #1211 that completely restore all images
2026-02-15 13:09:09 -08:00
crazy hugsy 6dce6c893f [Docs] Fix broken image paths (#1211)
## Description

Fixes #1210 by moving image path to `docs/assets/images/` (instead of
`assets/images/`)
2026-02-15 12:57:42 -08:00
Gordon Messmer 650978c076 Convert test workflow to container-based testing (#1208)
Refactor the CI workflow to build and run tests inside Docker containers
instead of directly on GitHub runners. This adds support for testing on
Fedora releases in addition to Ubuntu 22.04 and 24.04.

## Description

This change uses container images for tests so that platforms other than
the ones provided directly by GitHub can be tested.

Testing in container images makes it easier to support a broader range
of platforms, but more importantly it allows gef to test and adapt to
changes in glibc, gcc, and Python as they are released, rather than
re-synchronizing with those projects every two years.
2026-02-15 10:32:25 -08:00
crazy hugsy 6102a1e282 [Docs] Move imgur images to local docs folder (#1210)
## Description

Imgur is blocked in UK since September 2025 (see #1200)
Move imgur hosted images to local folder instead.

Fixes #1200
2026-02-03 18:31:55 -08:00
crazy hugsy 18404074f4 [CI] Test ARM64 build with GithubActions (#1166)
## Description

Ubuntu ARM runners are [now available](https://github.blog/changelog/2025-01-16-linux-arm64-hosted-runners-now-available-for-free-in-public-repositories-public-preview/).
Add them to the test suite.

Note: the following tests are marked as skipped for `aarch64` since they
failed on CI (but work locally). Will revisit later
 - `test_func_parse_maps_remote_qemu`
 - `test_func_parse_maps_realpath`
 - `test_cmd_heap_bins_tcache`
 - `test_cmd_heap_bins_tcache_all`
 - `test_can_establish_connection_to_gdbserver_again_after_disconnect`

---------

Signed-off-by: hugsy <[email protected]>
2026.01
2026-02-01 13:36:11 -08:00
Gordon Messmer d96faaa9d9 Fix formatting and links, per CI tests (#1209)
## Description

URL checks and format tests are currently failing in CI results. These
changes address the errors raised.
2026-02-01 12:10:40 -08:00
GHOS7 1N 7H3 F1NG3RS 4ce50e3db6 Update gef-extras.sh (#1207) 2026-02-01 12:06:08 -08:00
Jvle 58de027863 gef.sh: warn about XDG init file taking precedence (#1204)
## Description

On some systems, GDB may read the XDG init file
(`~/.config/gdb/gdbinit`) instead of `~/.gdbinit`.
In that case, the installer updates `~/.gdbinit` correctly, but GEF
still won’t auto-load on `gdb` startup, which is confusing for users.

This PR adds a minimal post-install hint: if `~/.config/gdb/gdbinit`
exists, print a note telling users to add `source ~/.gef-<tag>.py` to
that file if GEF doesn't auto-load.

## References
> On non-Apple hosts the locations searched are:
> 
> $XDG_CONFIG_HOME/gdb/gdbinit
> $HOME/.config/gdb/gdbinit
> $HOME/.gdbinit
> While on Apple hosts the locations searched are:
>
> $HOME/Library/Preferences/gdb/gdbinit
> $HOME/.gdbinit


https://sourceware.org/gdb/current/onlinedocs/gdb.html/Initialization-Files.html#Home-directory-initialization-files

---------

Signed-off-by: Jvle <[email protected]>
2026-02-01 12:04:25 -08:00
dependabot[bot] 60a99cb7fd Bump lycheeverse/lychee-action from 1.10.0 to 2.0.2 in /.github/workflows (#1192)
Bumps
[lycheeverse/lychee-action](https://github.com/lycheeverse/lychee-action)
from 1.10.0 to 2.0.2.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/lycheeverse/lychee-action/releases">lycheeverse/lychee-action's
releases</a>.</em></p>
<blockquote>
<h2>Version 2.0.2</h2>
<h2>What's Changed</h2>
<ul>
<li>Fix a typos by <a
href="https://github.com/szepeviktor"><code>@​szepeviktor</code></a> in
<a
href="https://redirect.github.com/lycheeverse/lychee-action/pull/257">lycheeverse/lychee-action#257</a></li>
<li>Document and use correct permissions in the GitHub workflows by <a
href="https://github.com/dscho"><code>@​dscho</code></a> in <a
href="https://redirect.github.com/lycheeverse/lychee-action/pull/258">lycheeverse/lychee-action#258</a></li>
<li>Add security policy by <a
href="https://github.com/mondeja"><code>@​mondeja</code></a> in <a
href="https://redirect.github.com/lycheeverse/lychee-action/pull/259">lycheeverse/lychee-action#259</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a
href="https://github.com/szepeviktor"><code>@​szepeviktor</code></a>
made their first contribution in <a
href="https://redirect.github.com/lycheeverse/lychee-action/pull/257">lycheeverse/lychee-action#257</a></li>
<li><a href="https://github.com/mondeja"><code>@​mondeja</code></a> made
their first contribution in <a
href="https://redirect.github.com/lycheeverse/lychee-action/pull/259">lycheeverse/lychee-action#259</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/lycheeverse/lychee-action/compare/v2...v2.0.2">https://github.com/lycheeverse/lychee-action/compare/v2...v2.0.2</a></p>
<h2>Version 2.0.1</h2>
<h2>What's Changed</h2>
<ul>
<li>Don't remove the lychee config file by <a
href="https://github.com/dmathieu"><code>@​dmathieu</code></a> in <a
href="https://redirect.github.com/lycheeverse/lychee-action/pull/255">lycheeverse/lychee-action#255</a></li>
<li>Bump lycheeverse/lychee-action from 1 to 2 by <a
href="https://github.com/dependabot"><code>@​dependabot</code></a> in <a
href="https://redirect.github.com/lycheeverse/lychee-action/pull/252">lycheeverse/lychee-action#252</a></li>
<li>Fix variable name in docs by <a
href="https://github.com/kdeldycke"><code>@​kdeldycke</code></a> in <a
href="https://redirect.github.com/lycheeverse/lychee-action/pull/253">lycheeverse/lychee-action#253</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a href="https://github.com/dmathieu"><code>@​dmathieu</code></a>
made their first contribution in <a
href="https://redirect.github.com/lycheeverse/lychee-action/pull/255">lycheeverse/lychee-action#255</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/lycheeverse/lychee-action/compare/v2...v2.0.1">https://github.com/lycheeverse/lychee-action/compare/v2...v2.0.1</a></p>
<h2>Version 2.0.0</h2>
<h2>Breaking Changes</h2>
<p><strong>Note:</strong> This release improves the action's robustness
by changing default behaviors. Changes are only required if you want to
opt out of the new failure conditions. Most users won't need to modify
their existing configurations.</p>
<h3>Fail pipeline on error by default</h3>
<p>We've changed the default behavior: pipelines will now fail on broken
links automatically. This addresses user feedback that not failing on
broken links was unexpected (see [issue <a
href="https://redirect.github.com/lycheeverse/lychee-action/issues/71">#71</a>](<a
href="https://redirect.github.com/lycheeverse/lychee-action/issues/71">lycheeverse/lychee-action#71</a>)).</p>
<p><strong>What you need to do:</strong></p>
<ul>
<li>Update to version 2 of this action to apply this change.</li>
<li>Users of the <code>lychee-action@master</code> branch don't need to
make any changes, as <code>fail: true</code> has been the default there
for a while.</li>
<li>If you prefer the old behavior, explicitly set <code>fail</code> to
<code>false</code> when updating:</li>
</ul>
<pre lang="yaml"><code>- name: Link Checker
  id: lychee
  uses: lycheeverse/lychee-action@v2
  with:
    fail: false  # Don't fail action on broken links
</code></pre>
<h3>Fail pipeline if no links were found</h3>
<p>Similar to the above change, we now fail the pipeline if no links are
found during a run. This helps warn users about potential configuration
issues.</p>
<p><strong>What you need to do:</strong></p>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/lycheeverse/lychee-action/commit/7cd0af4c74a61395d455af97419279d86aafaede"><code>7cd0af4</code></a>
Merge commit from fork</li>
<li><a
href="https://github.com/lycheeverse/lychee-action/commit/8ad54d3568ac3176a9fb57a0233cf04410b55cde"><code>8ad54d3</code></a>
fix link</li>
<li><a
href="https://github.com/lycheeverse/lychee-action/commit/762333c18963fc10db515e32000e2e4dbcb11f5f"><code>762333c</code></a>
Create SECURITY.md (<a
href="https://redirect.github.com/lycheeverse/lychee-action/issues/259">#259</a>)</li>
<li><a
href="https://github.com/lycheeverse/lychee-action/commit/71a38a3bd757f6306a6c14206219391d4e5807ed"><code>71a38a3</code></a>
Document and use correct permissions in the GitHub workflows (<a
href="https://redirect.github.com/lycheeverse/lychee-action/issues/258">#258</a>)</li>
<li><a
href="https://github.com/lycheeverse/lychee-action/commit/f141760066406690a7f54a23762e3d146ea0d721"><code>f141760</code></a>
Fix a typos (<a
href="https://redirect.github.com/lycheeverse/lychee-action/issues/257">#257</a>)</li>
<li><a
href="https://github.com/lycheeverse/lychee-action/commit/2bb232618be239862e31382c5c0eaeba12e5e966"><code>2bb2326</code></a>
don't remove the lychee config file (<a
href="https://redirect.github.com/lycheeverse/lychee-action/issues/255">#255</a>)</li>
<li><a
href="https://github.com/lycheeverse/lychee-action/commit/731bf1a2affebd80fab6515ba61d2648a76929a4"><code>731bf1a</code></a>
Fix variable name (<a
href="https://redirect.github.com/lycheeverse/lychee-action/issues/253">#253</a>)</li>
<li><a
href="https://github.com/lycheeverse/lychee-action/commit/e360f3c89142a5391e094404ea45e5494f1317dd"><code>e360f3c</code></a>
Bump lycheeverse/lychee-action from 1 to 2 (<a
href="https://redirect.github.com/lycheeverse/lychee-action/issues/252">#252</a>)</li>
<li><a
href="https://github.com/lycheeverse/lychee-action/commit/f87f0a62993c2647717456af92593666acb3a500"><code>f87f0a6</code></a>
Update version to <code>lycheeverse/lychee-action@v2</code> in docs</li>
<li><a
href="https://github.com/lycheeverse/lychee-action/commit/7da8ec1fc4e01b5a12062ac6c589c10a4ce70d67"><code>7da8ec1</code></a>
Test latest lychee version tag (<a
href="https://redirect.github.com/lycheeverse/lychee-action/issues/236">#236</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/lycheeverse/lychee-action/compare/v1.10.0...v2.0.2">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=lycheeverse/lychee-action&package-manager=github_actions&previous-version=1.10.0&new-version=2.0.2)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the
[Security Alerts page](https://github.com/hugsy/gef/network/alerts).

</details>

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-09 10:45:02 -08:00
Guy Shimko c1e354ebad Fix TIOCGWINSZ struct size mismatch (#1205)
A buffer the size of `struct winsize` should be passed to the TIOCGWINSZ
ioctl. The size of the winsize struct is 8 bytes (see
https://man7.org/linux/man-pages/man2/TIOCSWINSZ.2const.html), but a
4-bytes buffer was passed, which caused a BOF.

## Description

The patch fixes a BOF which caused a crash in some newer python
environments.

Fixes #1201
2025-12-27 00:41:03 -05:00
crazy hugsy ee605f9ae6 Limit the number of instructions when guessing args in context (#1184)
## Description

In `print_guessed_arguments`, cap the distance from pc to basic block
start address

Fixes #1183

Signed-off-by: hugsy <[email protected]>
2025-04-15 09:05:30 -07:00
Sami Kalliomäki 63304c722c Fix location of syscall-tables for gef-extras installation script (#1182)
Fix location of syscall-tables for gef-extras installation script.
2025-04-08 15:52:07 -04:00
Maxime Bonilloandcrazy hugsy 5404b6f7cf Install/update sh script: Avoid overwriting existing gdb config (#1175)
As a GDB user I need to keep my existing config when installing GEF

Current, the `~/.gdbinit` content is currently completely removed

Replaced move with copy for the backup
[Upgrade] Check if GEF is already sourced, and replace version
[Install] Add GEF script at 1st line

---------

Co-authored-by: crazy hugsy <[email protected]>
2025-03-25 17:54:22 -04:00
crazy hugsy c631746966 Verify gdb.parameter("debug-file"directory") returns a string (#1177)
## Description

This PR fixes a missing type check introduced by #1173 when getting
result from `gdb.parameter` while setting ` debug-file-directory`



Signed-off-by: hugsy <[email protected]>
2025-03-16 10:17:57 -07:00
4098b8fe04 Always print top chunk when run heap chunks -a (#1170)
## Description

Test case:
https://github.com/shellphish/how2heap/blob/master/glibc_2.39/house_of_tangerine.c

Top chunk cannot be printed after it's size changed, pero top chunk
always access by `arena.top`, it should always been printed ever with a
malform size.

Co-authored-by: crazy hugsy <[email protected]>
Co-authored-by: Grazfather <[email protected]>
2025-03-15 14:12:30 -07:00
Gordon Messmer 265f22e2e5 Add a path argument to GotCommand build_line to support hugsy/gef-extras/pull/122 (#1172)
Add a path argument to GotCommand build_line to support updates in
GotAudit.

Related changes in hugsy/gef-extras/pull/122

In order to reduce false positives in GotAudit, the build_line function
requires the path to the file whose symbols are being described.
2025-02-23 19:46:48 -05:00
tesujiandcrazy hugsy 57181d278a Setup fallback 'debug-file-directory' (#1173)
## Description

This PR adds fallback path `/usr/lib/debug` to `debug-file-directory` config.

Closes #1169.

Some gdbs installed outside `/usr` (like nix or in user homedir) will not search for dbgsyms in `/usr/lib/debug`. However `/us/lib/debug` is where most distros package debuginfo symbols to.

### Before

```console
> /run/workspace/bin/gdb -q -x .gef.py -ex 'show debug-file-directory' -ex 'quit'
The directory where separate debug symbols are searched for is "/nix/store/k51rfv38p65jbhw906vpl85yg1vd7xqn-gdb-15.2/lib/debug".
```
### After 
```console
> /run/workspace/bin/gdb -q -x .gef.py -ex 'show debug-file-directory' -ex 'quit'
The directory where separate debug symbols are searched for is "/nix/store/k51rfv38p65jbhw906vpl85yg1vd7xqn-gdb-15.2/lib/debug:/usr/lib/debug".
```

---------

Co-authored-by: crazy hugsy <[email protected]>
2025-02-13 12:58:39 -08:00
Gordon Messmer c430473382 Use the correct type for function passed to pthread_create. (#1171)
## Description

This patch modifies the `thread` function in two test files, so that it
matches the expected prototype for an argument to pthread_create. This
fixes a build failure with gcc 15:

```
heap-non-main.c: In function ‘main’:
heap-non-main.c:27:40: error: passing argument 3 of ‘pthread_create’ from incompatible pointer type [-Wincompatible-pointer-types]
   27 |         pthread_create(&thread1, NULL, thread, NULL);
      |                                        ^~~~~~
      |                                        |
      |                                        void * (*)(void)
In file included from heap-non-main.c:8:
/usr/include/pthread.h:204:36: note: expected ‘void * (*)(void *)’ but argument is of type ‘void * (*)(void)’
  204 |                            void *(*__start_routine) (void *),
      |                            ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
heap-non-main.c:11:7: note: ‘thread’ declared here
   11 | void *thread()
      |       ^~~~~~
```

## Checklist

<!-- N.B.: Your patch won't be reviewed unless fulfilling the following
base requirements: -->
<!--- Put an `x` in all the boxes that are complete, or that don't apply
-->
-  [x] My code follows the code style of this project.
-  [x] My change includes a change to the documentation, if required.
- [x] If my change adds new code, [adequate tests](docs/testing.md) have
been added.
-  [x] I have read and agree to the **CONTRIBUTING** document.
2025-02-12 12:03:20 -05:00
b10902118 7638efe9c4 fix enum.Flag empty check (#1167)
## Description

Fix the permission checks in `Section` by using
[enum.Flag.\_\_bool\_\_](https://docs.python.org/3/library/enum.html#enum.Flag).
For `enum.Flag`, != 0 always returns `True`, as the test below.
```python
import enum

class Permission(enum.Flag):
    NONE = 0
    EXECUTE = 1
    WRITE = 2
    READ = 4
    ALL = 7

p = Permission(0)
print(p, p != 0)  # Permission.NONE True
```

The fixed functions are rarely called. I found this when porting
`Section` to [llef](https://github.com/foundryzero/llef). I also have
checked all `!= 0` and found no similar error.
2025-01-26 09:35:46 -08:00
crazy hugsy ed10244b0f Fixes for release 2025.01 (#1164)
## Description

Minor fixes for the 2025.01 release

---------

Signed-off-by: hugsy <[email protected]>
2025.01
2025-01-12 06:49:07 -08:00
Wren [Undefined] 538c7c6fde Fix bge/bgeu for RISC-V (#1163)
This fixes `bge` and `bgeu` branch prediction for RISC-V due to a typo
in the original code.
2025-01-09 11:39:53 -05:00
Jörg Thalheim 522535864f [Docs] Typos fixes (#1160)
## Description

This PR fixes several typos in the doucmentation.
No code was changed.
2024-12-27 15:59:37 -08:00
Grazfather 283a7f63c2 reset_architecture: Force arch to lower case (#1159)
The caller shouldn't need to know to make it lower case.
2024-12-08 23:30:40 -08:00
crazy hugsy 29884e3195 [CI] Add extended testing capability (#1156)
## Description

Adds Github Actions workflow (`workflow_dispatch` only) and scripts for
running tests in docker on
 - [x] Fedora
 - [x] Debian
 - [x] ArchLinux

Fixes #1152
2024-11-13 09:13:53 +01:00
crazy hugsy 9f2737a04d Use maint info sec for coredumps (#1155)
## Description

When analyzing a coredump, always prefer `maintenance info sections`
over `info proc sections`

Fixes #1154
2024-11-11 19:38:37 +01:00
crazy hugsy 3bdba586cb Prevent duplicate panes in context.layout (#1153)
## Description

Make sure panes added in `context.layout` have a unique name

Fixes #1145
2024-11-11 19:35:20 +01:00
crazy hugsy 0f21eea18c Python 3.10 improvements (#1139)
## Description

Follow-up PR for #1133 but purely esthetic, no functional changes

Cleans up the code to make it more in comformance with Python 3.10
capabilities.

Replaces:
 - type `Union` with `|`
 - type `Dict`/`Set`/`List`/`Tuple` with `dict`/`set`/`list`/`tuple`
 - `Optional` with ` | None`
 - `if:` ... `elif`... -> `match`

Fixes: 
 - `gdb.events.*Event` -> `gdb.*Event`
- `GefHeapManager.malloc_align_address` had its `ceil` lambda moved as a
proper (nested) function

Lint:
 - `except:` -> `except Exception:`
 - removed a bunch of unused f-strings
 - `if not .. in ..` -> `if .. not in ..`
 - some short named variables renamed
2024-11-10 20:05:29 +01:00
crazy hugsy 4dccd78686 Simplified clear_screen command (#1148)
## Description

Simplify `clear_screen` API  by sending directly the clear screen sequence to `sys.stdout` by default.
Fixes #1147
2024-11-10 10:52:34 -08:00
5376d78160 Use shutil when looking for executables on the host system (#1146)
## Description

The implementation of the `which` function only checks for the
executable flag on paths, which means it can return a directory (at
least on POSIX), causing weird permission errors down the line. It
should instead defer to `shutil.which`; that function contains a
platform-agnostic implementation that should hopefully match the
behavior of the GNU `which` utility.

Co-authored-by: Grazfather <[email protected]>
Co-authored-by: crazy hugsy <[email protected]>
2024-10-29 13:19:51 -07:00
ValekoZandGrazfather ba70548a3e [cmd] Add support for flags specifying filters type in vmmap, and allow multiple filters (#1120)
Parse args:
 - `-a` / `--addr`:
- filter by address -> parses the next arg as an int or asks gdb the
value
 - `-n` / `--name`:
   - filter based on section name
- If nothing is specified, print a warning and guess the type (previous
behavior)

---------

Co-authored-by: Grazfather <[email protected]>
2024-10-24 10:21:44 +02:00
Grazfather f9f80450dc Remove ksymaddr docs (now in gef-extras) (#1141)
Now in gef-extras. Moved docs in hugsy/gef-extras#118

Fixes #1140
2024-10-01 21:38:51 -07:00
ValekoZ d8a3043ed8 [memory] Fix read_cstring trying to read too far (#1112) 2024-09-29 13:17:16 -04:00
crazy hugsyandGrazfather 115137cc05 Move GEF to a Python 3.10 baseline (#1133)
## Description

Move GEF to a Python 3.10 baseline

Fixes #1132

---------

Co-authored-by: Grazfather <[email protected]>
2024-09-25 21:27:55 -07:00
arty-hlr f298b7fb27 [UI] Fixed color swap between heap/stack in vmmap legend (#1136)
## Description

There is a bug in how stack/heap addresses colors are shown in gdb using
the `vmmap` command. This PR fixes it.
2024-09-16 15:11:54 -07:00
FunnyBiu 674c74dbff Fix python unicode encoding problem when installing gef in non-ascii locale (#1127)
Force python to use utf-8 encoding when running the gef.sh script.
2024-08-05 18:41:02 -04:00
Gordon Messmer 89079354ae Fix remote use of gef.memory.maps (#1109)
## Description

This change passes both the "display" path and the local "real" path for each section or file to the print_got_for function in GotCommand. Without this change, the `got` command does not work properly in a remote debugging session.
2024-07-27 20:11:14 -07:00
crazy hugsy 22d3ab06f7 [CI] Add new runner: Ubuntu 2404 (#1115)
## Description

Add Ubuntu 24.04 as new runner.
Also fixed many mistakes in `tests.yml`, cache failure, and old use of deprecated actions
2024-07-27 14:12:05 -07:00
crazy hugsy d116cfb9f5 [License] 2023 -> 2024 (#1126)
## Description

Being in July 2024, I think it's fair to acknowledge 2024 isn't going
anywhere. So let's update the license
2024-07-27 13:49:59 -07:00
Zion Leonahenahe Basque d8c77235a4 Fix an incorrect scoped function call (introduced in #1093) (#1124)
```
Python Exception <class 'NameError'>: name 'add_context_layout_mapping' is not defined
Error occurred in Python: name 'add_context_layout_mapping' is not defined
```
2024-07-21 12:04:45 -04:00
ValekoZandcrazy hugsy 6ddd780445 [internal] Add a way to append values to optional arguments in parse_arguments decorator (#1122)
Add support for the `append` action for ArgumentParser in the `parse_arguments` decorator on optional arguments.

This makes us able to support this:

```
command --arg 1 --arg 2 --arg 3
```

And get `[1, 2, 3]` as the `arg` value.

This CL is required to make changes to
https://github.com/hugsy/gef/pull/1120 before merging.

---------

Co-authored-by: crazy hugsy <[email protected]>
2024-06-24 13:00:18 -07:00
ValekoZ c450a2d5fd Update arch command documentation (#1121) 2024-06-09 12:33:17 -07:00
crazy hugsy 0ca807ba21 Reload settings if gef-extras scripts were loaded (#1118) 2024-06-05 08:12:07 -07:00