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

Class QlFsMapper

qiling/os/mapper.py:64–259  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62
63
64class QlFsMapper:
65
66 def __init__(self, path: QlOsPath):
67 self._mapping: MutableMapping[str, Any] = {}
68 self.path = path
69
70 def __contains__(self, vpath: str) -> bool:
71 # canonicalize the path first
72 absvpath = self.path.virtual_abspath(vpath)
73
74 return absvpath in self._mapping
75
76 def has_mapping(self, vpath: str) -> bool:
77 """Check whether a specific virtrual path has a binding.
78
79 Args:
80 vpath: virtual path name to check
81
82 Returns: `True` if the specified virtual path has been bound, `False` otherwise.
83 """
84
85 return vpath in self
86
87 def __len__(self) -> int:
88 return len(self._mapping)
89
90 def mapping_count(self) -> int:
91 """Count of currently existing bindings.
92 """
93
94 return len(self)
95
96 def __open_mapped(self, absvpath: str, opener: Callable, *args) -> Any:
97 """Internal method user for opening an existing mapped object.
98
99 Args:
100 absvpath: absolute virtual path name
101 opener: a method to use to open the target host path
102 *args: arguments to the opener method
103 """
104
105 mapped = self._mapping[absvpath]
106
107 # mapped to a file name on the host file system
108 if isinstance(mapped, str):
109 obj = opener(mapped, *args)
110
111 # mapped to a class or a method
112 elif callable(mapped):
113 obj = mapped()
114
115 # mapped to another kind of object
116 else:
117 obj = mapped
118
119 return obj
120
121 def __open_new(self, absvpath: str, opener: Callable, *args) -> Any:

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected