Skip to content

Commit 97002fe

Browse files
authored
Merge pull request #1336 from elicn/dev-improv
Periodic maintenance PR
2 parents bb0c5f3 + 4c53a43 commit 97002fe

File tree

33 files changed

+1834
-967
lines changed

33 files changed

+1834
-967
lines changed

examples/scripts/dllscollector.bat

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ CALL :collect_dll64 shlwapi.dll
118118
CALL :collect_dll64 user32.dll
119119
CALL :collect_dll64 vcruntime140.dll
120120
CALL :collect_dll64 vcruntime140d.dll
121+
CALL :collect_dll64 vcruntime140_1.dll
122+
CALL :collect_dll64 vcruntime140_1d.dll
121123
CALL :collect_dll64 win32u.dll
122124
CALL :collect_dll64 winhttp.dll
123125
CALL :collect_dll64 wininet.dll

qiling/core.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
class Qiling(QlCoreHooks, QlCoreStructs):
3333
def __init__(
3434
self,
35-
argv: Sequence[str] = None,
35+
argv: Sequence[str] = [],
3636
rootfs: str = r'.',
3737
env: MutableMapping[AnyStr, AnyStr] = {},
38-
code: bytes = None,
38+
code: Optional[bytes] = None,
3939
ostype: Union[str, QL_OS] = None,
4040
archtype: Union[str, QL_ARCH] = None,
4141
verbose: QL_VERBOSE = QL_VERBOSE.DEFAULT,
@@ -90,18 +90,26 @@ def __init__(
9090
##############
9191
# argv setup #
9292
##############
93-
if argv is None:
94-
argv = ['qilingcode']
93+
if argv:
94+
if code:
95+
raise AttributeError('argv and code are mutually execlusive')
9596

96-
elif not os.path.exists(argv[0]):
97-
raise QlErrorFileNotFound(f'Target binary not found: "{argv[0]}"')
97+
target = argv[0]
98+
99+
if not os.path.isfile(target):
100+
raise QlErrorFileNotFound(f'Target binary not found: "{target}"')
101+
else:
102+
# an empty argv list means we are going to execute a shellcode. to keep
103+
# the 'path' api compatible, we insert a dummy placeholder
104+
105+
argv = ['']
98106

99107
self._argv = argv
100108

101109
################
102110
# rootfs setup #
103111
################
104-
if not os.path.exists(rootfs):
112+
if not os.path.isdir(rootfs):
105113
raise QlErrorFileNotFound(f'Target rootfs not found: "{rootfs}"')
106114

107115
self._rootfs = rootfs
@@ -697,11 +705,11 @@ def restore(self, saved_states: Mapping[str, Any] = {}, *, snapshot: Optional[st
697705

698706
# Map "ql_path" to any objects which implements QlFsMappedObject.
699707
def add_fs_mapper(self, ql_path: Union["PathLike", str], real_dest):
700-
self.os.fs_mapper.add_fs_mapping(ql_path, real_dest)
708+
self.os.fs_mapper.add_mapping(ql_path, real_dest)
701709

702710
# Remove "ql_path" mapping.
703711
def remove_fs_mapper(self, ql_path: Union["PathLike", str]):
704-
self.os.fs_mapper.remove_fs_mapping(ql_path)
712+
self.os.fs_mapper.remove_mapping(ql_path)
705713

706714
# push to stack bottom, and update stack register
707715
def stack_push(self, data):
@@ -757,14 +765,16 @@ def emu_start(self, begin: int, end: int, timeout: int = 0, count: int = 0):
757765
if getattr(self.arch, '_init_thumb', False):
758766
begin |= 0b1
759767

760-
self._state = QL_STATE.STARTED
761-
762768
# reset exception status before emulation starts
763769
self._internal_exception = None
764770

771+
self._state = QL_STATE.STARTED
772+
765773
# effectively start the emulation. this returns only after uc.emu_stop is called
766774
self.uc.emu_start(begin, end, timeout, count)
767775

776+
self._state = QL_STATE.STOPPED
777+
768778
# if an exception was raised during emulation, propagate it up
769779
if self.internal_exception is not None:
770780
raise self.internal_exception

0 commit comments

Comments
 (0)