From be82d554f1565d50e97bb82bc7cd2de5e8b0b14a Mon Sep 17 00:00:00 2001 From: crazy hugsy Date: Sat, 22 Oct 2022 12:52:22 -0700 Subject: [PATCH 01/11] [ci] dummy typo --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index ad252d54b..0f8fff04f 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -86,7 +86,7 @@ jobs: python${{ env.PY_VER }} -m pylint --rcfile=$(pwd)/.pylintrc gef.py tests/*/*.py - name: Run test coverage - if: matrix.os == 'ubuntu-2204' + if: matrix.os == 'ubuntu-22.04' run: | current_score=$(curl --silent https://hugsy.github.io/gef/coverage/gef_py.html | grep pc_cov | sed 's?.*\([^%]*\)%?\1?g') bash scripts/generate-coverage-docs.sh From 850a45d1134ed2a9c0ac240727fb19d244a4b79d Mon Sep 17 00:00:00 2001 From: crazy hugsy Date: Sat, 22 Oct 2022 13:01:22 -0700 Subject: [PATCH 02/11] [CI] Fixed incorrect coverage check --- .github/workflows/run-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 0f8fff04f..be215c41d 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -91,5 +91,5 @@ jobs: current_score=$(curl --silent https://hugsy.github.io/gef/coverage/gef_py.html | grep pc_cov | sed 's?.*\([^%]*\)%?\1?g') bash scripts/generate-coverage-docs.sh new_score=$(cat docs/coverage/gef_py.html | grep pc_cov | sed 's?.*\([^%]*\)%?\1?g') - echo "Test coverage score: ${new_score}% (current ${current_score}%)" - python${{ env.PY_VER }} -c "( ${new_score} < ${current_score} ) or exit(1)" + echo "New coverage score: ${new_score}% (current ${current_score}%)" + python${{ env.PY_VER }} -c "( ${new_score} >= ${current_score} ) or exit(1)" From 9edd73e1e23cd4afd785f385ef0dbdb270ab6e22 Mon Sep 17 00:00:00 2001 From: crazy hugsy Date: Tue, 25 Oct 2022 08:36:41 -0700 Subject: [PATCH 03/11] Update index.md Fixed dead link --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 1a2d44564..c32a7d3ae 100644 --- a/docs/index.md +++ b/docs/index.md @@ -37,7 +37,7 @@ GEF has no dependencies, is fully battery-included and works out of the box. You bash -c "$(curl -fsSL https://gef.blah.cat/sh)" ``` -For more details and other ways to install GEF please see [installation page](/docs/install.md). +For more details and other ways to install GEF please see [installation page](https://hugsy.github.io/gef/install/). ### Run From 50e54e0f360c4b9e7baec4e776a82dd4f92c55b7 Mon Sep 17 00:00:00 2001 From: crazy hugsy Date: Mon, 7 Nov 2022 21:32:31 -0800 Subject: [PATCH 04/11] [ci] restored `pytest-forked` in requirements for tests, removed old style envvar --- .github/workflows/run-tests.yml | 29 +++++++++-------------------- tests/requirements.txt | 1 + 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index be215c41d..a2fef92d0 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -26,7 +26,7 @@ jobs: shell: bash steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Install python and toolchain run: | @@ -37,27 +37,18 @@ jobs: - name: Set runtime environment variables run: | echo PY_VER=`gdb -q -nx -ex "pi print('.'.join(map(str, sys.version_info[:2])))" -ex quit` >> $GITHUB_ENV - echo NB_CPU=`grep -c ^processor /proc/cpuinfo` >> $GITHUB_ENV - - - name: Set architecture specific properties - id: set-arch-properties - run: | - echo "::set-output name=arch::$(uname --processor)" - - - name: Get pip cache dir - id: pip-cache - run: | - echo "::set-output name=dir::$(python3 -m pip cache dir)" + echo GEF_CI_NB_CPU=`grep -c ^processor /proc/cpuinfo` >> $GITHUB_ENV + echo GEF_CI_ARCH=`uname --processor` >> $GITHUB_ENV + echo GEF_CI_CACHE_DIR=`python3 -m pip cache dir` >> $GITHUB_ENV - name: Cache dependencies - uses: actions/cache@v2 + uses: actions/cache@v3 id: cache-deps env: cache-name: cache-deps with: key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} - path: | - ${{ steps.pip-cache.outputs.dir }} + path: ${{ env.GEF_CI_CACHE_DIR }} restore-keys: ${{ runner.os }}-pip-${{ env.cache-name }}- ${{ runner.os }}-pip- @@ -66,7 +57,7 @@ jobs: - name: Install Python Requirements run: | - mkdir -p ${{ steps.pip-cache.outputs.dir }} + mkdir -p ${{ env.GEF_CI_CACHE_DIR }} python${{ env.PY_VER }} -m pip install --user --upgrade -r tests/requirements.txt - name: Setup GEF @@ -75,11 +66,9 @@ jobs: gdb -q -ex 'gef missing' -ex 'gef help' -ex 'gef config' -ex start -ex continue -ex quit /bin/pwd - name: Run Tests - env: - GEF_CI_ARCH: ${{ steps.set-arch-properties.outputs.arch }} run: | - make -C tests/binaries -j ${{ env.NB_CPU }} - python${{ env.PY_VER }} -m pytest --forked -n ${{ env.NB_CPU }} -v -k "not benchmark" tests/ + make -C tests/binaries -j ${{ env.GEF_CI_NB_CPU }} + python${{ env.PY_VER }} -m pytest --forked -n ${{ env.GEF_CI_NB_CPU }} -v -k "not benchmark" tests/ - name: Run linter run: | diff --git a/tests/requirements.txt b/tests/requirements.txt index 54cf60dda..c43a1571a 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -3,4 +3,5 @@ pytest pytest-cov pytest-xdist pytest-benchmark +pytest-forked coverage From a1b4f009eb0fc8c19f8c6652997fb03d27b97a33 Mon Sep 17 00:00:00 2001 From: crazy hugsy Date: Mon, 7 Nov 2022 22:01:29 -0800 Subject: [PATCH 05/11] [ci] added a margin for the coverage reduction test --- .github/workflows/run-tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a2fef92d0..5d10553dd 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -76,9 +76,11 @@ jobs: - name: Run test coverage if: matrix.os == 'ubuntu-22.04' + env: + ALLOWED_MARGIN: 0.05 run: | current_score=$(curl --silent https://hugsy.github.io/gef/coverage/gef_py.html | grep pc_cov | sed 's?.*\([^%]*\)%?\1?g') bash scripts/generate-coverage-docs.sh new_score=$(cat docs/coverage/gef_py.html | grep pc_cov | sed 's?.*\([^%]*\)%?\1?g') echo "New coverage score: ${new_score}% (current ${current_score}%)" - python${{ env.PY_VER }} -c "( ${new_score} >= ${current_score} ) or exit(1)" + python${{ env.PY_VER }} -c "( ${new_score} < ( ${current_score} - ${{ env.ALLOWED_MARGIN}} ) ) and exit(1)" From 65eece71f4acaecfc9f3b49258b7cb8390d685e7 Mon Sep 17 00:00:00 2001 From: Grazfather Date: Tue, 8 Nov 2022 01:06:53 -0500 Subject: [PATCH 06/11] reset_architecture: Return after setting arch to a specified arch (#914) --- gef.py | 1 + 1 file changed, 1 insertion(+) diff --git a/gef.py b/gef.py index 2159038a4..a9242d985 100644 --- a/gef.py +++ b/gef.py @@ -3618,6 +3618,7 @@ def reset_architecture(arch: Optional[str] = None) -> None: gef.arch = arches[arch]() except KeyError: raise OSError(f"Specified arch {arch.upper()} is not supported") + return gdb_arch = get_arch() From b52b758c5af6fb7759063645bcfb0242e5010ce9 Mon Sep 17 00:00:00 2001 From: Ananthu Date: Tue, 8 Nov 2022 11:38:12 +0530 Subject: [PATCH 07/11] Added support for GDBHISTFILE env variable (#912) --- gef.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gef.py b/gef.py index a9242d985..37efa6572 100644 --- a/gef.py +++ b/gef.py @@ -10850,7 +10850,7 @@ def reset_caches(self) -> None: "set pagination off", "set print elements 0", "set history save on", - "set history filename ~/.gdb_history", + f"set history filename {os.getenv('GDBHISTFILE', '~/.gdb_history')}", "set output-radix 0x10", "set print pretty on", "set disassembly-flavor intel", From c05d62a560284380d93850c5d4f17d03aeb47439 Mon Sep 17 00:00:00 2001 From: Boris-Chengbiao Zhou Date: Tue, 8 Nov 2022 07:09:36 +0100 Subject: [PATCH 08/11] Fix test command in documentation (#908) --- docs/testing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/testing.md b/docs/testing.md index 65c841096..29273d2c5 100644 --- a/docs/testing.md +++ b/docs/testing.md @@ -23,7 +23,7 @@ For testing GEF on the architecture on the host running the tests (most cases), ```bash cd /root/of/gef -python3 -m pytest -v -k not benchmark +python3 -m pytest -v -k "not benchmark" tests ``` Note that to ensure compatibility, tests must be executed with the same Python version GDB was compiled against. To obtain this version, you can execute the following command: From ea8273b032284b451f25094931a7942a3176ffa8 Mon Sep 17 00:00:00 2001 From: Jonathan Salwan Date: Tue, 8 Nov 2022 07:12:06 +0100 Subject: [PATCH 09/11] Fix shell-storm new API (#902) * Fix shell-storm new API * Update gef.py Co-authored-by: Grazfather --- gef.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gef.py b/gef.py index 37efa6572..c403c1466 100644 --- a/gef.py +++ b/gef.py @@ -6773,7 +6773,7 @@ class ShellcodeGetCommand(GenericCommand): _aliases_ = ["sc-get",] api_base = "http://shell-storm.org" - get_url = f"{api_base}/shellcode/files/shellcode-{{:d}}.php" + get_url = f"{api_base}/shellcode/files/shellcode-{{:d}}.html" def do_invoke(self, argv: List[str]) -> None: if len(argv) != 1: @@ -6799,7 +6799,7 @@ def get_shellcode(self, sid: int) -> None: ok("Downloaded, written to disk...") tempdir = gef.config["gef.tempdir"] fd, fname = tempfile.mkstemp(suffix=".txt", prefix="sc-", text=True, dir=tempdir) - shellcode = res.splitlines()[7:-11] + shellcode = res.split("
")[1].split("
")[0] shellcode = b"\n".join(shellcode).replace(b""", b'"') os.write(fd, shellcode) os.close(fd) From ec83f445b7e8597616fbe6900d4c63f572cdabff Mon Sep 17 00:00:00 2001 From: crazy hugsy Date: Mon, 7 Nov 2022 22:39:37 -0800 Subject: [PATCH 10/11] fixed error from #902 --- gef.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/gef.py b/gef.py index c403c1466..a00386ea0 100644 --- a/gef.py +++ b/gef.py @@ -1298,7 +1298,7 @@ def malloc_state_t() -> Type[ctypes.Structure]: # https://elixir.bootlin.com/glibc/glibc-2.23/source/malloc/malloc.c#L1719 fields += [ ("attached_threads", pointer) - ] + ] fields += [ ("system_mem", pointer), ("max_system_mem", pointer), @@ -1586,7 +1586,7 @@ def get_next_chunk(self, allow_unaligned: bool = False) -> "GlibcChunk": def get_next_chunk_addr(self) -> int: return self.data_address + self.size - + def has_p_bit(self) -> bool: return bool(self.flags & GlibcChunk.ChunkFlags.PREV_INUSE) @@ -1683,7 +1683,7 @@ def reveal_ptr(self, pointer: int) -> int: return gef.memory.read_integer(pointer) ^ (pointer >> 12) class GlibcTcacheChunk(GlibcFastChunk): - + pass @@ -6797,13 +6797,11 @@ def get_shellcode(self, sid: int) -> None: return ok("Downloaded, written to disk...") - tempdir = gef.config["gef.tempdir"] - fd, fname = tempfile.mkstemp(suffix=".txt", prefix="sc-", text=True, dir=tempdir) - shellcode = res.split("
")[1].split("
")[0] - shellcode = b"\n".join(shellcode).replace(b""", b'"') - os.write(fd, shellcode) - os.close(fd) - ok(f"Shellcode written to '{fname}'") + with tempfile.NamedTemporaryFile(prefix="sc-", suffix=".txt", mode='w+b', delete=False, dir=gef.config["gef.tempdir"]) as fd: + shellcode = res.split(b"
")[1].split(b"
")[0] + shellcode = shellcode.replace(b""", b'"') + fd.write(shellcode) + ok(f"Shellcode written to '{fd.name}'") return From 1bf74a82a779ea7dd1d94f4fd2475520f5912536 Mon Sep 17 00:00:00 2001 From: crazy hugsy Date: Mon, 7 Nov 2022 22:54:08 -0800 Subject: [PATCH 11/11] [CI] Refusing anything below 70% of coverage --- .github/workflows/run-tests.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 5d10553dd..8e207afd3 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -78,9 +78,11 @@ jobs: if: matrix.os == 'ubuntu-22.04' env: ALLOWED_MARGIN: 0.05 + MIN_COVERAGE: 70 run: | current_score=$(curl --silent https://hugsy.github.io/gef/coverage/gef_py.html | grep pc_cov | sed 's?.*\([^%]*\)%?\1?g') bash scripts/generate-coverage-docs.sh new_score=$(cat docs/coverage/gef_py.html | grep pc_cov | sed 's?.*\([^%]*\)%?\1?g') echo "New coverage score: ${new_score}% (current ${current_score}%)" - python${{ env.PY_VER }} -c "( ${new_score} < ( ${current_score} - ${{ env.ALLOWED_MARGIN}} ) ) and exit(1)" + python${{ env.PY_VER }} -c "( ${new_score} < ${{ env.MIN_COVERAGE}} ) and exit(1)" + python${{ env.PY_VER }} -c "( ${new_score} < ( ${current_score} - ${{ env.ALLOWED_MARGIN}} ) ) and exit(2)"