-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.html
273 lines (244 loc) · 10.3 KB
/
index.html
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Under The Hood Of Executables</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.2.0/github-markdown.min.css">
<style>
:root {
--bg-color: #ffffff;
--text-color: #24292e;
--link-color: #0366d6;
--nav-bg: #f6f8fa;
--border-color: #e1e4e8;
--code-bg: #f6f8fa;
--code-text: #24292e;
}
[data-theme="dark"] {
--bg-color: #0d1117;
--text-color: #c9d1d9;
--link-color: #58a6ff;
--nav-bg: #161b22;
--border-color: #30363d;
--code-bg: #1f2428;
--code-text: #e1e4e8;
}
body {
margin: 0;
padding: 0;
background-color: var(--bg-color);
color: var(--text-color);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
line-height: 1.6;
}
.header {
position: fixed;
top: 0;
left: 0;
right: 0;
height: 60px;
background-color: var(--nav-bg);
border-bottom: 1px solid var(--border-color);
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 20px;
z-index: 1000;
}
.nav-title {
font-size: 1.2em;
font-weight: bold;
color: var(--text-color);
}
.controls {
display: flex;
gap: 20px;
align-items: center;
}
.theme-toggle {
background: none;
border: none;
cursor: pointer;
padding: 8px;
color: var(--text-color);
display: flex;
align-items: center;
justify-content: center;
width: 40px;
height: 40px;
border-radius: 50%;
transition: background-color 0.3s;
}
.theme-toggle:hover {
background-color: var(--border-color);
}
.nav-button {
padding: 8px 16px;
background-color: var(--link-color);
color: #ffffff;
border: none;
border-radius: 6px;
cursor: pointer;
text-decoration: none;
font-size: 14px;
}
.nav-button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.container {
max-width: 800px;
margin: 80px auto 40px;
padding: 20px;
}
.markdown-body {
background-color: var(--bg-color) !important;
color: var(--text-color) !important;
}
.markdown-body pre {
background-color: var(--code-bg) !important;
border: 1px solid var(--border-color);
}
.markdown-body code {
color: var(--code-text) !important;
background-color: var(--code-bg) !important;
}
.markdown-body a {
color: var(--link-color);
}
#nextTitle, #prevTitle {
font-size: 12px;
margin-top: 4px;
opacity: 0.8;
}
.nav-group {
display: flex;
flex-direction: column;
align-items: center;
}
@media (max-width: 767px) {
.container {
padding: 15px;
}
.nav-title {
display: none;
}
}
</style>
</head>
<body>
<header class="header">
<div class="nav-group">
<button id="prevButton" class="nav-button" onclick="navigatePage('prev')" disabled>Previous</button>
<div id="prevTitle"></div>
</div>
<span class="nav-title">Under The Hood Of Executables</span>
<div class="controls">
<button class="theme-toggle" id="themeToggle" aria-label="Toggle theme">
<svg id="themeIcon" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<!-- Will be updated by JavaScript -->
</svg>
</button>
<div class="nav-group">
<button id="nextButton" class="nav-button" onclick="navigatePage('next')">Next</button>
<div id="nextTitle"></div>
</div>
</div>
</header>
<main class="container">
<div id="content" class="markdown-body"></div>
</main>
<script src="https://cdnjs.cloudflare.com/ajax/libs/markdown-it/13.0.1/markdown-it.min.js"></script>
<script>
const pages = [
{ path: 'INDEX.md', title: 'Index Of Book' },
{ path: 'src/Ch-1-The-Mystery-Of-Executable-Size/Why-is-my-Hello-World-so-Big.md', title: 'Chapter 1: Why is my "Hello World" so Big?' },
{ path: 'src/Ch-2-The-Executable-And-Linkable-Format/Demystifying-the-Executable-Format.md', title: 'Chapter 2: Demystifying the Executable Format' },
{ path: 'src/Ch-3-Sections-Organizing-Code-And-Data/Understanding-ELF-Sections.md', title: 'Chapter 3: Understanding ELF Sections' },
{ path: 'src/Ch-4-Global-Variables-And-Initialization/The-Secret-Life-of-Global-Variables-in-C.md', title: 'Chapter 4: The Secret Life of Global Variables in C' },
{ path: 'src/Ch-5-The-Linker\'s-Role/Bringing-The-C-Code-Together.md', title: 'Chapter 5: Bringing The C Code Together' },
{ path: 'src/Ch-6-Relocations-Patching-The-Code/The Linker\'s Patchwork.md', title: 'Chapter 6: The Linker\'s Patchwork' },
{ path: 'src/Ch-7-Symbols/Symbols.md', title: 'Chapter 7: Symbols' },
{ path: 'src/Ch-8-Customizing-The-Layout/Introduction-To-Linker-Scripts.md', title: 'Chapter 8: Introduction To Linker Scripts' },
{ path: 'src/Ch-9-Dynamic-Linking/Shrinking Executables and Sharing Code.md', title: 'Chapter 9: Shrinking Executables and Sharing Code' },
{ path: 'src/Ch-10-Dynamic-Linking-Process/Lazy Loading: Dynamic Linking on Demand.md', title: 'Chapter 10: Lazy Loading - Dynamic Linking on Demand' },
{ path: 'src/Ch-11-Controlling-Dynamic-Linking-Behavior/Taking-Control-Environment-Variables-For-Dynamic-Linking.md', title: 'Chapter 11: Taking Control - Environment Variables For Dynamic Linking' },
{ path: 'src/Ch-12-Linux-Executable-Loading/Linux-Executable-Loading.md', title: 'Chapter 12: Linux Executable Loading' },
{ path: 'src/Ch-13-Weak-Symbols/Weak Symbols: A Linker\'s Flexibility.md', title: 'Chapter 13: Weak Symbols - A Linker\'s Flexibility' },
{ path: 'src/Ch-14-Final-Chapter/Level-Up-Your-C.md', title: 'Chapter 14: Level Up Your C' }
];
let currentPageIndex = 0;
const md = window.markdownit();
const themeToggle = document.getElementById('themeToggle');
const themeIcon = document.getElementById('themeIcon');
const prevButton = document.getElementById('prevButton');
const nextButton = document.getElementById('nextButton');
const content = document.getElementById('content');
const prevTitle = document.getElementById('prevTitle');
const nextTitle = document.getElementById('nextTitle');
// Theme icons
const sunIcon = `
<path d="M12 1v2M12 21v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M1 12h2M21 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42M12 17.5a5.5 5.5 0 1 1 0-11 5.5 5.5 0 0 1 0 11z"/>
`;
const moonIcon = `
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
`;
// Theme handling
function setTheme(theme) {
document.documentElement.setAttribute('data-theme', theme);
localStorage.setItem('theme', theme);
themeIcon.innerHTML = theme === 'dark' ? sunIcon : moonIcon;
}
themeToggle.addEventListener('click', () => {
const currentTheme = document.documentElement.getAttribute('data-theme');
setTheme(currentTheme === 'dark' ? 'light' : 'dark');
});
// Initialize theme
const savedTheme = localStorage.getItem('theme') || 'light';
setTheme(savedTheme);
// Navigation
function updateNavigation() {
prevButton.disabled = currentPageIndex === 0;
nextButton.disabled = currentPageIndex === pages.length - 1;
prevTitle.textContent = currentPageIndex > 0 ? pages[currentPageIndex - 1].title : '';
nextTitle.textContent = currentPageIndex < pages.length - 1 ? pages[currentPageIndex + 1].title : '';
}
async function loadPage(index) {
try {
const response = await fetch(pages[index].path);
const text = await response.text();
content.innerHTML = md.render(text);
document.title = pages[index].title + ' - Under The Hood Of Executables';
currentPageIndex = index;
updateNavigation();
window.scrollTo(0, 0);
} catch (error) {
console.error('Error loading page:', error);
content.innerHTML = '<h1>Error loading page</h1><p>Please try again later.</p>';
}
}
function navigatePage(direction) {
const newIndex = direction === 'next' ? currentPageIndex + 1 : currentPageIndex - 1;
if (newIndex >= 0 && newIndex < pages.length) {
loadPage(newIndex);
}
}
// URL handling
function getPageIndexFromURL() {
const params = new URLSearchParams(window.location.search);
const page = params.get('page');
if (page) {
const index = pages.findIndex(p => p.path === page);
return index >= 0 ? index : 0;
}
return 0;
}
// Initialize page
window.addEventListener('DOMContentLoaded', () => {
const initialIndex = getPageIndexFromURL();
loadPage(initialIndex);
});
</script>
</body>
</html>