-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphVisualizer.html
More file actions
148 lines (134 loc) · 5.93 KB
/
GraphVisualizer.html
File metadata and controls
148 lines (134 loc) · 5.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<!DOCTYPE html>
<html>
<head>
<title>Bytecode Graph Visualizer (File Load)</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/cytoscape/3.26.0/cytoscape.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dagre/0.8.5/dagre.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/cytoscape-dagre@2.5.0/cytoscape-dagre.min.js"></script>
<style>
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; display: flex; flex-direction: column; height: 100vh; margin: 0; background: #f8f9fa; }
#toolbar { padding: 15px 20px; background: #ffffff; border-bottom: 1px solid #dee2e6; display: flex; gap: 20px; align-items: center; box-shadow: 0 2px 4px rgba(0,0,0,0.05); z-index: 10; }
#cy { flex: 1; background: #ffffff; width: 100%; }
.filter-group { display: flex; gap: 10px; align-items: center; padding-left: 15px; border-left: 1px solid #ccc; }
label { font-size: 13px; cursor: pointer; display: flex; align-items: center; gap: 5px; }
input[type="file"] { font-size: 13px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
</style>
</head>
<body>
<div id="toolbar">
<input type="file" id="file-input" accept=".json">
<div class="filter-group">
<strong>Edges:</strong>
<label><span class="legend-dot" style="background:#767061"></span><input type="checkbox" class="filter" value="cfg" checked> CFG</label>
<label><span class="legend-dot" style="background:#00c4ff"></span><input type="checkbox" class="filter" value="dfg" checked> DFG</label>
<label><span class="legend-dot" style="background:#b453f5"></span><input type="checkbox" class="filter" value="cdg" checked> CDG</label>
<label><span class="legend-dot" style="background:#6dcd00"></span><input type="checkbox" class="filter" value="ddg" checked> DDG</label>
<label><span class="legend-dot" style="background:#e52c1a"></span><input type="checkbox" class="filter" value="ex" checked> EX</label>
</div>
</div>
<div id="cy"></div>
<script>
let cy;
document.getElementById('file-input').addEventListener('change', function(e) {
const file = e.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
try {
const data = JSON.parse(e.target.result);
renderGraph(data);
} catch (err) {
alert("JSON 파일을 읽는 중 오류가 발생했습니다.");
}
};
reader.readAsText(file);
});
function renderGraph(data) {
const elements = [];
// Nodes
data.nodes.forEach(node => {
elements.push({
data: {
id: node.offset.toString(),
label: `[${node.offset}]\n${node.mnemonic}\n${node.operands}`
}
});
});
// Edges Helper
const addEdges = (edgeList, type) => {
if (!edgeList) return;
edgeList.forEach((edge, index) => {
elements.push({
data: {
id: `${type}-${index}`,
source: edge.src.toString(),
target: edge.dst.toString()
},
classes: type
});
});
};
addEdges(data.edges.cfg, 'cfg');
addEdges(data.edges.dfg, 'dfg');
addEdges(data.edges.cdg, 'cdg');
addEdges(data.edges.ddg, 'ddg');
addEdges(data.edges.ex, 'ex');
cy = cytoscape({
container: document.getElementById('cy'),
elements: elements,
style: [
{
selector: 'node',
style: {
'label': 'data(label)',
'text-wrap': 'wrap',
'background-color': '#ffffff',
'border-width': 1.5,
'border-color': '#333',
'width': '100px',
'height': '60px',
'shape': 'round-rectangle',
'font-size': '11px',
'text-valign': 'center',
'text-halign': 'center',
'color': '#2c3e50'
}
},
{
selector: 'edge',
style: {
'width': 2,
'curve-style': 'bezier',
'target-arrow-shape': 'triangle',
'arrow-scale': 1.2
}
},
{ selector: '.cfg', style: { 'line-color': '#767061', 'target-arrow-color': '#767061' } },
{ selector: '.dfg', style: { 'line-color': '#00c4ff', 'target-arrow-color': '#00c4ff', 'line-style': 'dashed' } },
{ selector: '.cdg', style: { 'line-color': '#b453f5', 'target-arrow-color': '#b453f5' } },
{ selector: '.ddg', style: { 'line-color': '#6dcd00', 'target-arrow-color': '#6dcd00', 'line-style': 'dashed' } },
{ selector: '.ex', style: { 'line-color': '#e52c1a', 'target-arrow-color': '#e52c1a' } }
],
layout: {
name: 'dagre', // 위에서 아래로 흐르는 계층 구조
rankDir: 'TB',
nodeSep: 50,
rankSep: 100
}
});
updateVisibility();
}
function updateVisibility() {
if (!cy) return;
document.querySelectorAll('.filter').forEach(checkbox => {
const type = checkbox.value;
cy.edges(`.${type}`).style('display', checkbox.checked ? 'element' : 'none');
});
}
document.querySelectorAll('.filter').forEach(cb => {
cb.addEventListener('change', updateVisibility);
});
</script>
</body>
</html>