Skip to content

Commit b6cf49a

Browse files
authored
Merge pull request #940 from cla7aye15I4nd/dev
Add support for STM32 series microcontroller simulation
2 parents 187e0f3 + a117346 commit b6cf49a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+10697
-98
lines changed

examples/mcu/LCD1602A.txt

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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+
| | | # | ### | ### |# #| # | | | | | # | # | | | |
84+
| | | # |# #| # |# #| | | | | | ####| # | # |## # |# #|
85+
| | | # |# #| # |# #| ## |# #| | | # |# # | # |# # | # |# #|
86+
| | | # | ####| # | # # | # |# #| | |#####| # | # |# # | |# #|
87+
| | | # | #| # | # | # | ####| | |# #| # | # |# # #| | ####|
88+
| | | # | # | # | # | # | #| | | #| # | # |# # #| | #|
89+
| | | # | ## | ### | # | ### | ### | | | ## | # | # |# ## | | ### |
90+
| | | | | | | | | | | | | | | | |
91+
-------------------------------------------------------------------------------------------------
92+
| | | | | ###|#####| # | | | | | | | | # | #|
93+
| | | # | ## | # | #| | | | | |#####| # |# | |#### |
94+
| | |# # #| ## | # | # | ## |#####| | | | #| # |# | ## | # |
95+
| | | ### | | # | # | # | # | | |#####| #|# #|# #| # |#####|
96+
| | |# # #| ## | # | # | # | # | | | # | #|# #|# # | # | # |
97+
| | | # | ## |# # |# |# # | # | | | # | #|# #|# # | # | |
98+
| | | | | ## |#####| ## |#####| | |#####|#####|# #|## |# # | |
99+
| | | | | | | | | | | | | | | ## | |
100+
-------------------------------------------------------------------------------------------------
101+
| | | | |# #| ### |# | # | | | | # # |# | |# # | |
102+
| | | # | ## |# # | # |# | # | | | |#####|# |#####| # |#####|
103+
| | | # | ## |# # | # |# # | # | | | # | # # |#####|# #|# # | # |
104+
| | |#####| |## | # |# # | # | | |#####| # # |# |# #| | ####|
105+
| | | # | ## |# # | # |## | # | | | ## | # |# |# #| | # #|
106+
| | | # | # |# # | # |# # | # | | | # # | # |# |# #| |# #|
107+
| | | | # |# #| ### |# # | # | | |# # | # | ####|#####| | |
108+
| | | | | | | | | | | | | | | | |
109+
-------------------------------------------------------------------------------------------------
110+
| | | | # |# |# #| ## | # | | | | | | | # | |
111+
| | | | # |# | # # | # | # | | | |## |#####|#####| ### |#####|
112+
| | | | # |# |#####| # | # | | | # | #| #|# #|# # |# # #|
113+
| | | |# |# | # | # | # | | |#####|## #| #|# #|# # #|#####|
114+
| | | ## | # |# |#####| # | # | | | # #| #| #| #| ### |# #|
115+
| | | # | # |# | # | # | # | | | # # | # | # | # | # |# #|
116+
| | | # | # |#####| # | ### | # | | | # |### | ## | # | | |
117+
| | | | | | | | | | | | | | | | |
118+
-------------------------------------------------------------------------------------------------
119+
| | | | |# #| ### | | # | | | | | | | # | |
120+
| | | | |## ##| # | | # | | | |#####| # |## |### | # |
121+
| | | |#####|# # #| # |## # | # | | | | #|# # | | # |#####|
122+
| | |#####| |# # #| # |# # #| # | | | ### | # | # | #|### | # |
123+
| | | |#####|# #| # |# # #| # | | | # | # | #| #| # | |
124+
| | | | |# #| # |# #| # | | | # | # # | #| # | ####| |
125+
| | | | |# #| ### |# #| # | | |#####|# #| |### | | |
126+
| | | | | | | | | | | | | | | | |
127+
-------------------------------------------------------------------------------------------------
128+
| | | | # |# #| # | | | | | | # | # | # | ### | |
129+
| | | | # |# #| # # | | # | | | |#####|#####|# # |# ## | |
130+
| | | | # |## #|# #|# ## | # | | |#### | # #| # | # |## #| |
131+
| | | | #|# # #| |## #|#####| | | # | # # | # | |# #| |
132+
| | | | # |# ##| |# #| # | | |#### | # |# # #| |# #| |
133+
| | | ## | # |# #| |# #| # | | | # | # |# # #| | | |
134+
| | | ## | # |# #| |# #| | | |#### | ###| # | | | |
135+
| | | | | | | | | | | | | | | | |
136+
-------------------------------------------------------------------------------------------------
137+
| | | | ### | ### | | | | | | | | |### | # # |#####|
138+
| | | #|# #|# #| | | # | | | |# #|#####|# # | ### |#####|
139+
| | | # | #|# #| | ### | # | | | |# #| #|### |# #|#####|
140+
| | | # | # |# #| |# #|#####| | |# # #| # #| #| |# #|#####|
141+
| | | # | # |# #| |# #| # | | |# # #| #| # # | | ### |#####|
142+
| | |# | |# #| |# #| # | | | #| # | # | | |#####|
143+
| | | | # | ### |#####| ### | | | | ## | ## | # | | |#####|
144+
| | | | | | | | | | | | | | | |#####|
145+
-------------------------------------------------------------------------------------------------

