Skip to content

Commit 8eaa062

Browse files
committed
update and adapt the code
2 parents 87634b6 + 452f416 commit 8eaa062

File tree

10 files changed

+103
-105
lines changed

10 files changed

+103
-105
lines changed

qiling/const.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ class QL_INTERCEPT(IntEnum):
6565

6666
QL_OS_BAREMETAL = (QL_OS.MCU,)
6767
QL_OS_INTERPRETER = (QL_OS.EVM,)
68-
QL_OS_ALL = QL_OS_POSIX + QL_OS_NONPID + (QL_OS.WINDOWS,)
69-
QL_OS_BARE_RTOS = (QL_OS.BARE,)
7068

7169
QL_HOOK_BLOCK = 0b0001
7270
QL_CALL_BLOCK = 0b0010
@@ -92,7 +90,7 @@ def __reverse_enum(e: Type[Enum]) -> Mapping[str, Any]:
9290
QL_OS.DOS : "DOS",
9391
QL_OS.EVM : "EVM",
9492
QL_OS.MCU : "MCU",
95-
QL_OS.BARE : "BLOB"
93+
QL_OS.BARE : "BARE"
9694
}
9795

9896
arch_os_map = {

qiling/core.py

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from .hw.hw import QlHwManager
2020
from .loader.loader import QlLoader
2121

22-
from .const import QL_ARCH_ENDIAN, QL_ENDIAN, QL_VERBOSE, QL_OS_INTERPRETER, QL_OS_BAREMETAL, QL_OS_ALL, QL_OS_BARE_RTOS
22+
from .const import QL_ARCH_ENDIAN, QL_ENDIAN, QL_VERBOSE, QL_OS_INTERPRETER, QL_OS_BAREMETAL
2323
from .exception import QlErrorFileNotFound, QlErrorArch, QlErrorOsType
2424
from .utils import *
2525
from .core_struct import QlCoreStructs
@@ -194,24 +194,19 @@ def __init__(
194194
##############
195195
# Components #
196196
##############
197-
if self.gpos or self.baremetal or self.blob:
197+
if not self.interpreter:
198198
self._mem = component_setup("os", "memory", self)
199199
self._reg = component_setup("arch", "register", self)
200-
201-
if self.baremetal:
202-
self._hw = component_setup("hw", "hw", self)
200+
203201

204202
self._arch = arch_setup(self.archtype, self)
205203

206204
# Once we finish setting up arch layer, we can init QlCoreHooks.
207-
self.uc = self.arch.init_uc
208-
QlCoreHooks.__init__(self, self.uc)
205+
if not self.interpreter:
206+
self.uc = self.arch.init_uc
207+
QlCoreHooks.__init__(self, self.uc)
209208

210-
# Setup Outpt
211-
if self.gpos or self.baremetal:
212209
self.arch.utils.setup_output()
213-
214-
if self.gpos:
215210
self._os = os_setup(self.archtype, self.ostype, self)
216211

217212
if stdin is not None:
@@ -225,10 +220,7 @@ def __init__(
225220

226221
# Run the loader
227222
self.loader.run()
228-
229-
if self.gpos:
230-
# Add extra guard options when configured to do so
231-
self._init_stop_guard()
223+
self._init_stop_guard()
232224

233225
#####################
234226
# Qiling Components #
@@ -481,24 +473,6 @@ def baremetal(self) -> bool:
481473
"""
482474
return self.ostype in QL_OS_BAREMETAL
483475

484-
@property
485-
def gpos(self) -> bool:
486-
""" General purpose OS
487-
- Windows, Linux, MacOS and etc
488-
489-
Type: bool
490-
"""
491-
return self.ostype in QL_OS_ALL
492-
493-
@property
494-
def blob(self) -> bool:
495-
""" Static linked bare binary type
496-
- U-Boot, VxWorks, eCos
497-
498-
Type: bool
499-
"""
500-
return self.ostype in QL_OS_BARE_RTOS
501-
502476
@property
503477
def platform_os(self):
504478
""" Specify current platform os where Qiling runs on.

qiling/debugger/gdb/gdb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(self, ql: Qiling, ip: str = '127.0.01', port: int = 9999):
5454
if self.ql.baremetal:
5555
load_address = self.ql.loader.load_address
5656
exit_point = load_address + os.path.getsize(ql.path)
57-
elif self.ql.code and ql.gpos:
57+
elif self.ql.code:
5858
load_address = self.ql.os.entry_point
5959
exit_point = load_address + len(ql.code)
6060
else:

qiling/loader/bare.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Cross Platform and Multi Architecture Advanced Binary Emulation Framework
4+
#
5+
6+
from qiling import Qiling
7+
from qiling.loader.loader import QlLoader
8+
from qiling.os.memory import QlMemoryHeap
9+
10+
class QlLoaderBARE(QlLoader):
11+
def __init__(self, ql: Qiling):
12+
super().__init__(ql)
13+
14+
self.load_address = 0
15+
16+
def run(self):
17+
self.load_address = self.ql.os.entry_point # for consistency
18+
19+
self.ql.mem.map(self.ql.os.entry_point, self.ql.os.code_ram_size, info="[code]")
20+
self.ql.mem.write(self.ql.os.entry_point, self.ql.code)
21+
22+
heap_address = self.ql.os.entry_point + self.ql.os.code_ram_size
23+
heap_size = int(self.ql.os.profile.get("CODE", "heap_size"), 16)
24+
self.ql.os.heap = QlMemoryHeap(self.ql, heap_address, heap_address + heap_size)
25+
26+
self.ql.reg.arch_sp = heap_address - 0x1000
27+
28+
return

qiling/loader/blob.py

Lines changed: 0 additions & 65 deletions
This file was deleted.

qiling/loader/mcu.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
from qiling.const import *
1212
from qiling.core import Qiling
13+
from qiling.utils import component_setup
1314

1415
from .loader import QlLoader
1516

16-
1717
class IhexParser:
1818
def __init__(self, path):
1919
self.pc = None
@@ -60,7 +60,7 @@ def parse_line(self, line):
6060
class QlLoaderMCU(QlLoader):
6161
def __init__(self, ql:Qiling):
6262
super(QlLoaderMCU, self).__init__(ql)
63-
63+
self.ql._hw = component_setup("hw", "hw", self.ql)
6464
self.load_address = 0
6565
self.path = self.argv[0]
6666
self.filetype = self.guess_filetype()

qiling/os/bare/bare.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Cross Platform and Multi Architecture Advanced Binary Emulation Framework
4+
#
5+
6+
from qiling import Qiling
7+
from qiling.cc import QlCC, intel, arm, mips
8+
from qiling.const import QL_ARCH
9+
from qiling.os.fcall import QlFunctionCall
10+
from qiling.os.os import QlOs
11+
12+
class QlOsBare(QlOs):
13+
""" QlOsBare for bare barines.
14+
15+
For bare binary such as u-boot, it's ready to be mapped and executed directly,
16+
where there is(may be) no concept of os? Currently, some functionalities such as
17+
resolve_fcall_params(), heap or add_fs_mapper() are based on os. To keep the
18+
consistence of api usage, QlOsBare is introduced and placed at its loader temporarily.
19+
"""
20+
def __init__(self, ql: Qiling):
21+
super(QlOsBare, self).__init__(ql)
22+
23+
self.ql = ql
24+
25+
cc: QlCC = {
26+
QL_ARCH.X86 : intel.cdecl,
27+
QL_ARCH.X8664 : intel.amd64,
28+
QL_ARCH.ARM : arm.aarch32,
29+
QL_ARCH.ARM64 : arm.aarch64,
30+
QL_ARCH.MIPS : mips.mipso32
31+
}[ql.archtype](ql)
32+
33+
self.fcall = QlFunctionCall(ql, cc)
34+
35+
def run(self):
36+
if self.ql.entry_point:
37+
self.entry_point = self.ql.entry_point
38+
39+
self.exit_point = self.ql.loader.load_address + len(self.ql.code)
40+
if self.ql.exit_point:
41+
self.exit_point = self.ql.exit_point
42+
43+
self.ql.emu_start(self.entry_point, self.exit_point, self.ql.timeout, self.ql.count)

qiling/os/mcu/const.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Cross Platform and Multi Architecture Advanced Binary Emulation Framework
4+
#
5+

qiling/os/mcu/mcu.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python3
2+
#
3+
# Cross Platform and Multi Architecture Advanced Binary Emulation Framework
4+
#
5+
6+
from unicorn import UcError
7+
8+
from qiling.os.os import QlOs
9+
10+
class QlOsMcu(QlOs):
11+
def __init__(self, ql):
12+
super(QlOsMcu, self).__init__(ql)
13+
14+
def run(self):
15+
pass

qiling/os/os.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(self, ql: Qiling, resolvers: Mapping[Any, Resolver] = {}):
3535
self.child_processes = False
3636
self.thread_management = None
3737
self.profile = self.ql.profile
38-
self.path = QlPathManager(ql, self.ql.profile.get("MISC", "current_path"))
38+
self.path = None if self.ql.baremetal else QlPathManager(ql, self.ql.profile.get("MISC", "current_path"))
3939
self.exit_code = 0
4040

4141
self.user_defined_api = {

0 commit comments

Comments
 (0)