proj: Correct parsing in python
This commit is contained in:
@@ -2355,9 +2355,9 @@ int sym(getaddrinfo)(const char *restrict node, const char *restrict service, co
|
|||||||
}
|
}
|
||||||
const int ret = __real_getaddrinfo(node, service, hints, res);
|
const int ret = __real_getaddrinfo(node, service, hints, res);
|
||||||
if (res != NULL) {
|
if (res != NULL) {
|
||||||
msg("return %i:%s; res=%qi", ret, getaddrinfoerror(ret), *res);
|
msg("return %i:%s; errno %s; res=%qi", ret, getaddrinfoerror(ret), strerrorname_np(errno), *res);
|
||||||
} else {
|
} else {
|
||||||
msg("return %i:%s", ret, getaddrinfoerror(ret));
|
msg("return %i:%s; errno %s", ret, getaddrinfoerror(ret), strerrorname_np(errno));
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,9 +109,9 @@ class Handler(StreamRequestHandler):
|
|||||||
def parse_arg(argument: str) -> tuple[any, int]:
|
def parse_arg(argument: str) -> tuple[any, int]:
|
||||||
if argument == '':
|
if argument == '':
|
||||||
return None, 0
|
return None, 0
|
||||||
m = re.match(r'^\s*(\(nil\)|NULL|null|nullptr)\s*(,|$)', argument)
|
m = re.match(r'^\s*(\(nil\)|NULL|null|nullptr)\s*(,|]|}|$)', argument)
|
||||||
if m:
|
if m:
|
||||||
return 0, len(m.group(0))
|
return 0, len(m.group(0)) - (1 if m.group(2) in ('}', ']') else 0)
|
||||||
m = re.match(r'\s*"', argument)
|
m = re.match(r'\s*"', argument)
|
||||||
if m:
|
if m:
|
||||||
idx = len(m.group(0)) - 1
|
idx = len(m.group(0)) - 1
|
||||||
@@ -120,17 +120,37 @@ class Handler(StreamRequestHandler):
|
|||||||
if idx < len(argument) and argument[idx] == ',':
|
if idx < len(argument) and argument[idx] == ',':
|
||||||
idx += 1
|
idx += 1
|
||||||
return s, idx
|
return s, idx
|
||||||
m = re.match(r'^\s*(.*?)([,:]|$)', argument)
|
m = re.match(r'\s*\[', argument)
|
||||||
|
if m:
|
||||||
|
idx = len(m.group(0))
|
||||||
|
s, i = Handler.parse_args(argument[idx:])
|
||||||
|
idx += i
|
||||||
|
if idx < len(argument) and argument[idx] == ',':
|
||||||
|
idx += 1
|
||||||
|
return s, idx
|
||||||
|
m = re.match(r'\s*\{', argument)
|
||||||
|
if m:
|
||||||
|
idx = len(m.group(0))
|
||||||
|
s, i = Handler.parse_args(argument[idx:], named=True)
|
||||||
|
idx += i
|
||||||
|
if idx < len(argument) and argument[idx] == ',':
|
||||||
|
idx += 1
|
||||||
|
return s, idx
|
||||||
|
m = re.match(r'^\s*(.*?)([,:\]}]|$)', argument)
|
||||||
a, e = m.group(1), m.group(2)
|
a, e = m.group(1), m.group(2)
|
||||||
idx = len(m.group(0))
|
idx = len(m.group(0))
|
||||||
if a.startswith('0x'):
|
if a.startswith('0x'):
|
||||||
val = int(a[2:], 16)
|
val = int(a[2:], 16)
|
||||||
elif a.startswith('0') and len(a) > 1:
|
elif a.startswith('0') and len(a) > 1:
|
||||||
val = int(a[1:], 8)
|
val = int(a[1:], 8)
|
||||||
|
elif a in ('(nil)', 'NULL', 'null', 'nullptr'):
|
||||||
|
val = 0
|
||||||
else:
|
else:
|
||||||
val = int(a, 10)
|
val = int(a, 10)
|
||||||
if e in (',', ''):
|
if e in (',', ''):
|
||||||
return val, idx
|
return val, idx
|
||||||
|
elif e in ('}', ']'):
|
||||||
|
return val, idx - 1
|
||||||
if argument[idx] == '[':
|
if argument[idx] == '[':
|
||||||
idx += 1
|
idx += 1
|
||||||
l, i = Handler.parse_args(argument[idx:])
|
l, i = Handler.parse_args(argument[idx:])
|
||||||
@@ -155,18 +175,12 @@ class Handler(StreamRequestHandler):
|
|||||||
idx += 1
|
idx += 1
|
||||||
return (val, s), idx
|
return (val, s), idx
|
||||||
elif argument[idx] == '{':
|
elif argument[idx] == '{':
|
||||||
m = re.match(r'^[^}]*}', argument[idx:])
|
idx += 1
|
||||||
if not m or not m.group(0).startswith('{') or not m.group(0).endswith('}'):
|
l, i = Handler.parse_args(argument[idx:], named=True)
|
||||||
raise ValueError()
|
idx += i
|
||||||
value = m.group(0)
|
|
||||||
idx += len(value)
|
|
||||||
if idx < len(argument) and argument[idx] == ',':
|
if idx < len(argument) and argument[idx] == ',':
|
||||||
idx += 1
|
idx += 1
|
||||||
entries = {}
|
return (val, list(l)), idx
|
||||||
for e in [v.strip() for v in value[1:-1].split(',') if len(v.strip()) > 0]:
|
|
||||||
k, v = e.split(':', 1)
|
|
||||||
entries[k.strip()] = Handler.parse_arg(v)[0]
|
|
||||||
return (val, entries), idx
|
|
||||||
else:
|
else:
|
||||||
m = re.match(r'[A-Z0-9_]+', argument[idx:])
|
m = re.match(r'[A-Z0-9_]+', argument[idx:])
|
||||||
if not m:
|
if not m:
|
||||||
@@ -178,17 +192,27 @@ class Handler(StreamRequestHandler):
|
|||||||
return (val, value), idx
|
return (val, value), idx
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_args(arguments: str) -> tuple[tuple, int]:
|
def parse_args(arguments: str, named: bool = False) -> tuple[tuple or dict, int]:
|
||||||
args = []
|
# FIXME parse dicts in lists, dicts in dicts, ...
|
||||||
|
print(named, arguments)
|
||||||
|
args = [] if not named else {}
|
||||||
idx = 0
|
idx = 0
|
||||||
|
name = None
|
||||||
while idx < len(arguments):
|
while idx < len(arguments):
|
||||||
if arguments[idx] == ']':
|
if arguments[idx] == ']' and not named or arguments[idx] == '}' and named:
|
||||||
idx += 1
|
idx += 1
|
||||||
break
|
break
|
||||||
|
elif named:
|
||||||
|
m = re.match(r'^\s*([^:]+):', arguments[idx:])
|
||||||
|
idx += len(m.group(0))
|
||||||
|
name = m.group(1)
|
||||||
val, i = Handler.parse_arg(arguments[idx:])
|
val, i = Handler.parse_arg(arguments[idx:])
|
||||||
args.append(val)
|
if named:
|
||||||
|
args[name] = val
|
||||||
|
else:
|
||||||
|
args.append(val)
|
||||||
idx += i
|
idx += i
|
||||||
return tuple(args), idx
|
return tuple(args) if not named else args, idx
|
||||||
|
|
||||||
def handle_msg(self, msg: bytes):
|
def handle_msg(self, msg: bytes):
|
||||||
timestamp, pid, tid, data = msg.rstrip(b'\n').split(b' ', 3)
|
timestamp, pid, tid, data = msg.rstrip(b'\n').split(b' ', 3)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ def main() -> None:
|
|||||||
'INTERCEPT': 'unix:' + socket_name,
|
'INTERCEPT': 'unix:' + socket_name,
|
||||||
'INTERCEPT_VERBOSE': '1',
|
'INTERCEPT_VERBOSE': '1',
|
||||||
'INTERCEPT_FUNCTIONS': '*',
|
'INTERCEPT_FUNCTIONS': '*',
|
||||||
'INTERCEPT_LIBRARIES': '*,-/lib*,-/usr/lib*',
|
'INTERCEPT_LIBRARIES': ','.join(['*', '-/lib*', '-/usr/lib*']),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ def main() -> None:
|
|||||||
'INTERCEPT': 'unix:' + socket_name,
|
'INTERCEPT': 'unix:' + socket_name,
|
||||||
'INTERCEPT_VERBOSE': '1',
|
'INTERCEPT_VERBOSE': '1',
|
||||||
'INTERCEPT_FUNCTIONS': ','.join(['malloc', 'calloc', 'realloc', 'reallocarray', 'free', 'getaddrinfo', 'freeaddrinfo']),
|
'INTERCEPT_FUNCTIONS': ','.join(['malloc', 'calloc', 'realloc', 'reallocarray', 'free', 'getaddrinfo', 'freeaddrinfo']),
|
||||||
'INTERCEPT_LIBRARIES': '*,-/lib*,-/usr/lib*',
|
'INTERCEPT_LIBRARIES': ','.join(['*', '-/lib*', '-/usr/lib*']),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ def main() -> None:
|
|||||||
'INTERCEPT': 'unix:' + socket_name,
|
'INTERCEPT': 'unix:' + socket_name,
|
||||||
'INTERCEPT_VERBOSE': '1',
|
'INTERCEPT_VERBOSE': '1',
|
||||||
'INTERCEPT_FUNCTIONS': '*',
|
'INTERCEPT_FUNCTIONS': '*',
|
||||||
'INTERCEPT_LIBRARIES': '*,-/lib*,-/usr/lib*',
|
'INTERCEPT_LIBRARIES': ','.join(['*', '-/lib*', '-/usr/lib*']),
|
||||||
})
|
})
|
||||||
for i, name in enumerate(ctx['call_sequence']):
|
for i, name in enumerate(ctx['call_sequence']):
|
||||||
errors = [r[1] for r in ctx['results'] if r[0] == i]
|
errors = [r[1] for r in ctx['results'] if r[0] == i]
|
||||||
|
|||||||
Reference in New Issue
Block a user