examples/mcu/stm32f4_dma.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import sys
2+
sys.path.append("../..")
3+
4+
from qiling.core import Qiling
5+
from qiling.const import QL_VERBOSE
6+
7+
8+
def stm32f411_dma():
9+
ql = Qiling(["../rootfs/mcu/stm32f411/dma-clock.hex"],
10+
archtype="cortex_m", profile="stm32f411", verbose=QL_VERBOSE.DEBUG)
11+
12+
ql.hw.create('usart2')
13+
ql.hw.create('dma1')
14+
ql.hw.create('rcc')
15+
16+
ql.run(count=200000)
17+
buf = ql.hw.usart2.recv()
18+
19+
## check timestamp
20+
tick = [int(x) for x in buf.split()]
21+
for i in range(1, len(tick)):
22+
assert(4 <= tick[i] - tick[i - 1] <= 6)
23+
24+
if __name__ == "__main__":
25+
stm32f411_dma()

examples/mcu/stm32f4_freertos.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import sys
2+
sys.path.append("../..")
3+
4+
from qiling.core import Qiling
5+
from qiling.const import QL_VERBOSE
6+
7+
8+
def stm32f411_freertos():
9+
ql = Qiling(["../rootfs/mcu/stm32f411/os-demo.hex"],
10+
archtype="cortex_m", profile="stm32f411", verbose=QL_VERBOSE.DEBUG)
11+
12+
ql.hw.create('usart2')
13+
ql.hw.create('rcc')
14+
ql.hw.create('gpioa')
15+
16+
count = 0
17+
def counter():
18+
nonlocal count
19+
count += 1
20+
21+
ql.hw.gpioa.hook_set(5, counter)
22+
23+
ql.run(count=200000)
24+
25+
print(count >= 5)
26+
print(ql.hw.usart2.recv())
27+
28+
if __name__ == "__main__":
29+
stm32f411_freertos()

examples/mcu/stm32f4_hack_lock.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Cross Platform and Multi Architecture Advanced Binary Emulation Framework
4+
#
5+
6+
7+
import sys
8+
from multiprocessing import Pool
9+
from multiprocessing import Process
10+
11+
sys.path.append("../..")
12+
13+
from qiling.core import Qiling
14+
from qiling.const import QL_VERBOSE
15+
16+
def dicts():
17+
a = 0x79df7
18+
b = 0x75ee0
19+
c = 0xcc5ee
20+
M = 0xf4247
21+
22+
for x in range(1, 20):
23+
yield str((a*x*x + b*x + c) % M)
24+
25+
# Cracking the passwd of lock
26+
def crack(passwd):
27+
ql = Qiling(["../../examples/rootfs/mcu/stm32f407/backdoorlock.hex"],
28+
archtype="cortex_m", profile="stm32f407", verbose=QL_VERBOSE.OFF)
29+
30+
ql.hw.create('spi2')
31+
ql.hw.create('gpioe')
32+
ql.hw.create('gpiof')
33+
ql.hw.create('usart1')
34+
ql.hw.create('rcc')
35+
36+
ql.hw.show_info()
37+
38+
print('Testing passwd', passwd)
39+
40+
ql.patch(0x8000238, b'\x00\xBF' * 4)
41+
ql.patch(0x80031e4, b'\x00\xBF' * 11)
42+
ql.patch(0x80032f8, b'\x00\xBF' * 13)
43+
ql.patch(0x80013b8, b'\x00\xBF' * 10)
44+
45+
ql.hw.usart1.send(passwd.encode() + b'\r')
46+
47+
ql.hw.systick.set_ratio(100)
48+
ql.run(count=1000000, end=0x8003225)
49+
if ql.arch.get_pc() == 0x8003225:
50+
print('Success, the passwd is', passwd)
51+
else:
52+
print('Fail, the passwd is not', passwd)
53+
54+
del ql
55+
56+
pool = Pool()
57+
for passwd in dicts():
58+
pool.apply_async(crack, args=(passwd,))
59+
60+
pool.close()
61+
pool.join()

examples/mcu/stm32f4_hello_gpio.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import sys
2+
sys.path.append("../..")
3+
4+
from qiling.core import Qiling
5+
from qiling.const import QL_VERBOSE
6+
7+
8+
def test_mcu_gpio_stm32f411():
9+
ql = Qiling(["../../examples/rootfs/mcu/stm32f411/hello_gpioA.hex"],
10+
archtype="cortex_m", profile="stm32f411", verbose=QL_VERBOSE.DEBUG)
11+
12+
ql.hw.create('usart2')
13+
ql.hw.create('rcc')
14+
ql.hw.create('gpioa')
15+
16+
17+
ql.hw.gpioa.hook_set(5, lambda: print('LED light up'))
18+
ql.hw.gpioa.hook_reset(5, lambda: print('LED light off'))
19+
20+
ql.run(count=10000)
21+
22+
if __name__ == "__main__":
23+
test_mcu_gpio_stm32f411()

0 commit comments

Comments
 (0)