1 #include <stdio.h>
2 
3 #define NK_INCLUDE_FIXED_TYPES
4 #define NK_INCLUDE_STANDARD_IO
5 #define NK_INCLUDE_STANDARD_VARARGS
6 #define NK_IMPLEMENTATION
7 #include <nuklear.h>
8 
9 #define STB_IMAGE_IMPLEMENTATION
10 #include <stb_image.h>
11 
12 #include <ui/display.h>
13 #include <ui/font.h>
14 #include <ui/image.h>
15 #include <ui/window.h>
16 
17 #include <vuln/l1tf.h>
18 #include <vuln/meltdown.h>
19 #include <vuln/ridl.h>
20 #include <vuln/spectre.h>
21 #include <vuln/ssb.h>
22 
23 #include "style.h"
24 
25 #include "../system.h"
26 
27 #if defined(_WIN32)
28 #define FONT_NAME "Segoe UI"
29 #else
30 #define FONT_NAME "Vera Sans"
31 #endif
32 
33 void
34 show_system_tab(struct nk_context *ctx, struct style *style, struct sys_info *info, int flags);
35 void
36 show_meltdown_tab(struct nk_context *ctx, struct style *style, struct meltdown_info *info, int flags);
37 void
38 show_l1tf_tab(struct nk_context *ctx, struct style *style, struct l1tf_info *info, int flags);
39 void
40 show_spectre_v1_tab(struct nk_context *ctx, struct style *style, struct spectre_info *info, int flags);
41 void
42 show_spectre_v2_tab(struct nk_context *ctx, struct style *style, struct spectre_info *info, int flags);
43 void
44 show_ssb_tab(struct nk_context *ctx, struct style *style, struct ssb_info *info, int flags);
45 void
46 show_ridl_tab(struct nk_context *ctx, struct style *style, struct ridl_info *info, int flags);
47 
48 void
set_theme(struct nk_context * ctx)49 set_theme(struct nk_context *ctx)
50 {
51 	struct nk_color table[NK_COLOR_COUNT];
52 
53 	table[NK_COLOR_TEXT] = nk_rgba(70, 70, 70, 255);
54 	table[NK_COLOR_WINDOW] = nk_rgba(240, 240, 240, 255);
55 	table[NK_COLOR_HEADER] = nk_rgba(175, 175, 175, 255);
56 	table[NK_COLOR_BORDER] = nk_rgba(0, 0, 0, 255);
57 	table[NK_COLOR_BUTTON] = nk_rgba(185, 185, 185, 255);
58 	table[NK_COLOR_BUTTON_HOVER] = nk_rgba(170, 170, 170, 255);
59 	table[NK_COLOR_BUTTON_ACTIVE] = nk_rgba(160, 160, 160, 255);
60 	table[NK_COLOR_TOGGLE] = nk_rgba(150, 150, 150, 255);
61 	table[NK_COLOR_TOGGLE_HOVER] = nk_rgba(120, 120, 120, 255);
62 	table[NK_COLOR_TOGGLE_CURSOR] = nk_rgba(175, 175, 175, 255);
63 	table[NK_COLOR_SELECT] = nk_rgba(190, 190, 190, 255);
64 	table[NK_COLOR_SELECT_ACTIVE] = nk_rgba(175, 175, 175, 255);
65 	table[NK_COLOR_SLIDER] = nk_rgba(190, 190, 190, 255);
66 	table[NK_COLOR_SLIDER_CURSOR] = nk_rgba(80, 80, 80, 255);
67 	table[NK_COLOR_SLIDER_CURSOR_HOVER] = nk_rgba(70, 70, 70, 255);
68 	table[NK_COLOR_SLIDER_CURSOR_ACTIVE] = nk_rgba(60, 60, 60, 255);
69 	table[NK_COLOR_PROPERTY] = nk_rgba(175, 175, 175, 255);
70 	table[NK_COLOR_EDIT] = nk_rgba(150, 150, 150, 255);
71 	table[NK_COLOR_EDIT_CURSOR] = nk_rgba(0, 0, 0, 255);
72 	table[NK_COLOR_COMBO] = nk_rgba(175, 175, 175, 255);
73 	table[NK_COLOR_CHART] = nk_rgba(160, 160, 160, 255);
74 	table[NK_COLOR_CHART_COLOR] = nk_rgba(45, 45, 45, 255);
75 	table[NK_COLOR_CHART_COLOR_HIGHLIGHT] = nk_rgba( 255, 0, 0, 255);
76 	table[NK_COLOR_SCROLLBAR] = nk_rgba(180, 180, 180, 255);
77 	table[NK_COLOR_SCROLLBAR_CURSOR] = nk_rgba(140, 140, 140, 255);
78 	table[NK_COLOR_SCROLLBAR_CURSOR_HOVER] = nk_rgba(150, 150, 150, 255);
79 	table[NK_COLOR_SCROLLBAR_CURSOR_ACTIVE] = nk_rgba(160, 160, 160, 255);
80 	//table[NK_COLOR_TAB_HEADER] = nk_rgba(180, 180, 180, 255);
81 	table[NK_COLOR_TAB_HEADER] = nk_rgba(48, 105, 152, 255);
82 
83 	nk_style_from_table(ctx, table);
84 
85 	ctx->style.tab.text = nk_rgb(255, 255, 255);
86 }
87 
88 int
main(void)89 main(void)
90 {
91 	struct style style;
92 	struct sys_info sys_info;
93 	struct spectre_info spectre_info;
94 	struct ssb_info ssb_info;
95 	struct meltdown_info meltdown_info;
96 	struct l1tf_info l1tf_info;
97 	struct ridl_info ridl_info;
98 	struct ui_window *window;
99 	struct nk_context *ctx;
100 	unsigned width, height;
101 
102 	if (ui_open_display() < 0) {
103 		fprintf(stderr, "error: unable to open the display\n");
104 		return -1;
105 	}
106 
107 	style.font = ui_create_font(FONT_NAME, 14, 0);
108 	style.bold_font = ui_create_font(FONT_NAME, 14, UI_FONT_BOLD);
109 	style.header_font = ui_create_font(FONT_NAME, 14, UI_FONT_BOLD);
110 
111 	style.red = nk_rgb(160, 44, 44);
112 	style.green = nk_rgb(102, 136, 0);
113 	style.yellow = nk_rgb(255, 102, 0);
114 	style.black = nk_rgb(0, 0, 0);
115 
116 	window = ui_create_window(style.font, "MDS Tool", 0, 0, 640, 480);
117 
118 	if (!window)
119 		return -1;
120 
121 	ui_show_window(window);
122 
123 	ctx = ui_get_context(window);
124 	set_theme(ctx);
125 	ctx->style.button.rounding = 0;
126 
127 	query_sys_info(&sys_info);
128 	query_spectre_info(&spectre_info);
129 	query_ssb_info(&ssb_info);
130 	query_meltdown_info(&meltdown_info);
131 	query_l1tf_info(&l1tf_info);
132 	query_ridl_info(&ridl_info);
133 
134 	while (!ui_should_close(window)) {
135 		nk_input_begin(ctx);
136 		ui_process_events();
137 		nk_input_end(ctx);
138 
139 		ui_get_window_size(window, &width, &height);
140 
141 		if (nk_begin(ctx, "", nk_rect(0, 0, (float)width, (float)height + 11), 0)) {
142 			show_system_tab(ctx, &style, &sys_info, NK_MAXIMIZED);
143 			show_spectre_v1_tab(ctx, &style, &spectre_info, NK_MAXIMIZED);
144 			show_spectre_v2_tab(ctx, &style, &spectre_info, NK_MAXIMIZED);
145 			show_ssb_tab(ctx, &style, &ssb_info, NK_MAXIMIZED);
146 			show_meltdown_tab(ctx, &style, &meltdown_info, NK_MAXIMIZED);
147 			show_l1tf_tab(ctx, &style, &l1tf_info, NK_MAXIMIZED);
148 			show_ridl_tab(ctx, &style, &ridl_info, NK_MAXIMIZED);
149 		}
150 
151 		nk_end(ctx);
152 
153 		ui_render_window(window, nk_rgba(0, 0, 0, 0));
154 	}
155 
156 	ui_close_display();
157 
158 	return 0;
159 }
160