From ce96491487a1405544902e3a9a1eb7b999b58b72 Mon Sep 17 00:00:00 2001 From: StalkR Date: Fri, 31 May 2019 07:09:08 +0000 Subject: [PATCH] typeinfo: more types for golang and tests (#652) --- pwndbg/typeinfo.py | 12 ++++++------ tests/binaries/gosample.x64.go | 3 +++ tests/binaries/gosample.x86.go | 3 +++ tests/binaries/makefile | 19 +++++++++++++++++-- tests/test_go.py | 33 +++++++++++++++++++++++++++++++++ 5 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 tests/binaries/gosample.x64.go create mode 100644 tests/binaries/gosample.x86.go create mode 100644 tests/test_go.py diff --git a/pwndbg/typeinfo.py b/pwndbg/typeinfo.py index 92e619373..40afe32a0 100644 --- a/pwndbg/typeinfo.py +++ b/pwndbg/typeinfo.py @@ -49,20 +49,20 @@ def lookup_types(*types): def update(): module.char = gdb.lookup_type('char') - module.ulong = lookup_types('unsigned long', 'uint', 'u32') - module.long = lookup_types('long', 'int', 'i32') - module.uchar = lookup_types('unsigned char', 'ubyte', 'u8') + module.ulong = lookup_types('unsigned long', 'uint', 'u32', 'uint32') + module.long = lookup_types('long', 'int', 'i32', 'int32') + module.uchar = lookup_types('unsigned char', 'ubyte', 'u8', 'uint8') module.ushort = lookup_types('unsigned short', 'ushort', 'u16', 'uint16') - module.uint = lookup_types('unsigned int', 'uint', 'u32') + module.uint = lookup_types('unsigned int', 'uint', 'u32', 'uint32') module.void = lookup_types('void', '()') module.uint8 = module.uchar module.uint16 = module.ushort module.uint32 = module.uint module.uint64 = lookup_types('unsigned long long', 'ulong', 'u64', 'uint64') - module.int8 = lookup_types('char', 'i8') + module.int8 = lookup_types('char', 'i8', 'int8') module.int16 = lookup_types('short', 'i16', 'int16') - module.int32 = lookup_types('int', 'i32') + module.int32 = lookup_types('int', 'i32', 'int32') module.int64 = lookup_types('long long', 'long', 'i64', 'int64') module.ssize_t = module.long diff --git a/tests/binaries/gosample.x64.go b/tests/binaries/gosample.x64.go new file mode 100644 index 000000000..38dd16da6 --- /dev/null +++ b/tests/binaries/gosample.x64.go @@ -0,0 +1,3 @@ +package main + +func main() {} diff --git a/tests/binaries/gosample.x86.go b/tests/binaries/gosample.x86.go new file mode 100644 index 000000000..38dd16da6 --- /dev/null +++ b/tests/binaries/gosample.x86.go @@ -0,0 +1,3 @@ +package main + +func main() {} diff --git a/tests/binaries/makefile b/tests/binaries/makefile index 8b5e2c7b6..5772f26f9 100644 --- a/tests/binaries/makefile +++ b/tests/binaries/makefile @@ -14,6 +14,10 @@ LDFLAGS = EXTRA_FLAGS = EXTRA_FLAGS_ASM = +GO = go +SOURCES_GO = $(wildcard *.go) +COMPILED_GO = $(SOURCES_GO:.go=) + ifeq ($(TARGET), x86) CFLAGS += -m32 endif @@ -27,7 +31,7 @@ endif .PHONY : all clean -all: $(LINKED) $(LINKED_ASM) +all: $(LINKED) $(LINKED_ASM) $(COMPILED_GO) %.out : %.c @@ -42,9 +46,20 @@ all: $(LINKED) $(LINKED_ASM) @echo "[+] Linking '$@'" @$(LD) -o $@ $? +%.x86 : %.x86.go + @echo "[+] Building '$@'" + @GOARCH=386 $(GO) build $? + @# Not stripped on purpose + +%.x64 : %.x64.go + @echo "[+] Building '$@'" + @GOARCH=amd64 $(GO) build $? + @# Not stripped on purpose + + clean : @echo "[+] Cleaning stuff" - @rm -f $(COMPILED) $(LINKED) + @rm -f $(COMPILED) $(LINKED) $(COMPILED_GO) reference-binary.out: EXTRA_FLAGS := -Dexample=1 diff --git a/tests/test_go.py b/tests/test_go.py new file mode 100644 index 000000000..ed95ba72a --- /dev/null +++ b/tests/test_go.py @@ -0,0 +1,33 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function +from __future__ import unicode_literals + +import gdb + +import tests + +GOSAMPLE_X64 = tests.binaries.get('gosample.x64') +GOSAMPLE_X86 = tests.binaries.get('gosample.x86') + + +def test_typeinfo_go_x64(start_binary): + """ + Tests pwndbg's typeinfo knows about the Go x64 types. + Catches: Python Exception No type named u8.: + Test catches the issue only if the binaries are not stripped. + """ + gdb.execute('file ' + GOSAMPLE_X64) + start = gdb.execute('start', to_string=True) + assert 'Python Exception' not in start + + +def test_typeinfo_go_x86(start_binary): + """ + Tests pwndbg's typeinfo knows about the Go x32 types + Catches: Python Exception No type named u8.: + Test catches the issue only if the binaries are not stripped. + """ + gdb.execute('file ' + GOSAMPLE_X86) + start = gdb.execute('start', to_string=True) + assert 'Python Exception' not in start