1919 from .hw .hw import QlHwManager
2020 from .loader .loader import QlLoader
2121
22- from .const import QL_ARCH_ENDIAN , QL_ENDIAN , QL_OS , QL_VERBOSE , QL_ARCH_NONEOS , QL_ARCH_HARDWARE
22+ from .const import QL_ARCH_ENDIAN , QL_ENDIAN , QL_OS , QL_VERBOSE , QL_ARCH_INTERPRETER , QL_ARCH_BAREMETAL
2323from .exception import QlErrorFileNotFound , QlErrorArch , QlErrorOsType , QlErrorOutput
2424from .utils import *
2525from .core_struct import QlCoreStructs
@@ -68,7 +68,8 @@ def __init__(
6868 self ._code = code
6969 self ._ostype = ostype
7070 self ._archtype = archtype
71- self ._noneos = None ,
71+ self ._interpreter = False ,
72+ self ._baremetal = False ,
7273 self ._archendian = None
7374 self ._archbit = None
7475 self ._pointersize = None
@@ -110,29 +111,29 @@ def __init__(
110111 """
111112 Qiling Framework Core Engine
112113 """
113- ##############
114- # Shellcode? #
115- ##############
114+ ###############
115+ # code_exec() #
116+ ###############
116117
117118 if self ._code or (self ._archtype and type (self ._archtype ) == str ):
118119 if (self ._archtype and type (self ._archtype ) == str ):
119120 self ._archtype = arch_convert (self ._archtype .lower ())
120121
121- if (self ._ostype and type (self ._ostype ) == str ):
122+ if self ._ostype == None :
123+ self ._ostype = arch_os_convert (self ._archtype )
124+ else :
122125 self ._ostype = ostype_convert (self ._ostype .lower ())
123126
124- if self ._archtype in QL_ARCH_NONEOS or self ._ostype == None :
125- if self ._ostype == None :
126- self ._ostype = arch_os_convert (self ._archtype )
127- if self ._code == None :
128- self ._code = self ._archtype
129-
130-
127+ if self ._code == None :
128+ self ._code = "qiling"
131129 if self ._argv is None :
132130 self ._argv = ["qilingcode" ]
133131 if self ._rootfs is None :
134132 self ._rootfs = "."
135-
133+
134+ self ._interpreter = True if self ._archtype in (QL_ARCH_INTERPRETER ) else False
135+ self ._baremetal = True if self ._archtype in (QL_ARCH_BAREMETAL ) else False
136+
136137 # file check
137138 if self ._code is None :
138139 if not os .path .exists (str (self ._argv [0 ])):
@@ -201,11 +202,11 @@ def __init__(
201202 # Components #
202203 ##############
203204
204- if self . archtype not in QL_ARCH_NONEOS :
205+ if not self . _interpreter :
205206 self ._mem = component_setup ("os" , "memory" , self )
206207 self ._reg = component_setup ("arch" , "register" , self )
207208
208- if self .archtype in QL_ARCH_HARDWARE :
209+ if self ._baremetal :
209210 self ._hw = component_setup ("hw" , "hw" , self )
210211
211212 self ._arch = arch_setup (self .archtype , self )
@@ -215,11 +216,11 @@ def __init__(
215216 QlCoreHooks .__init__ (self , self .uc )
216217
217218 # Setup Outpt
218- if self . archtype not in QL_ARCH_NONEOS :
219+ if not self . _interpreter :
219220 self .arch .utils .setup_output ()
220221
221- if ( self . archtype not in QL_ARCH_NONEOS ) :
222- if ( self . archtype not in QL_ARCH_HARDWARE ) :
222+ if not self . _interpreter :
223+ if not self . _baremetal :
223224 self ._os = os_setup (self .archtype , self .ostype , self )
224225
225226 if stdin is not None :
@@ -234,8 +235,8 @@ def __init__(
234235 # Run the loader
235236 self .loader .run ()
236237
237- if ( self . archtype not in QL_ARCH_NONEOS ) :
238- if ( self . archtype not in QL_ARCH_HARDWARE ) :
238+ if not self . _interpreter :
239+ if not self . _baremetal :
239240 # Add extra guard options when configured to do so
240241 self ._init_stop_guard ()
241242
@@ -545,7 +546,7 @@ def verbose(self):
545546 def verbose (self , v ):
546547 self ._verbose = v
547548 self .log .setLevel (ql_resolve_logger_level (self ._verbose ))
548- if self .archtype not in QL_ARCH_NONEOS :
549+ if self .interpreter :
549550 self .arch .utils .setup_output ()
550551
551552 @property
@@ -629,6 +630,31 @@ def uc(self) -> Uc:
629630 def uc (self , u ):
630631 self ._uc = u
631632
633+ @property
634+ def interpreter (self ) -> bool :
635+ """ Raw uc instance.
636+
637+ Type: Ucgit
638+ """
639+ return self ._interpreter
640+
641+ @interpreter .setter
642+ def interpreter (self , i ):
643+ self ._interpreter = i
644+
645+ @property
646+ def baremetal (self ) -> bool :
647+ """ Raw uc instance.
648+
649+ Type: Ucgit
650+ """
651+ return self ._baremetal
652+
653+ @baremetal .setter
654+ def baremetal (self , b ):
655+ self ._baremetal = b
656+
657+
632658 @property
633659 def stop_options (self ) -> "QlStopOptions" :
634660 """ The stop options configured:
@@ -710,21 +736,22 @@ def run(self, begin=None, end=None, timeout=0, count=0, code = None):
710736 if self ._debugger != False and self ._debugger != None :
711737 self ._debugger = debugger_setup (self ._debugger , self )
712738
713- if self .archtype not in QL_ARCH_NONEOS and self .archtype not in QL_ARCH_HARDWARE :
714- self .write_exit_trap ()
715- # patch binary
716- self .__enable_bin_patch ()
739+ if not self .interpreter :
740+ if not self .baremetal :
741+ self .write_exit_trap ()
742+ # patch binary
743+ self .__enable_bin_patch ()
717744
718- # emulate the binary
719- self .os .run ()
745+ # emulate the binary
746+ self .os .run ()
720747
721- if self .archtype in QL_ARCH_NONEOS :
748+ if self .interpreter :
722749 if code == None :
723750 return self .arch .run (self ._code )
724751 else :
725752 return self .arch .run (code )
726753
727- if self .archtype in QL_ARCH_HARDWARE :
754+ if self .baremetal :
728755 self .__enable_bin_patch ()
729756 if self .count <= 0 :
730757 self .count = - 1
@@ -872,7 +899,7 @@ def stop(self):
872899 if self .multithread :
873900 self .os .thread_management .stop ()
874901
875- elif self .archtype in QL_ARCH_HARDWARE :
902+ elif self .baremetal :
876903 self .arch .stop ()
877904
878905 else :
0 commit comments