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_INTERPRETER , QL_ARCH_BAREMETAL
22+ from .const import QL_ARCH_ENDIAN , QL_ENDIAN , QL_OS , QL_VERBOSE , QL_ARCH_INTERPRETER , QL_ARCH_BAREMETAL , QL_OS_ALL
2323from .exception import QlErrorFileNotFound , QlErrorArch , QlErrorOsType , QlErrorOutput
2424from .utils import *
2525from .core_struct import QlCoreStructs
@@ -68,9 +68,10 @@ def __init__(
6868 self ._code = code
6969 self ._ostype = ostype
7070 self ._archtype = archtype
71- self ._interpreter = False ,
72- self ._baremetal = False ,
73- self ._archendian = None
71+ self ._interpreter = False
72+ self ._baremetal = False
73+ self ._gpos = False
74+ self ._archendian = QL_ENDIAN .EL
7475 self ._archbit = None
7576 self ._pointersize = None
7677 self ._profile = profile
@@ -107,14 +108,12 @@ def __init__(
107108 self .count = None
108109 self ._initial_sp = None
109110
110-
111111 """
112112 Qiling Framework Core Engine
113113 """
114114 ###############
115115 # code_exec() #
116116 ###############
117-
118117 if self ._code or (self ._archtype and type (self ._archtype ) == str ):
119118 if (self ._archtype and type (self ._archtype ) == str ):
120119 self ._archtype = arch_convert (self ._archtype .lower ())
@@ -136,19 +135,21 @@ def __init__(
136135 self ._path = (str (self ._argv [0 ]))
137136 self ._targetname = ntpath .basename (self ._argv [0 ])
138137
139- # file check
140- if (self ._path and self ._rootfs ) and self ._code == None :
138+ ##############
139+ # File check #
140+ ##############
141+ if (not self ._interpreter and not self ._baremetal ) and self ._code == None :
141142 if not os .path .exists (str (self ._argv [0 ])):
142143 raise QlErrorFileNotFound ("Target binary not found: %s" % (self ._argv [0 ]))
143144 if not os .path .exists (self ._rootfs ):
144145 raise QlErrorFileNotFound ("Target rootfs not found" )
145-
146+
146147 guessed_archtype , guessed_ostype , guessed_archendian = ql_guess_emu_env (self ._path )
148+
147149 if self ._ostype is None :
148150 self ._ostype = guessed_ostype
149151 if self ._archtype is None :
150152 self ._archtype = guessed_archtype
151- if self .archendian is None :
152153 self ._archendian = guessed_archendian
153154
154155 if not ql_is_valid_ostype (self ._ostype ):
@@ -157,10 +158,13 @@ def __init__(
157158 if not ql_is_valid_arch (self ._archtype ):
158159 raise QlErrorArch ("Invalid Arch %s" % self ._archtype )
159160
160- ##########
161- # Loader #
162- ##########
163161
162+
163+
164+ #######################################
165+ # Loader and General Purpose OS check #
166+ #######################################
167+ self ._gpos = True if self ._ostype in (QL_OS_ALL ) else False
164168 self ._loader = loader_setup (self ._ostype , self )
165169
166170 #####################
@@ -169,7 +173,6 @@ def __init__(
169173 self ._profile , debugmsg = profile_setup (self )
170174
171175 # Log's configuration
172-
173176 self ._log_file_fd , self ._log_filter = ql_setup_logger (self ,
174177 self ._log_file ,
175178 self ._console ,
@@ -188,25 +191,23 @@ def __init__(
188191 self ._archbit = ql_get_arch_bits (self ._archtype )
189192 self ._pointersize = (self .archbit // 8 )
190193
191- # Endian for shellcode needs to set manually
192- if self ._code :
193- self ._archendian = QL_ENDIAN .EL
194- if bigendian == True and self ._archtype in (QL_ARCH_ENDIAN ):
195- self ._archendian = QL_ENDIAN .EB
194+
195+ if bigendian == True and self ._archtype in (QL_ARCH_ENDIAN ):
196+ self ._archendian = QL_ENDIAN .EB
197+
196198
197199 # Once we finish setting up archendian and arcbit, we can init QlCoreStructs.
198200 QlCoreStructs .__init__ (self , self ._archendian , self ._archbit )
199201
200202 ##############
201203 # Components #
202204 ##############
203-
204- if not self ._interpreter :
205+ if self ._gpos or self ._baremetal :
205206 self ._mem = component_setup ("os" , "memory" , self )
206207 self ._reg = component_setup ("arch" , "register" , self )
207-
208- if self ._baremetal :
209- self ._hw = component_setup ("hw" , "hw" , self )
208+
209+ if self ._baremetal :
210+ self ._hw = component_setup ("hw" , "hw" , self )
210211
211212 self ._arch = arch_setup (self .archtype , self )
212213
@@ -215,29 +216,27 @@ def __init__(
215216 QlCoreHooks .__init__ (self , self .uc )
216217
217218 # Setup Outpt
218- if not self ._interpreter :
219+ if self . _gpos or self ._baremetal :
219220 self .arch .utils .setup_output ()
220221
221- if not self ._interpreter :
222- if not self ._baremetal :
223- self ._os = os_setup (self .archtype , self .ostype , self )
222+ if self ._gpos :
223+ self ._os = os_setup (self .archtype , self .ostype , self )
224224
225- if stdin is not None :
226- self ._os .stdin = stdin
225+ if stdin is not None :
226+ self ._os .stdin = stdin
227227
228- if stdout is not None :
229- self ._os .stdout = stdout
228+ if stdout is not None :
229+ self ._os .stdout = stdout
230230
231- if stderr is not None :
232- self ._os .stderr = stderr
231+ if stderr is not None :
232+ self ._os .stderr = stderr
233233
234234 # Run the loader
235235 self .loader .run ()
236236
237- if not self ._interpreter :
238- if not self ._baremetal :
239- # Add extra guard options when configured to do so
240- self ._init_stop_guard ()
237+ if self ._gpos :
238+ # Add extra guard options when configured to do so
239+ self ._init_stop_guard ()
241240
242241 #####################
243242 # Qiling Components #
@@ -654,6 +653,18 @@ def baremetal(self, b):
654653 self ._baremetal = b
655654
656655
656+ @property
657+ def gpos (self ) -> bool :
658+ """ Raw uc instance.
659+
660+ Type: Ucgit
661+ """
662+ return self ._gpos
663+
664+ @gpos .setter
665+ def gpos (self , o ):
666+ self ._gpos = o
667+
657668 @property
658669 def stop_options (self ) -> "QlStopOptions" :
659670 """ The stop options configured:
0 commit comments