12 header =
"""// SPDX-FileCopyrightText: 2019-2021 RizinOrg <info@rizin.re>
13 // SPDX-FileCopyrightText: 2019 Francesco Tamagni <mrmacete@protonmail.ch>
14 // SPDX-License-Identifier: LGPL-3.0-only
19 * This file is generated in this way:
21 * python3 build_mig_index.py ~/xnu-4570.51.1/bsd/kern/trace_codes traps.json > mig_index.h
24 * The traps.json file is generated from any dyld cache using the machtraps.py rzpipe script.
32 with open(trace_codes,
"r")
as f:
34 splitted = re.compile(
"\s+").split(line.rstrip(
"\n"))
36 code =
int(splitted[0], 0)
37 klass = code & 0xFF000000
38 if klass == 0xFF000000:
39 name = name.replace(
"MSG_",
"")
40 num = (code & 0x00FFFFFF) >> 2
43 with open(trap_json,
"r")
as f:
44 traps = json.loads(f.read())
49 data[num] = routine[
"name"]
53 result.append((num, data[num]))
55 result.sort(key=
lambda x: x[0])
58 print(
"#ifndef RZ_MIG_INDEX_H")
59 print(
"#define RZ_MIG_INDEX_H\n")
61 print(
"#define RZ_MIG_INDEX_LEN %d\n" % (
len(data) * 2))
63 print(
"static const char *mig_index[RZ_MIG_INDEX_LEN] = {")
65 print(
'\t"%d", "%s",' % pair)
71 if __name__ ==
"__main__":
73 print(
"usage %s bsd/kern/trace_codes traps.json" % sys.argv[0])
76 convert(sys.argv[1], sys.argv[2])
def convert(trace_codes, trap_json)