Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Py3k

* Dont run py2 on CI

* Don't launch futurize on CI

* Move to latest isort options

* Modernize imports (isort>=5)

* Fix removed jump dir
  • Loading branch information
disconnect3d authored Aug 15, 2020
1 parent ccd8f76 commit 301012a
Show file tree
Hide file tree
Showing 154 changed files with 56 additions and 821 deletions.
11 changes: 2 additions & 9 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,18 @@ jobs:
path: ~/.cache/pip
key: ${{ matrix.os }}-cache-pip

- name: Set up Python 2.7
uses: actions/setup-python@v1
with:
python-version: 2.7

- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8

- name: Install linters
run: |
pip install isort future
pip install isort
- name: Run tests
run: |
futurize --all-imports --stage1 --print-function --write --unicode-literals pwndbg tests
git diff-index --quiet HEAD -- pwndbg tests
isort --check-only --diff --recursive pwndbg tests
python2.7 -m py_compile ida_script.py $(git ls-files 'pwndbg/*.py')
isort --check-only --diff pwndbg tests
python3 -m py_compile $(git ls-files 'pwndbg/*.py')
1 change: 0 additions & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[settings]
indent=' '
not_skip = __init__.py
force_single_line = 1
known_third_party=capstone,unicorn,six,psutil,pycparser,gdb
2 changes: 0 additions & 2 deletions DEVELOPING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ Feel free to update the list below!

* Process properties can be retrieved thx to `pwndbg/proc.py` - e.g. using `pwndbg.proc.pid` will give us current process pid

* We have an inthook to make it easier to work with Python 2 and gdb.Value objects - see the docstring in `pwndbg/inthook.py` . Specifically, it makes it so that you can call `int()` on a `gdb.Value` instance and get what you want.

* We have a wrapper for handling exceptions that are thrown by commands - defined in `pwndbg/exception.py` - current approach seems to work fine - by using `set exception-verbose on` - we get a stacktrace. If we want to debug stuff we can always do `set exception-debugger on`.

* Some of pwndbg's functionality - e.g. memory fetching - require us to have an instance of proper `gdb.Type` - the problem with that is that there is no way to define our own types - we have to ask gdb if it detected particular type in this particular binary (that sucks). We do it in `pwndbg/typeinfo.py` and it works most of the time. The known bug with that is that it might not work properly for Golang binaries compiled with debugging symbols.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pwndbg [![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://github.com/pwndbg/pwndbg/blob/dev/LICENSE.md) [![Py2&3](https://img.shields.io/badge/Python-2%20%26%203-green.svg)]() [![IRC](https://img.shields.io/badge/freenode-%23pwndbg-red.svg)](https://webchat.freenode.net/?channels=#pwndbg)
# pwndbg [![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://github.com/pwndbg/pwndbg/blob/dev/LICENSE.md) [![IRC](https://img.shields.io/badge/freenode-%23pwndbg-red.svg)](https://webchat.freenode.net/?channels=#pwndbg)

`pwndbg` (/poʊndbæg/) is a GDB plug-in that makes debugging with GDB suck less, with a focus on features needed by low-level software developers, hardware hackers, reverse-engineers and exploit developers.

Expand Down
16 changes: 2 additions & 14 deletions gdbinit.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,19 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals

import locale
import sys
from os import path

import six

directory, file = path.split(__file__)
directory = path.expanduser(directory)
directory = path.abspath(directory)

sys.path.append(directory)

# this is an unconventional workaround to
# support unicode printing for python2
# https://github.com/pwndbg/pwndbg/issues/117
# on python3 it warns if the user has different
# encoding than utf-8
# warn if the user has different encoding than utf-8
encoding = locale.getpreferredencoding()
if six.PY2:
reload(sys)
sys.setdefaultencoding('utf-8')

elif encoding != 'UTF-8':
if encoding != 'UTF-8':
print('******')
print('Your encoding ({}) is different than UTF-8. pwndbg might not work properly.'.format(encoding))
print('You might try launching gdb with:')
Expand Down
7 changes: 1 addition & 6 deletions pwndbg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import signal

import gdb
Expand Down Expand Up @@ -68,7 +63,6 @@
import pwndbg.exception
import pwndbg.gdbutils.functions
import pwndbg.heap
import pwndbg.inthook
import pwndbg.memory
import pwndbg.net
import pwndbg.proc
Expand All @@ -88,6 +82,7 @@

try:
import unicorn

import pwndbg.emu
except:
pass
Expand Down
7 changes: 1 addition & 6 deletions pwndbg/abi.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import functools
import re

Expand All @@ -13,7 +8,7 @@
import pwndbg.color.message as M


