@@ -125,29 +125,24 @@ def __init__(
125125 self ._ostype = ostype_convert (self ._ostype .lower ())
126126
127127 if self ._code == None :
128- self ._code = "qiling "
128+ self ._code = "qilingcode "
129129 if self ._argv is None :
130130 self ._argv = ["qilingcode" ]
131131 if self ._rootfs is None :
132132 self ._rootfs = "."
133133
134134 self ._interpreter = True if self ._archtype in (QL_ARCH_INTERPRETER ) else False
135135 self ._baremetal = True if self ._archtype in (QL_ARCH_BAREMETAL ) else False
136+ self ._path = (str (self ._argv [0 ]))
137+ self ._targetname = ntpath .basename (self ._argv [0 ])
136138
137139 # file check
138- if self ._code is None :
140+ if ( self ._path and self . _rootfs ) and self . _code == None :
139141 if not os .path .exists (str (self ._argv [0 ])):
140142 raise QlErrorFileNotFound ("Target binary not found: %s" % (self ._argv [0 ]))
141143 if not os .path .exists (self ._rootfs ):
142144 raise QlErrorFileNotFound ("Target rootfs not found" )
143145
144- self ._path = (str (self ._argv [0 ]))
145- self ._targetname = ntpath .basename (self ._argv [0 ])
146-
147- ##########
148- # Loader #
149- ##########
150- if self ._code is None :
151146 guessed_archtype , guessed_ostype , guessed_archendian = ql_guess_emu_env (self ._path )
152147 if self ._ostype is None :
153148 self ._ostype = guessed_ostype
@@ -162,6 +157,10 @@ def __init__(
162157 if not ql_is_valid_arch (self ._archtype ):
163158 raise QlErrorArch ("Invalid Arch %s" % self ._archtype )
164159
160+ ##########
161+ # Loader #
162+ ##########
163+
165164 self ._loader = loader_setup (self ._ostype , self )
166165
167166 #####################
@@ -736,33 +735,25 @@ def run(self, begin=None, end=None, timeout=0, count=0, code = None):
736735 if self ._debugger != False and self ._debugger != None :
737736 self ._debugger = debugger_setup (self ._debugger , self )
738737
739- if not self .interpreter :
740- if not self .baremetal :
741- self .write_exit_trap ()
742- # patch binary
743- self .__enable_bin_patch ()
744-
745- # emulate the binary
746- self .os .run ()
747-
748738 if self .interpreter :
749- if code == None :
750- return self .arch .run (self ._code )
751- else :
752- return self .arch .run (code )
753-
754- if self .baremetal :
739+ return self .arch .run (code )
740+ elif self .baremetal :
755741 self .__enable_bin_patch ()
756742 if self .count <= 0 :
757743 self .count = - 1
758- self .arch .run (count = self .count , end = self .exit_point )
759-
744+ self .arch .run (count = self .count , end = self .exit_point )
745+ else :
746+ self .write_exit_trap ()
747+ # patch binary
748+ self .__enable_bin_patch ()
749+ # emulate the binary
750+ self .os .run ()
751+
760752 # run debugger
761753 if self ._debugger != False and self ._debugger != None :
762754 self ._debugger .run ()
763755
764756
765-
766757 # patch code to memory address
767758 def patch (self , addr , code , file_name = b'' ):
768759 if file_name == b'' :
0 commit comments