MCPcopy Index your code
hub / github.com/keystone-engine/keypatch / convert_hexstr

Function convert_hexstr

keypatch.py:51–79  ·  view source on GitHub ↗
(code)

Source from the content-addressed store, hash-verified

49
50# return a normalized code, or None if input is invalid
51def convert_hexstr(code):
52 # normalize code
53 code = code.lower()
54 code = code.replace(' ', '') # remove space
55 code = code.replace('h', '') # remove trailing 'h' in 90h
56 code = code.replace('0x', '') # remove 0x
57 code = code.replace('\\x', '') # remove \x
58 code = code.replace(',', '') # remove ,
59 code = code.replace(';', '') # remove ;
60 code = code.replace('"', '') # remove "
61 code = code.replace("'", '') # remove '
62 code = code.replace("+", '') # remove +
63
64 # single-digit hexcode?
65 if len(code) == 1 and ((code >= '0' and code <= '9') or (code >= 'a' and code <= 'f')):
66 # stick 0 in front (so 'a' --> '0a')
67 code = '0' + code
68
69 # odd-length is invalid
70 if len(code) % 2 != 0:
71 return None
72
73 try:
74 hex_data = code.decode('hex')
75 # we want a list of int
76 return [ord(i) for i in hex_data]
77 except:
78 # invalid hex
79 return None
80
81# download a file from @url, then return (result, file-content)
82# return (0, content) on success, or ({1|2}, None) on download failure

Callers 1

fill_codeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected