MCPcopy Create free account
hub / github.com/qilingframework/qiling / __init__

Method __init__

qiling/os/os.py:29–104  ·  view source on GitHub ↗
(self, ql: Qiling, resolvers: Mapping[Any, Resolver] = {})

Source from the content-addressed store, hash-verified

27 Resolver = Callable[[int], Any]
28
29 def __init__(self, ql: Qiling, resolvers: Mapping[Any, Resolver] = {}):
30 self.ql = ql
31
32 # standard streams overrides (elicn: should they be io.IOBase ?)
33 self._stdin: TextIO
34 self._stdout: TextIO
35 self._stderr: TextIO
36
37 self.utils = QlOsUtils(ql)
38 self.stats = QlOsStats()
39 self.fcall: QlFunctionCall
40 self.child_processes = False
41 self.thread_management = None
42 self.profile = self.ql.profile
43 self.exit_code = 0
44
45 if self.type in QL_OS_POSIX + (QL_OS.WINDOWS, QL_OS.DOS):
46 cwd = self.profile.get("MISC", "current_path")
47
48 self.path = QlOsPath(ql.rootfs, cwd, self.type)
49 self.fs_mapper = QlFsMapper(self.path)
50
51 self.user_defined_api: Dict[QL_INTERCEPT, Dict[Union[int, str], Callable]] = {
52 QL_INTERCEPT.CALL: {},
53 QL_INTERCEPT.ENTER: {},
54 QL_INTERCEPT.EXIT: {}
55 }
56
57 try:
58 # Qiling may be used on interactive shells (ex: IDLE) or embedded python
59 # interpreters (ex: IDA Python). such environments use their own version
60 # for the standard streams which usually do not support certain operations,
61 # such as fileno(). here we use this to determine how we are going to use
62 # the environment standard streams
63
64 # IDAPython returns True for stdin but False for stdout and stderr so checking
65 # all three
66 sys.stdin.fileno()
67 sys.stdout.fileno()
68 sys.stderr.fileno()
69 except (UnsupportedOperation, AttributeError):
70 # Qiling is used on an interactive shell or embedded python interpreter.
71 # if the internal stream buffer is accessible, we should use it
72 self._stdin = getattr(sys.stdin, 'buffer', sys.stdin)
73 self._stdout = getattr(sys.stdout, 'buffer', sys.stdout)
74 self._stderr = getattr(sys.stderr, 'buffer', sys.stderr)
75 else:
76 # Qiling is used in a script, or on an environment that supports ordinary
77 # stanard streams
78 self._stdin = PersistentQlFile('stdin', sys.stdin.fileno())
79 self._stdout = PersistentQlFile('stdout', sys.stdout.fileno())
80 self._stderr = PersistentQlFile('stderr', sys.stderr.fileno())
81
82 # defult exit point
83 self.exit_point = {
84 16: 0xfffff, # 20bit address lane
85 32: 0x8fffffff,
86 64: 0xffffffffffffffff

Callers

nothing calls this directly

Calls 11

QlOsUtilsClass · 0.85
QlOsStatsClass · 0.85
QlOsPathClass · 0.85
QlFsMapperClass · 0.85
PersistentQlFileClass · 0.85
read_cstringMethod · 0.80
read_wstringMethod · 0.80
read_guidMethod · 0.80
getMethod · 0.45
filenoMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected