Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:hugsy/gef into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
hugsy committed Nov 11, 2022
2 parents e48e2f3 + 1bf74a8 commit 8713e3f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 24 deletions.
23 changes: 13 additions & 10 deletions .github/workflows/run-tests.yml
Expand Up @@ -37,9 +37,9 @@ 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
echo GEF_CI_NB_CPU=`grep -c ^processor /proc/cpuinfo` >> $GITHUB_ENV
echo GEF_CI_ARCH=`uname --processor` >> $GITHUB_ENV
echo GEF_CACHE_DIR=`python3 -m pip cache dir` >> $GITHUB_ENV
echo GEF_CI_CACHE_DIR=`python3 -m pip cache dir` >> $GITHUB_ENV
- name: Cache dependencies
uses: actions/cache@v3
Expand All @@ -48,8 +48,7 @@ jobs:
cache-name: cache-deps
with:
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
path: |
${{ env.GEF_CACHE_DIR }}
path: ${{ env.GEF_CI_CACHE_DIR }}
restore-keys:
${{ runner.os }}-pip-${{ env.cache-name }}-
${{ runner.os }}-pip-
Expand All @@ -58,7 +57,7 @@ jobs:

- name: Install Python Requirements
run: |
mkdir -p ${{ env.GEF_CACHE_DIR }}
mkdir -p ${{ env.GEF_CI_CACHE_DIR }}
python${{ env.PY_VER }} -m pip install --user --upgrade -r tests/requirements.txt
- name: Setup GEF
Expand All @@ -68,18 +67,22 @@ jobs:
- name: Run Tests
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: |
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'
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?.*<span class="pc_cov">\([^%]*\)%</span>?\1?g')
bash scripts/generate-coverage-docs.sh
new_score=$(cat docs/coverage/gef_py.html | grep pc_cov | sed 's?.*<span class="pc_cov">\([^%]*\)%</span>?\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} < ${{ env.MIN_COVERAGE}} ) and exit(1)"
python${{ env.PY_VER }} -c "( ${new_score} < ( ${current_score} - ${{ env.ALLOWED_MARGIN}} ) ) and exit(2)"
2 changes: 1 addition & 1 deletion docs/index.md
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/testing.md
Expand Up @@ -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:
Expand Down
23 changes: 11 additions & 12 deletions gef.py
Expand Up @@ -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),
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -1683,7 +1683,7 @@ def reveal_ptr(self, pointer: int) -> int:
return gef.memory.read_integer(pointer) ^ (pointer >> 12)

class GlibcTcacheChunk(GlibcFastChunk):

pass


Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -6772,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:
Expand All @@ -6796,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.splitlines()[7:-11]
shellcode = b"\n".join(shellcode).replace(b"&quot;", 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"<pre>")[1].split(b"</pre>")[0]
shellcode = shellcode.replace(b"&quot;", b'"')
fd.write(shellcode)
ok(f"Shellcode written to '{fd.name}'")
return


Expand Down Expand Up @@ -10849,7 +10848,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",
Expand Down
1 change: 1 addition & 0 deletions tests/requirements.txt
Expand Up @@ -3,4 +3,5 @@ pytest
pytest-cov
pytest-xdist
pytest-benchmark
pytest-forked
coverage

0 comments on commit 8713e3f

Please sign in to comment.