Skip to content

Commit 327f475

Browse files
committed
Decouple BLOB entry point and load address
1 parent b18cc88 commit 327f475

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

examples/uboot_bin.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[CODE]
22
ram_size = 0xa00000
3+
load_address = 0x80800000
34
entry_point = 0x80800000
45
heap_size = 0x300000
56

qiling/loader/blob.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ def __init__(self, ql: Qiling):
1515
self.load_address = 0
1616

1717
def run(self):
18-
self.load_address = self.ql.os.entry_point # for consistency
18+
self.load_address = self.ql.os.load_address
19+
self.entry_point = self.ql.os.entry_point
1920

2021
code_begins = self.load_address
2122
code_size = self.ql.os.code_ram_size
@@ -28,8 +29,10 @@ def run(self):
2829
self.images.append(Image(code_begins, code_ends, 'blob_code'))
2930

3031
# FIXME: heap starts above end of ram??
32+
# FIXME: heap should be allocated by OS, not loader
3133
heap_base = code_ends
3234
heap_size = int(self.ql.os.profile.get("CODE", "heap_size"), 16)
3335
self.ql.os.heap = QlMemoryHeap(self.ql, heap_base, heap_base + heap_size)
3436

37+
# FIXME: stack pointer should be a configurable profile setting
3538
self.ql.arch.regs.arch_sp = code_ends - 0x1000

qiling/os/blob/blob.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from qiling.os.fcall import QlFunctionCall
1010
from qiling.os.os import QlOs
1111

12+
1213
class QlOsBlob(QlOs):
1314
""" QlOsBlob for bare barines.
1415
@@ -21,7 +22,7 @@ class QlOsBlob(QlOs):
2122
type = QL_OS.BLOB
2223

2324
def __init__(self, ql: Qiling):
24-
super(QlOsBlob, self).__init__(ql)
25+
super().__init__(ql)
2526

2627
self.ql = ql
2728

@@ -39,11 +40,14 @@ def __init__(self, ql: Qiling):
3940
self.fcall = QlFunctionCall(ql, cc)
4041

4142
def run(self):
42-
if self.ql.entry_point:
43+
# if entry point was set explicitly, override the default one
44+
if self.ql.entry_point is not None:
4345
self.entry_point = self.ql.entry_point
4446

45-
self.exit_point = self.ql.loader.load_address + len(self.ql.code)
46-
if self.ql.exit_point:
47+
self.exit_point = self.load_address + len(self.ql.code)
48+
49+
# if exit point was set explicitly, override the default one
50+
if self.ql.exit_point is not None:
4751
self.exit_point = self.ql.exit_point
4852

4953
self.ql.emu_start(self.entry_point, self.exit_point, self.ql.timeout, self.ql.count)

qiling/os/os.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def __init__(self, ql: Qiling, resolvers: Mapping[Any, Resolver] = {}):
8989
if self.ql.code:
9090
# this shellcode entrypoint does not work for windows
9191
# windows shellcode entry point will comes from pe loader
92+
self.load_address = self.profile.getint('CODE', 'load_address')
9293
self.entry_point = self.profile.getint('CODE', 'entry_point')
9394
self.code_ram_size = self.profile.getint('CODE', 'ram_size')
9495

tests/profiles/uboot_bin.ql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[CODE]
22
ram_size = 0xa00000
3+
load_address = 0x80800000
34
entry_point = 0x80800000
45
heap_size = 0x300000
56

0 commit comments

Comments
 (0)