mirror of https://github.com/pwndbg/pwndbg.git
Fix nearpc following jumps when used w/o emulation (#499)
* Tests launcher: show passed and failed count * Build nearpc, emulate, u, pdisass test binaries * Add tests for emulate, nearpc, pdisass, u * Refactored disasm and emulator * Fix nearpc following jumps w/o emulation * Prevent tests from calling start_binary twice * Add test for emulate_disasm_loop * Fix isort * Add nasm to travis install * Add --eval-command quit to tests invocation This should prevent travis from staying in gdb/stalled build when something fails in weird way (like a file is missing) ``` [+] Building 'emulate_disasm.o' make: nasm: Command not found make: *** [emulate_disasm.o] Error 127 gdbinit.py: No such file or directory. pytests_collect.py: No such file or directory. No output has been received in the last 10m0s, this potentially indicates a stalled build or something wrong with the build itself. Check the details on how to adjust your build configuration on: https://docs.travis-ci.com/user/common-build-problems/#Build-times-out-because-no-output-was-received ``` * Add test binariespull/500/head
parent
87aa167599
commit
f2ebe4bce0
@ -1,10 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd tests/binaries && make && cd ../..
|
||||
|
||||
# NOTE: We run tests under GDB sessions and because of some cleanup/tests dependencies problems
|
||||
# we decided to run each test in a separate GDB session
|
||||
TESTS_LIST=$(gdb --silent --nx --nh --command gdbinit.py --command pytests_collect.py | grep -o "tests/.*::.*")
|
||||
TESTS_LIST=$(gdb --silent --nx --nh --command gdbinit.py --command pytests_collect.py --eval-command quit | grep -o "tests/.*::.*")
|
||||
|
||||
tests_passed_or_skipped=0
|
||||
tests_failed=0
|
||||
|
||||
for test_case in ${TESTS_LIST}; do
|
||||
PWNDBG_LAUNCH_TEST="${test_case}" PWNDBG_DISABLE_COLORS=1 gdb --silent --nx --nh --command gdbinit.py --command pytests_launcher.py
|
||||
done
|
||||
PWNDBG_LAUNCH_TEST="${test_case}" PWNDBG_DISABLE_COLORS=1 gdb --silent --nx --nh --command gdbinit.py --command pytests_launcher.py --eval-command quit
|
||||
|
||||
exit_status=$?
|
||||
|
||||
if [ ${exit_status} -eq 0 ]; then
|
||||
(( ++tests_passed_or_skipped ))
|
||||
else
|
||||
(( ++tests_failed ))
|
||||
fi
|
||||
done
|
||||
|
||||
echo ""
|
||||
echo "*********************************"
|
||||
echo "********* TESTS SUMMARY *********"
|
||||
echo "*********************************"
|
||||
echo "Tests passed or skipped: ${tests_passed_or_skipped}"
|
||||
echo "Tests failed: ${tests_failed}"
|
||||
|
||||
if [ ${tests_failed} -ne 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@ -0,0 +1,14 @@
|
||||
global _start
|
||||
|
||||
; This binary is there to test
|
||||
; emulate vs nearpc/u/pdisas commands
|
||||
; The emulate should show just jump and one nop
|
||||
; The rest should show jump and two nops
|
||||
;
|
||||
; Motivated by https://github.com/pwndbg/pwndbg/issues/315
|
||||
|
||||
_start:
|
||||
jmp label
|
||||
nop
|
||||
label:
|
||||
nop
|
||||
Binary file not shown.
@ -0,0 +1,17 @@
|
||||
global _start
|
||||
|
||||
; This binary is there to test
|
||||
; emulate vs nearpc/u/pdisas commands
|
||||
; The emulate should show just jump and one nop
|
||||
; The rest should show jump and two nops
|
||||
;
|
||||
; Motivated by https://github.com/pwndbg/pwndbg/issues/315
|
||||
|
||||
_start:
|
||||
mov rsi, string
|
||||
mov rdi, rsp
|
||||
mov rcx, 3
|
||||
rep movsb
|
||||
|
||||
string db '12345', 0
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@ -0,0 +1,95 @@
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import tests
|
||||
from pwndbg.commands.nearpc import emulate
|
||||
from pwndbg.commands.nearpc import nearpc
|
||||
from pwndbg.commands.nearpc import pdisass
|
||||
from pwndbg.commands.windbg import u
|
||||
|
||||
EMULATE_DISASM_BINARY = tests.binaries.get('emulate_disasm.out')
|
||||
EMULATE_DISASM_LOOP_BINARY = tests.binaries.get('emulate_disasm_loop.out')
|
||||
|
||||
|
||||
def test_emulate_disasm(start_binary):
|
||||
"""
|
||||
Tests emulate command and its caching behavior
|
||||
"""
|
||||
start_binary(EMULATE_DISASM_BINARY)
|
||||
|
||||
assert emulate(to_string=True) == [
|
||||
' ► 0x400080 <_start> jmp label <0x400083>',
|
||||
' ↓',
|
||||
' 0x400083 <label> nop ',
|
||||
' 0x400084 add byte ptr [rax], al',
|
||||
' 0x400086 add byte ptr [rax], al',
|
||||
' 0x400088 add byte ptr [rax], al',
|
||||
' 0x40008a add byte ptr [rax], al',
|
||||
' 0x40008c add byte ptr [rax], al',
|
||||
' 0x40008e add byte ptr [rax], al',
|
||||
' 0x400090 add byte ptr [rax], al',
|
||||
' 0x400092 add byte ptr [rax], al',
|
||||
' 0x400094 add byte ptr [rax], al'
|
||||
]
|
||||
|
||||
disasm_without_emu = [
|
||||
' ► 0x400080 <_start> jmp label <0x400083>',
|
||||
' ',
|
||||
' 0x400082 <_start+2> nop ',
|
||||
' 0x400083 <label> nop ',
|
||||
' 0x400084 add byte ptr [rax], al',
|
||||
' 0x400086 add byte ptr [rax], al',
|
||||
' 0x400088 add byte ptr [rax], al',
|
||||
' 0x40008a add byte ptr [rax], al',
|
||||
' 0x40008c add byte ptr [rax], al',
|
||||
' 0x40008e add byte ptr [rax], al',
|
||||
' 0x400090 add byte ptr [rax], al',
|
||||
' 0x400092 add byte ptr [rax], al'
|
||||
]
|
||||
|
||||
assert nearpc(to_string=True) == disasm_without_emu
|
||||
assert emulate(to_string=True, emulate=False) == disasm_without_emu
|
||||
assert pdisass(to_string=True) == disasm_without_emu
|
||||
assert u(to_string=True) == disasm_without_emu
|
||||
|
||||
|
||||
def test_emulate_disasm_loop(start_binary):
|
||||
start_binary(EMULATE_DISASM_LOOP_BINARY)
|
||||
|
||||
assert emulate(to_string=True) == [
|
||||
' ► 0x400080 <_start> movabs rsi, string <0x400094>',
|
||||
' 0x40008a <_start+10> mov rdi, rsp',
|
||||
' 0x40008d <_start+13> mov ecx, 3',
|
||||
' 0x400092 <_start+18> rep movsb byte ptr [rdi], byte ptr [rsi]',
|
||||
' ↓',
|
||||
' 0x400092 <_start+18> rep movsb byte ptr [rdi], byte ptr [rsi]',
|
||||
' ↓',
|
||||
' 0x400092 <_start+18> rep movsb byte ptr [rdi], byte ptr [rsi]',
|
||||
' ↓',
|
||||
' 0x400092 <_start+18> rep movsb byte ptr [rdi], byte ptr [rsi]',
|
||||
' 0x400094 <string> xor dword ptr [rdx], esi',
|
||||
' 0x400096 <string+2> xor esi, dword ptr [rsi]',
|
||||
' 0x40009d add byte ptr [rax], al',
|
||||
' 0x40009f add byte ptr [rax], al'
|
||||
]
|
||||
|
||||
disasm_without_emu = [
|
||||
' ► 0x400080 <_start> movabs rsi, string <0x400094>',
|
||||
' 0x40008a <_start+10> mov rdi, rsp',
|
||||
' 0x40008d <_start+13> mov ecx, 3',
|
||||
' 0x400092 <_start+18> rep movsb byte ptr [rdi], byte ptr [rsi]',
|
||||
' 0x400094 <string> xor dword ptr [rdx], esi',
|
||||
' 0x400096 <string+2> xor esi, dword ptr [rsi]',
|
||||
' 0x40009d add byte ptr [rax], al',
|
||||
' 0x40009f add byte ptr [rax], al',
|
||||
' 0x4000a1 add byte ptr [rax], al',
|
||||
' 0x4000a3 add byte ptr [rax], al',
|
||||
' 0x4000a5 add byte ptr [rax], al'
|
||||
]
|
||||
|
||||
assert nearpc(to_string=True) == disasm_without_emu
|
||||
assert emulate(to_string=True, emulate=False) == disasm_without_emu
|
||||
assert pdisass(to_string=True) == disasm_without_emu
|
||||
assert u(to_string=True) == disasm_without_emu
|
||||
Loading…
Reference in new issue