compile binary just-in-time

pull/880/head
Daniel Ebert 4 years ago committed by Disconnect3d
parent 0608fc8dd1
commit 9613310e8c

@ -20,7 +20,7 @@ linux() {
install_apt() {
sudo apt-get update || true
sudo apt-get install -y nasm
sudo apt-get install -y nasm gcc
test -f /usr/bin/go || sudo apt-get install -y golang
}

@ -0,0 +1,3 @@
all:
gcc binary.c -o binary

@ -50,11 +50,18 @@ def run_gdb_with_script(binary='', core='', pybefore=None, pyafter=None):
return output
def compile_binary(binary_source, binary_out):
assert os.path.isfile(binary_source)
subprocess.check_call(['gcc', binary_source, '-o', binary_out])
HELLO = [
'pwndbg: loaded ### commands. Type pwndbg [filter] for a list.',
'pwndbg: created $rebase, $ida gdb functions (can be used with print/break)'
]
BINARY_SOURCE = tests.binaries.div_zero_binary.get('binary.c')
BINARY = tests.binaries.div_zero_binary.get('binary')
CORE = tests.binaries.div_zero_binary.get('core')
@ -68,6 +75,8 @@ def test_loads_pure_gdb_without_crashing():
@pytest.mark.skipif(launched_locally, reason='This test uses binaries compiled on travis builds.')
def test_loads_binary_without_crashing():
if not os.path.isfile(BINARY):
compile_binary(BINARY_SOURCE, BINARY)
output = run_gdb_with_script(binary=BINARY).splitlines()
expected = ['Reading symbols from %s...' % BINARY,
@ -79,35 +88,51 @@ def test_loads_binary_without_crashing():
@pytest.mark.skipif(launched_locally, reason='This test uses binaries compiled on travis builds.')
def test_loads_binary_with_core_without_crashing():
if not os.path.isfile(BINARY):
compile_binary(BINARY_SOURCE, BINARY)
output = run_gdb_with_script(binary=BINARY, core=CORE).splitlines()
expected = [
'Reading symbols from %s...' % BINARY,
'(No debugging symbols found in %s)' % BINARY,
'[New LWP 45429]',
"Core was generated by `./binary'.",
'Program terminated with signal SIGFPE, Arithmetic exception.',
'#0 0x0000556e99b7913c in main ()',
]
expected += HELLO
assert all(item in output for item in expected)
# matches for example '[New LWP 45429]'
lwp_line = re.compile('^\[New LWP \d+\]$')
assert any([lwp_line.match(line) for line in output])
# matches for example '#0 0x0000556e99b7913c in main ()'
crash_address_line = re.compile('^#0 0x[0-9a-fA-F]+ in main \(\)$')
assert any([crash_address_line.match(line) for line in output])
@pytest.mark.skipif(launched_locally, reason='This test uses binaries compiled on travis builds.')
def test_loads_core_without_crashing():
if not os.path.isfile(BINARY):
compile_binary(BINARY_SOURCE, BINARY)
output = run_gdb_with_script(core=CORE).splitlines()
expected = [
"[New LWP 45429]",
"Core was generated by `./binary'.",
'Program terminated with signal SIGFPE, Arithmetic exception.',
'#0 0x0000556e99b7913c in ?? ()',
]
expected += HELLO
assert all(item in output for item in expected)
# matches for example '[New LWP 45429]'
lwp_line = re.compile('^\[New LWP \d+\]$')
assert any([lwp_line.match(line) for line in output])
# matches for example '#0 0x0000556e99b7913c in ?? ()'
crash_address_line = re.compile('^#0 0x[0-9a-fA-F]+ in \?\? \(\)$')
assert any([crash_address_line.match(line) for line in output])
def test_entry_no_file_loaded():
# This test is just to demonstrate that if gdb fails, all we have left is its stdout/err

Loading…
Cancel
Save