| 1 | #!/bin/sh |
| 2 | |
| 3 | # $1 = key specification as multiline string |
| 4 | # $2 = dump file to store process memory |
| 5 | |
| 6 | GEN_SCRIPT="debian/tests/helpers/gen_rsa_key.py" |
| 7 | |
| 8 | # Spawns subshell running the key generation script |
| 9 | (echo "$1" | python3 "${GEN_SCRIPT}") & |
| 10 | |
| 11 | # Sleep to retrieve the PID of the child process reliably |
| 12 | sleep .3 |
| 13 | |
| 14 | PID=$(pgrep -f -u root "python3 ${GEN_SCRIPT}") |
| 15 | |
| 16 | # Dumps memory |
| 17 | grep rw-p /proc/${PID}/maps | sed -n 's/^\([0-9a-f]*\)-\([0-9a-f]*\) .*$/\1\t\2/p' \ |
| 18 | | while read start stop; |
| 19 | do gdb --batch --pid ${PID} -ex "append memory $2 0x$start 0x$stop" > /dev/null 2>&1; |
| 20 | done |
| 21 | |
| 22 | # Terminates key generation script |
| 23 | kill -9 ${PID} |