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

Method __repl

qiling/os/utils.py:180–234  ·  view source on GitHub ↗

Convert printf format string tokens into Python's.

(m: re.Match)

Source from the content-addressed store, hash-verified

178 }
179
180 def __repl(m: re.Match) -> str:
181 """Convert printf format string tokens into Python's.
182 """
183
184 if m['follows'] == '%':
185 return '%%'
186
187 else:
188 flags = m['flags'] or ''
189
190 fill = ' ' if ' ' in flags else ''
191 align = '<' if '-' in flags else ''
192 sign = '+' if '+' in flags else ''
193 pound = '#' if '#' in flags else ''
194 zeros = '0' if '0' in flags else ''
195
196 width = m['width'] or ''
197
198 if width == '*':
199 width = f'{next(va_list)}'
200
201 prec = m['precision'] or ''
202
203 if prec == '*':
204 prec = f'{next(va_list)}'
205
206 if prec:
207 prec = f'.{prec}'
208
209 typ = m['type']
210 arg = next(va_list)
211
212 if typ == 's':
213 typ = 's'
214 arg = read_str[wstring](arg)
215
216 elif typ == 'S':
217 typ = 's'
218 arg = read_str[not wstring](arg)
219
220 elif typ == 'Z':
221 # note: ANSI_STRING and UNICODE_STRING have identical layout
222 ucstr_struct = make_unicode_string(self.ql.arch.bits)
223
224 with ucstr_struct.ref(self.ql.mem, arg) as ucstr_obj:
225 typ = 's'
226 arg = read_str[wstring](ucstr_obj.Buffer)
227
228 elif typ == 'p':
229 pound = '#'
230 typ = 'x'
231
232 repl_args.append(arg)
233
234 return f'%{fill}{align}{sign}{pound}{zeros}{width}{prec}{typ}'
235
236 out = fmtstr.sub(__repl, format)
237

Callers

nothing calls this directly

Calls 3

make_unicode_stringFunction · 0.90
refMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected