Skip to content

Commit

Permalink
Rename module to pwndbg
Browse files Browse the repository at this point in the history
  • Loading branch information
zachriggle committed Mar 10, 2015
1 parent 2c844f2 commit 27180e0
Show file tree
Hide file tree
Showing 46 changed files with 499 additions and 346 deletions.
31 changes: 30 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,33 @@ Currently it works on GDB with Python3.

\* Lots of use of `gdb.event` to manage cache lifetimes.
\*\* Automatic exploration of process maps when you're doing e.g. remote debugging
of a QEMU user stub and `/proc/$$/pids` is broken for `${reasons}`.
of a QEMU user stub and `/proc/$$/pids` is broken for `${reasons}`.


Snazzy features which may not work:


### Type Printing

Hurray windbg. This works without any loaded symbols, and is architecture-appropriate.

```
geef> show arch
The target architecture is set automatically (currently i386:x86-64)
geef> dt hostent
hostent
+0x0000 h_name : char *
+0x0008 h_aliases : char **
+0x0010 h_addrtype : int
+0x0014 h_length : int
+0x0018 h_addr_list : char **
geef> dt passwd
passwd
+0x0000 pw_name : char *
+0x0008 pw_passwd : char *
+0x0010 pw_uid : __uid_t
+0x0014 pw_gid : __gid_t
+0x0018 pw_gecos : char *
+0x0020 pw_dir : char *
+0x0028 pw_shell : char *
```
2 changes: 1 addition & 1 deletion gdbinit.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

sys.path.append(directory)

import gef
import pwndbg

10 changes: 0 additions & 10 deletions gef/commands/dt.py

This file was deleted.

19 changes: 0 additions & 19 deletions gef/commands/hexdump.py

This file was deleted.

5 changes: 0 additions & 5 deletions gef/commands/windbg.py

This file was deleted.

28 changes: 14 additions & 14 deletions gef/__init__.py → pwndbg/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import gdb
import gef.arch
import gef.vmmap
import gef.dt
import gef.memory
import gef.elf
import gef.proc
import gef.regs
import gef.stack
import gef.commands
import gef.commands.hexdump
import gef.commands.context
import gef.commands.telescope
import gef.commands.vmmap
import gef.commands.dt
import pwndbg.arch
import pwndbg.vmmap
import pwndbg.dt
import pwndbg.memory
import pwndbg.elf
import pwndbg.proc
import pwndbg.regs
import pwndbg.stack
import pwndbg.commands
import pwndbg.commands.hexdump
import pwndbg.commands.context
import pwndbg.commands.telescope
import pwndbg.commands.vmmap
import pwndbg.commands.dt


pre_commands = """
Expand Down
14 changes: 7 additions & 7 deletions gef/arch.py → pwndbg/arch.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import struct
import sys
import gdb
import gef.memoize
import gef.events
import gef.types
import pwndbg.memoize
import pwndbg.events
import pwndbg.types

current = None
ptrmask = 0xfffffffff
endian = 'little'
ptrsize = gef.types.ptrsize
ptrsize = pwndbg.types.ptrsize
fmt = '=i'

@gef.events.stop
@pwndbg.events.stop
def update():
m = sys.modules[__name__]

m.current = gdb.selected_frame().architecture().name()
m.ptrsize = gef.types.ptrsize
m.ptrmask = (1 << 8*gef.types.ptrsize)-1
m.ptrsize = pwndbg.types.ptrsize
m.ptrmask = (1 << 8*pwndbg.types.ptrsize)-1

if 'little' in gdb.execute('show endian', to_string=True):
m.endian = 'little'
Expand Down
20 changes: 10 additions & 10 deletions gef/auxv.py → pwndbg/auxv.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import gdb

import gef.events
import gef.info
import gef.regs
import gef.types
import pwndbg.events
import pwndbg.info
import pwndbg.regs
import pwndbg.types

example_info_auxv_linux = """
33 AT_SYSINFO_EHDR System-supplied DSO's ELF header 0x7ffff7ffa000
Expand Down Expand Up @@ -69,7 +69,7 @@ def set(self, const, value):
name = AT_CONSTANTS.get(const, "AT_UNKNOWN%i" % const)

if name in ['AT_EXECFN', 'AT_PLATFORM']:
value = gdb.Value(value).cast(gef.types.pchar).string()
value = gdb.Value(value).cast(pwndbg.types.pchar).string()

