MCPcopy Create free account
hub / github.com/blacklanternsecurity/bbot / gen_chord_data

Function gen_chord_data

bbot/scripts/docs.py:26–91  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

24
25
26def gen_chord_data():
27 # This function generates the dataset for the chord graph in the documentation
28 # showing relationships between BBOT modules and their consumed/produced event types
29 preloaded_mods = sorted(MODULE_LOADER.preloaded().items(), key=lambda x: x[0])
30
31 entity_lookup_table = {}
32 rels = []
33 entities = {}
34 entity_counter = 1
35
36 def add_entity(entity, parent_id):
37 if entity not in entity_lookup_table:
38 nonlocal entity_counter
39 e_id = entity_counter
40 entity_counter += 1
41 entity_lookup_table[entity] = e_id
42 entity_lookup_table[e_id] = entity
43 entities[e_id] = {"id": e_id, "name": entity, "parent": parent_id, "consumes": [], "produces": []}
44 return entity_lookup_table[entity]
45
46 # create entities for all the modules and event types
47 for module, preloaded in preloaded_mods:
48 watched = [e for e in preloaded["watched_events"] if e != "*"]
49 produced = [e for e in preloaded["produced_events"] if e != "*"]
50 if watched or produced:
51 m_id = add_entity(module, 99999999)
52 for event_type in watched:
53 e_id = add_entity(event_type, 88888888)
54 entities[m_id]["consumes"].append(e_id)
55 entities[e_id]["consumes"].append(m_id)
56 for event_type in produced:
57 e_id = add_entity(event_type, 88888888)
58 entities[m_id]["produces"].append(e_id)
59 entities[e_id]["produces"].append(m_id)
60
61 def add_rel(incoming, outgoing, t):
62 if incoming == "*" or outgoing == "*":
63 return
64 i_id = entity_lookup_table[incoming]
65 o_id = entity_lookup_table[outgoing]
66 rels.append({"source": i_id, "target": o_id, "type": t})
67
68 # create all the module <--> event type relationships
69 for module, preloaded in preloaded_mods:
70 for event_type in preloaded["watched_events"]:
71 add_rel(module, event_type, "consumes")
72 for event_type in preloaded["produced_events"]:
73 add_rel(event_type, module, "produces")
74
75 # write them to JSON files
76 data_dir = Path(__file__).parent.parent.parent / "docs" / "data" / "chord_graph"
77 data_dir.mkdir(parents=True, exist_ok=True)
78 entity_file = data_dir / "entities.json"
79 rels_file = data_dir / "rels.json"
80
81 entities = [
82 {"id": 77777777, "name": "root"},
83 {"id": 99999999, "name": "module", "parent": 77777777},

Callers 1

update_docsFunction · 0.85

Calls 6

add_entityFunction · 0.85
add_relFunction · 0.85
openFunction · 0.85
preloadedMethod · 0.80
valuesMethod · 0.80
dumpMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…