-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
212 lines (151 loc) · 5.65 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
<!DOCTYPE html>
<html>
<head>
<title>Pixel Explorer</title>
<style>
body {
background-color: #eeeeee;
dcolor: white;
}
#myCanvas {
border:1px solid grey;
}
.config-tbl {
width: 1024px;
}
input[type="range"] {
width: 512px;
}
</style>
</head>
<body>
<h1>Pixel Explorer</h1>
<input type="file" id="files" name="file" onchange="readfile()">
<br><br>
<canvas id="myCanvas" width="1024px" height="512px"></canvas>
<br>
<table class="config-tbl">
<tr>
<td>Offset:</td><td><input id="vo" value="0" oninput="offset.value=this.value; update()"></td>
<td><input type="range" min="0" max="655200" value="0" class="slider" id="offset" oninput="update()" class="slider_full"></td>
</tr>
<tr>
<td>Shift:</td><td><input id="vs" value="0" oninput="shift.value=this.value;update()"></td>
<td><input type="range" min="0" max="64" value="0" class="slider" id="shift" oninput="update()" class="slider_half"></td>
</tr>
<tr>
<td>Block:</td><td><input id="vb" value="8" oninput="block.value=this.value;update()"></td>
<td><input type="range" min="0" max="64" value="0" class="slider" id="block" oninput="update()" class="slider_half"></td>
</tr>
<tr>
<td>Reverse bit order:</td>
<td>
<input type="checkbox" id="reverse" onchange="update()">
</td>
</tr>
<tr>
<td>Invert colors:</td>
<td>
<input type="checkbox" id="invert" onchange="do_invert(this.checked)">
</td>
</tr>
<tr>
<td>Highlight printable bytes:</td>
<td>
<input type="checkbox" id="highlight" checked onchange="update();">
</td>
</tr>
</table>
<hr>
Simple program to explore binary files as a bunch of pixels. Perfect to find sprites, fonts, and more in classic ROMs and firmwares.
<script type="text/javascript">
const W = 512
const H = 256
const S = 2;
const PW = 4;
const BG_COLOR = "#111111";
const FG_COLOR = "#EEEEEE";
const ALPHA_COLOR = "#00FF00";
const NUM_COLOR = "#00FFFF";
let g_data = ""
let c = document.getElementById("myCanvas");
let ctx = c.getContext("2d");
ctx.scale(S, S);
ctx.fillStyle = BG_COLOR;
ctx.fillRect(0, 0, W, H);
shift.value = 0;
offset.value = 0;
block.value = 8;
invert.checked = false;
highlight.checked = true;
const printable_reg = /[a-zA-Z0-9]/;
const printable_alpha = /[a-zA-Z]/;
const printable_num = /[0-9]/;
function do_invert(inv) {
document.body.style.filter = inv ? "invert(1)" : "invert(0)";
document.body.style.backgroundColor = inv ? BG_COLOR : FG_COLOR;
}
function update() {
const shift_ = parseInt(shift.value) || 0;
const offset_ = parseInt(offset.value) || 0;
const blocksize_ = parseInt(block.value) || 1;
const reverse_ = !!reverse.checked;
const highlight_ = !!highlight.checked;
if (blocksize_ < 0)
blocksize_ = 1;
vs.value = shift_;
vo.value = offset_;
vb.value = blocksize_;
drawFrame(offset_, shift_, blocksize_, reverse_, highlight_);
}
function drawFrame(offset, shift, blocksize, reverse, highlight) {
ctx.fillStyle = BG_COLOR;
ctx.fillRect(0, 0, W, H);
let cols = W / blocksize;
let current_char = offset;
let current_bit = offset * 8 + shift;
let c = 0;
for (let c = 0; c < cols; c++) {
for (let y = 0; y < H; y++) {
for (let b = 0; b < blocksize; b++) {
let char_idx = Math.floor(current_bit / 8)
let byte = g_data.charCodeAt(char_idx);
ctx.fillStyle = FG_COLOR;
if (highlight) {
if (printable_alpha.test(g_data[char_idx]))
ctx.fillStyle = ALPHA_COLOR;
else if (printable_num.test(g_data[char_idx]))
ctx.fillStyle = NUM_COLOR;
}
let bit_pos = (current_bit & 7);
let p = ((byte >> (reverse ? 7 - bit_pos : bit_pos)) & 1) === 1;
let x = c * blocksize + b;
if (p)
ctx.fillRect(x, y, 1, 1);
current_bit++;
}
}
}
}
function readfile() {
var files = document.getElementById('files').files;
if (!files.length) {
alert('No file loaded');
return;
}
var file = files[0];
var reader = new FileReader();
reader.onloadend = function (evt) {
if (evt.target.readyState == FileReader.DONE) { // DONE == 2
g_data = evt.target.result;
// set range max value
offset.setAttribute("max", g_data.length);
// draw
update();
}
};
reader.readAsBinaryString(file);
}
</script>
</body>
</html>