setattr(self, name, value)
def __str__(self):
Expand All @@ -80,7 +80,7 @@ def __str__(self):
rv[attr] = value
return str(rv)

@gef.memoize.reset_on_objfile
@pwndbg.memoize.reset_on_objfile
def get():
return use_info_auxv() or walk_stack() or AUXV()

Expand All @@ -107,7 +107,7 @@ def use_info_auxv():
0 AT_NULL End of vector 0x0
"""

lines = gef.info.auxv().splitlines()
lines = pwndbg.info.auxv().splitlines()

if not lines:
return None
Expand All @@ -126,15 +126,15 @@ def use_info_auxv():


def walk_stack():
sp = gef.regs.sp
sp = pwndbg.regs.sp

print("BAD SP")

if not sp:
return None

end = gef.memory.find_upper_boundary(sp)
p = gdb.Value(end).cast(gef.types.ulong.pointer())
end = pwndbg.memory.find_upper_boundary(sp)
p = gdb.Value(end).cast(pwndbg.types.ulong.pointer())

# So we don't walk off the end of the stack
p -= 2
Expand Down
16 changes: 8 additions & 8 deletions gef/chain.py → pwndbg/chain.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import gdb
import gef.color
import gef.enhance
import gef.memory
import gef.types
import gef.vmmap
import pwndbg.color
import pwndbg.enhance
import pwndbg.memory
import pwndbg.types
import pwndbg.vmmap


def get(address, limit=5):
Expand All @@ -17,7 +17,7 @@ def get(address, limit=5):
for i in range(limit):
result.append(address)
try:
address = int(gef.memory.poi(gef.types.ppvoid, address))
address = int(pwndbg.memory.poi(pwndbg.types.ppvoid, address))
except gdb.MemoryError:
break

Expand All @@ -28,9 +28,9 @@ def format(value):
chain = get(value)

# Enhance the last entry
end = [gef.enhance.enhance(chain[-1])]
end = [pwndbg.enhance.enhance(chain[-1])]

# Colorize the rest
rest = list(map(gef.color.get, chain[:-1]))
rest = list(map(pwndbg.color.get, chain[:-1]))

return ' --> '.join(rest + end)
4 changes: 2 additions & 2 deletions gef/color.py → pwndbg/color.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import gdb
import gef.vmmap
import pwndbg.vmmap

NORMAL = "\x1b[0m"
BLACK = "\x1b[30m"
Expand Down Expand Up @@ -36,7 +36,7 @@ def get(address, text = None):
text(str): Optional text to use in place of the address
in the return value string.
"""
page = gef.vmmap.find(int(address))
page = pwndbg.vmmap.find(int(address))

if page is None: color = NORMAL
elif '[stack' in page.objfile: color = STACK
Expand Down
24 changes: 12 additions & 12 deletions gef/commands/__init__.py → pwndbg/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import traceback
import gdb

import gef.regs
import gef.memory
import gef.hexdump
import gef.color
import gef.chain
import gef.enhance
import gef.symbol
import gef.ui
import gef.proc
import pwndbg.regs
import pwndbg.memory
import pwndbg.hexdump
import pwndbg.color
import pwndbg.chain
import pwndbg.enhance
import pwndbg.symbol
import pwndbg.ui
import pwndbg.proc

debug = True

Expand All @@ -29,7 +29,7 @@ def invoke(self, argument, from_tty):
pass

try:
arg = gef.regs.fix(arg)
arg = pwndbg.regs.fix(arg)
argv[i] = gdb.parse_and_eval(arg)
except Exception:
pass
Expand All @@ -46,7 +46,7 @@ def __call__(self, *args):
def OnlyWhenRunning(func):
def wrapper(*a):
func.__doc__
if not gef.proc.alive:
if not pwndbg.proc.alive:
pass
else:
func(*a)
Expand All @@ -61,7 +61,7 @@ def searchmem(searchfor):

if isinstance(searchfor, gdb.Value):
try:
searchfor = gef.memory.read(searchfor.address, searchfor.sizeof)
searchfor = pwndbg.memory.read(searchfor.address, searchfor.sizeof)
except:
searchfor = 0
print(searchfor)
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 27180e0

Please sign in to comment.