Skip to content

Commit 15fb466

Browse files
committed
add a simple uboot example
1 parent 626b79d commit 15fb466

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

examples/hello_arm_uboot.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Cross Platform and Multi Architecture Advanced Binary Emulation Framework
4+
#
5+
6+
import sys
7+
sys.path.append("..")
8+
9+
from qiling.core import Qiling
10+
from qiling.const import QL_VERBOSE
11+
from qiling.os.const import STRING
12+
13+
def get_kaimendaji_password():
14+
def my_getenv(ql, *args, **kwargs):
15+
env = {"ID": b"000000000000000", "ethaddr": b"11:22:33:44:55:66"}
16+
params = ql.os.resolve_fcall_params({'key': STRING})
17+
value = env.get(params["key"], b"")
18+
19+
value_addr = ql.os.heap.alloc(len(value))
20+
ql.mem.write(value_addr, value)
21+
22+
ql.reg.r0 = value_addr
23+
ql.reg.arch_pc = ql.reg.lr
24+
25+
def get_password(ql, *args, **kwargs):
26+
password_raw = ql.mem.read(ql.reg.r0, ql.reg.r2)
27+
28+
password = ''
29+
for item in password_raw:
30+
if 0 <= item <= 9:
31+
password += chr(item + 48)
32+
else:
33+
password += chr(item + 87)
34+
35+
print("The password is: %s" % password)
36+
37+
def partial_run_init(ql):
38+
# argv prepare
39+
ql.reg.arch_sp -= 0x30
40+
arg0_ptr = ql.reg.arch_sp
41+
ql.mem.write(arg0_ptr, b"kaimendaji")
42+
43+
ql.reg.arch_sp -= 0x10
44+
arg1_ptr = ql.reg.arch_sp
45+
ql.mem.write(arg1_ptr, b"000000") # arbitrary password
46+
47+
ql.reg.arch_sp -= 0x20
48+
argv_ptr = ql.reg.arch_sp
49+
ql.mem.write(argv_ptr, ql.pack(arg0_ptr))
50+
ql.mem.write(argv_ptr + ql.pointersize, ql.pack(arg1_ptr))
51+
52+
ql.reg.r2 = 2
53+
ql.reg.r3 = argv_ptr
54+
55+
56+
with open("../examples/rootfs/blob/u-boot.bin.img", "rb") as f:
57+
uboot_code = f.read()
58+
59+
ql = Qiling(code=uboot_code[0x40:], archtype="arm", ostype="blob", profile="uboot_bin.ql", verbose=QL_VERBOSE.OFF)
60+
61+
image_base_addr = ql.loader.load_address
62+
ql.hook_address(my_getenv, image_base_addr + 0x13AC0)
63+
ql.hook_address(get_password, image_base_addr + 0x48634)
64+
65+
partial_run_init(ql)
66+
67+
ql.run(image_base_addr + 0x486B4, image_base_addr + 0x48718)
68+
69+
if __name__ == "__main__":
70+
get_kaimendaji_password()

examples/uboot_bin.ql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[CODE]
2+
ram_size = 0xa00000
3+
entry_point = 0x80800000
4+
heap_size = 0x300000
5+
6+
7+
[LOG]
8+
# log directory output
9+
# usage: dir = qlog
10+
dir =
11+
# split log file, use with multithread
12+
split = False
13+
14+
15+
[MISC]
16+
# append string into different logs
17+
# maily for multiple times Ql run with one file
18+
# usage: append = test1
19+
append =
20+
current_path = /

0 commit comments

Comments
 (0)