class ABI(object):
class ABI:
"""
Encapsulates information about a calling convention.
"""
Expand Down
5 changes: 0 additions & 5 deletions pwndbg/android.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import gdb

import pwndbg.color.message as message
Expand Down
9 changes: 0 additions & 9 deletions pwndbg/arch.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import struct
import sys

Expand Down Expand Up @@ -66,10 +61,6 @@ def update():
(8, 'big'): '>Q',
}.get((m.ptrsize, m.endian))

# Work around Python 2.7.6 struct.pack / unicode incompatibility
# See https://github.com/pwndbg/pwndbg/pull/336 for more information.
m.fmt = str(m.fmt)

# Attempt to detect the qemu-user binary name
if m.current == 'arm' and m.endian == 'big':
m.qemu = 'armeb'
Expand Down
5 changes: 0 additions & 5 deletions pwndbg/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
Allows describing functions, specifically enumerating arguments which
may be passed in a combination of registers and stack values.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import gdb
from capstone import CS_GRP_CALL
from capstone import CS_GRP_INT
Expand Down
4 changes: 0 additions & 4 deletions pwndbg/argv.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import gdb

Expand Down
4 changes: 0 additions & 4 deletions pwndbg/auxv.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import os
import re
Expand Down
4 changes: 0 additions & 4 deletions pwndbg/chain.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import gdb

Expand Down
4 changes: 0 additions & 4 deletions pwndbg/color/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import os
import re
Expand Down
4 changes: 0 additions & 4 deletions pwndbg/color/backtrace.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import pwndbg.color.theme as theme
import pwndbg.config as config
Expand Down
4 changes: 0 additions & 4 deletions pwndbg/color/chain.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import pwndbg.color.theme as theme
import pwndbg.config as config
Expand Down
4 changes: 0 additions & 4 deletions pwndbg/color/context.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import pwndbg.color.theme as theme
import pwndbg.config as config
Expand Down
4 changes: 0 additions & 4 deletions pwndbg/color/disasm.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import capstone

Expand Down
4 changes: 0 additions & 4 deletions pwndbg/color/enhance.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import pwndbg.color.theme as theme
import pwndbg.config as config
Expand Down
4 changes: 0 additions & 4 deletions pwndbg/color/hexdump.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import pwndbg.color.theme as theme
import pwndbg.config as config
Expand Down
23 changes: 0 additions & 23 deletions pwndbg/color/lexer.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import re

import six
from pygments.lexer import RegexLexer
from pygments.lexer import include
from pygments.token import Comment
Expand Down Expand Up @@ -116,20 +110,3 @@ class PwntoolsLexer(RegexLexer):
(r'[-*,.():]+', Punctuation)
]
}

# Note: convert all unicode() to str() if in Python2.7 since unicode_literals is enabled
# The pygments<=2.2.0 (latest stable when commit) in Python2.7 use 'str' type in rules matching
# We must convert all unicode back to str()
if six.PY2:
def _to_str(obj):
type_ = type(obj)
if type_ in (tuple, list):
return type_(map(_to_str, obj))
elif type_ is unicode:
return str(obj)
return obj

PwntoolsLexer.tokens = {
_to_str(k): _to_str(v)
for k, v in PwntoolsLexer.tokens.iteritems()
}
9 changes: 1 addition & 8 deletions pwndbg/color/memory.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import six

import pwndbg.color.theme as theme
import pwndbg.config as config
import pwndbg.vmmap
Expand Down Expand Up @@ -62,7 +55,7 @@ def get(address, text = None):
old_color = color
color = lambda x: rwx(old_color(x))

if text is None and isinstance(address, six.integer_types) and address > 255:
if text is None and isinstance(address, int) and address > 255:
text = hex(int(address))
if text is None:
text = str(int(address))
Expand Down
4 changes: 0 additions & 4 deletions pwndbg/color/message.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from pwndbg import config
from pwndbg.color import generateColorFunction
Expand Down
4 changes: 0 additions & 4 deletions pwndbg/color/nearpc.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import pwndbg.color.theme as theme
import pwndbg.config as config
Expand Down
7 changes: 2 additions & 5 deletions pwndbg/color/syntax_highlight.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import itertools
import os.path
Expand All @@ -15,8 +11,9 @@

try:
import pygments
import pygments.lexers
import pygments.formatters
import pygments.lexers

from pwndbg.color.lexer import PwntoolsLexer
except ImportError:
pygments = None
Expand Down
4 changes: 0 additions & 4 deletions pwndbg/color/telescope.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import pwndbg.color.theme as theme
import pwndbg.config as config
Expand Down
4 changes: 0 additions & 4 deletions pwndbg/color/theme.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import pwndbg.config

Expand Down
Loading

0 comments on commit 301012a

Please sign in to comment.