Skip to content

Commit a117346

Browse files
committed
Add set_ratio in systick
1 parent 4a1418a commit a117346

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

examples/mcu/stm32f4_hack_lock.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ def crack(passwd):
2727
ql = Qiling(["../../examples/rootfs/mcu/stm32f407/backdoorlock.hex"],
2828
archtype="cortex_m", profile="stm32f407", verbose=QL_VERBOSE.OFF)
2929

30+
ql.hw.create('spi2')
31+
ql.hw.create('gpioe')
32+
ql.hw.create('gpiof')
3033
ql.hw.create('usart1')
34+
ql.hw.create('rcc')
3135

3236
ql.hw.show_info()
3337

@@ -40,7 +44,8 @@ def crack(passwd):
4044

4145
ql.hw.usart1.send(passwd.encode() + b'\r')
4246

43-
ql.run(count=300000, end=0x8003225)
47+
ql.hw.systick.set_ratio(100)
48+
ql.run(count=1000000, end=0x8003225)
4449
if ql.arch.get_pc() == 0x8003225:
4550
print('Success, the passwd is', passwd)
4651
else:

qiling/hw/timer/cm4_systick.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ def __init__(self, ql, label):
2626
)
2727

2828
# Maybe we will want to customize the timer speed in the future
29-
self.RATIO = 1
29+
self.ratio = 1
30+
31+
def set_ratio(self, ratio):
32+
self.ratio = ratio
3033

3134
def step(self):
3235
if not self.systick.CTRL & SYSTICK_CTRL.ENABLE:
@@ -39,7 +42,7 @@ def step(self):
3942
if self.systick.CTRL & SYSTICK_CTRL.TICKINT:
4043
self.ql.hw.nvic.set_pending(IRQ.SYSTICK)
4144
else:
42-
self.systick.VAL -= self.RATIO
45+
self.systick.VAL -= self.ratio
4346

4447
def read(self, offset: int, size: int) -> int:
4548
self.ql.log.debug(f'[{self.label.upper()}] [R] {self.find_field(offset, size):10s}')

0 commit comments

Comments
 (0)