forked from MCUSec/uEmu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlaunch-uEmu-template.sh
83 lines (66 loc) · 2.55 KB
/
launch-uEmu-template.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
#
# This file was automatically generated by s2e-env at {{ creation_time }}
#
# This script is used to run the S2E analysis. Additional QEMU command line
# arguments can be passed to this script at run time.
#
uEmu_DIR="{{ root_dir }}"
BUILD_DIR="$uEmu_DIR/build"
BUILD=release
INSTALL_DIR="$BUILD_DIR/libs2e-$BUILD/{{ qemu_arch }}-s2e-softmmu"
FIRMWARE="{{ firmware }}"
# Comment this out to enable QEMU GUI
GRAPHICS=-nographic
if [ "x$1" = "xdebug" ]; then
DEBUG=1
shift
elif [ $1 ]; then
echo "wrong parameter!"
exit 8
fi
export S2E_CONFIG=uEmu-config.lua
export S2E_SHARED_DIR=$INSTALL_DIR
export S2E_MAX_PROCESSES=1
export S2E_UNBUFFERED_STREAM=1
if [ $S2E_MAX_PROCESSES -gt 1 ]; then
# Multi-threaded mode does not support graphics output, so we override
# whatever settings were there before.
export GRAPHICS=-nographic
fi
if [ "x$DEBUG" != "x" ]; then
if [ ! -d "$BUILD_DIR/qemu-$BUILD" ]; then
echo "No debug build found in $BUILD_DIR/qemu-$BUILD. Please run \`\`uEmu build -g\`\`"
exit 1
fi
QEMU="$BUILD_DIR/qemu-$BUILD/{{ qemu_arch }}-softmmu/qemu-system-{{ qemu_arch }}"
QEMU_MEMORY="{{ memory }}"
LIBS2E="$BUILD_DIR/libs2e-$BUILD/{{ qemu_arch }}-s2e-softmmu/libs2e.so"
rm -f gdb.ini
echo handle SIGUSR1 noprint >> gdb.ini
echo handle SIGUSR2 noprint >> gdb.ini
echo set disassembly-flavor intel >> gdb.ini
echo set print pretty on >> gdb.ini
echo set environment S2E_CONFIG=$S2E_CONFIG >> gdb.ini
echo set environment S2E_SHARED_DIR=$S2E_SHARED_DIR >> gdb.ini
echo set environment LD_PRELOAD=$LIBS2E >> gdb.ini
echo set environment S2E_UNBUFFERED_STREAM=1 >> gdb.ini
echo set environment S2E_MAX_PROCESSES=1 >> gdb.ini
# echo set environment LIBCPU_LOG_LEVEL=in_asm,int,exec >> gdb.ini
# echo set environment LIBCPU_LOG_FILE=/tmp/log.txt >> gdb.ini
# echo set environment S2E_QMP_SERVER=127.0.0.1:3322 >> gdb.ini
echo set python print-stack full >> gdb.ini
GDB="gdb --init-command=gdb.ini --args"
$GDB $QEMU \
-k en-us $GRAPHICS -M mps2-ans2e -cpu cortex-m3 -m $QEMU_MEMORY -enable-kvm \
-serial file:s2e-last/serial.txt $QEMU_EXTRA_FLAGS \
-kernel $FIRMWARE
else
QEMU="$BUILD_DIR/opt/bin/qemu-system-{{ qemu_arch }}"
QEMU_MEMORY="{{ memory }}"
LIBS2E="$BUILD_DIR/opt/share/libs2e/libs2e-{{ qemu_arch }}-s2e.so"
LD_PRELOAD=$LIBS2E $QEMU \
-k en-us $GRAPHICS -M mps2-ans2e -cpu cortex-m3 -m $QEMU_MEMORY -enable-kvm \
-serial file:s2e-last/serial.txt $QEMU_EXTRA_FLAGS \
-kernel $FIRMWARE
fi