MCPcopy Create free account
hub / github.com/Fadi002/de4py / _decode_bytes_fromhex

Method _decode_bytes_fromhex

de4py/engines/onyx/string_decoder.py:271–291  ·  view source on GitHub ↗
(self, source: str)

Source from the content-addressed store, hash-verified

269 return pattern.sub(decode_hex, source)
270
271 def _decode_bytes_fromhex(self, source: str) -> str:
272 p1 = re.compile(
273 r'bytes\.fromhex\s*\(\s*["\']([0-9a-fA-F\s]+)["\']\s*\)'
274 r'(?:\.decode\s*\([^)]*\))?'
275 )
276 def d1(m):
277 try:
278 return repr(bytes.fromhex(m.group(1).replace(' ','').replace('\n','')).decode('utf-8', errors='replace'))
279 except Exception:
280 return m.group(0)
281 source = p1.sub(d1, source)
282 p2 = re.compile(
283 r'codecs\.decode\s*\(\s*b?["\']([0-9a-fA-F]+)["\']\s*,\s*["\']hex(?:_codec)?["\']\s*\)'
284 r'(?:\.decode\s*\([^)]*\))?'
285 )
286 def d2(m):
287 try:
288 return repr(bytes.fromhex(m.group(1)).decode('utf-8', errors='replace'))
289 except Exception:
290 return m.group(0)
291 return p2.sub(d2, source)
292
293 def _decode_bytearray_literals(self, source: str) -> str:
294 p1 = re.compile(r'bytearray\s*\(\s*(b"[^"]*"|b\'[^\']*\')\s*\)(?:\.decode\s*\([^)]*\))?')

Callers 1

_single_passMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected