61caacda |
1 | local skel_1 = [[ |
2 | <html> |
3 | <head> |
62a95012 |
4 | |
5 | <script> |
6 | var dictionary = {} |
7 | function add(commaSeparated) |
8 | { |
9 | var fields = commaSeparated.split(","); |
10 | var manufacturerCode = fields[0]; |
11 | var modelCode = fields[1]; |
12 | var modelSubCode= fields[2]; |
13 | var modelName = fields[3]; |
14 | var ATQA = fields[4]; |
15 | var SAK = fields[5]; |
16 | |
17 | //In the data below, wrong endian is used. Mifare is |
18 | // written as "0004" instead of "0400", so we need to |
19 | // flip it |
20 | ATQA = ATQA.substr(2,4)+ATQA.substr(0,2) |
21 | |
22 | var info = { |
23 | modelCode : modelCode, |
24 | modelSubCode : modelSubCode, |
25 | modelName : modelName, |
26 | ATQA : ATQA, |
27 | SAK : SAK |
28 | } |
29 | console.log("Adding "+modelName+" , "+SAK) |
30 | |
31 | dictionary[ATQA] = dictionary[ATQA] || []; |
32 | dictionary[ATQA].push(info) |
33 | } |
34 | function lookup(atqa, sak) |
35 | { |
36 | if (!dictionary[atqa]) return "UNKNOWN"; |
37 | |
38 | var possibleMatches = []; |
39 | for(var i = 0 ; i < dictionary[atqa].length ; i++) |
40 | { |
41 | |
42 | var info = dictionary[atqa][i]; |
43 | console.log("Comparing "+sak+ " with "+ info.SAK); |
44 | if(sak && info.SAK == sak)//exact match |
45 | { |
46 | return info.modelName; |
47 | // possibleMatches.push(info.modelName); |
48 | }else //SAK unknown |
49 | { |
50 | possibleMatches.push(info.modelName); |
51 | } |
52 | } |
53 | if(possibleMatches.length > 0) |
54 | return possibleMatches.join(" or "); |
55 | return "UNKNOWN" |
56 | } |
57 | |
3af373f3 |
58 | add("04,,,Mifare TNP3xxx Activision 1K,0f01,01"); |
62a95012 |
59 | add("04,,,Mifare Mini,0004,09"); |
60 | add("04,,,Mifare Classic 1k/Mifare Plus(4 byte UID) 2K SL1,0004,08"); |
61 | add("04,,,Mifare Plus (4 byte UID) 2K SL2,0004,10"); |
62 | add("04,,,Mifare Plus (4 byte UID) 4K SL2,0004,11"); |
63 | add("04,,,Mifare Plus (4 byte UID) 4K SL1,0004,18"); |
64 | add("04,,,Mifare Plus (4 byte UID) 2K/4K SL3,0004,20"); |
65 | add("04,,,Mifare Classic 4K,0002,18"); |
66 | add("xx,,,NDEF Tags,0044,00 "); |
67 | add("04,,,Mifare Ultralight/UltralightC,0044,04"); |
68 | add("04,,,Mifare Plus (7 byte UID) 2K SL1,0042,08"); |
69 | add("04,,,Mifare Plus (7 byte UID) 2K SL1,0044,08"); |
70 | add("04,,,Mifare Plus (7 byte UID) 4K SL1,0042,18"); |
71 | add("04,,,Mifare Plus (7 byte UID) 4K SL1,0044,18"); |
72 | add("04,,,Mifare Plus (7 byte UID),0042,10"); |
73 | add("04,,,Mifare Plus (7 byte UID),0044,10"); |
74 | add("04,,,Mifare Plus (7 byte UID),0042,11"); |
75 | add("04,,,Mifare Plus (7 byte UID),0044,11"); |
76 | add("04,,,Mifare Plus (7 byte UID),0042,20"); |
77 | add("04,,,Mifare Plus (7 byte UID),0044,20"); |
78 | add("04,,,Mifare DesFire / DesFire EV1,0344,20067577810280"); |
79 | add("04,,,JCOP31,0304,283877B14A434F503331"); |
80 | add("04,,,JCOP31 v2.4.1,0048,207877B1024A434F5076323431"); |
81 | add("04,,,JCOP41 v2.2,0048,203833B14A434F503431563232"); |
82 | add("04,,,JCOP41 v2.3.1,0004,283833B14A434F50343156323331"); |
83 | add("05,,,Mifare Classic 1K,0004,88"); |
84 | add("40,,,MPCOS,0002,98"); |
85 | add("25,,,Topaz/Topaz512/Jewel,0C00,"); |
86 | add("1D,,,FM1208SH01,0004,53"); |
87 | add("1D,,,FM1208,0008,20"); |
88 | add("Nokia,,,Mifare Classic 4K emulated by Nokia 6212,0002,38"); |
89 | add("Nokia,,,Mifare Classic 4K emulated by Nokia 6131,0008,38"); |
90 | add("04,,,Smart MX with Mifare 4K emulation,0002"); |
91 | add("04,,,Smart MX with Mifare 4K emulation,0102"); |
92 | add("04,,,Smart MX with Mifare 4K emulation,0202"); |
93 | add("04,,,Smart MX with Mifare 4K emulation,0302"); |
94 | add("04,,,Smart MX with Mifare 4K emulation,0402"); |
95 | add("04,,,Smart MX with Mifare 4K emulation,0502"); |
96 | add("04,,,Smart MX with Mifare 4K emulation,0602"); |
97 | add("04,,,Smart MX with Mifare 4K emulation,0702"); |
98 | add("04,,,Smart MX with Mifare 4K emulation,0802"); |
99 | add("04,,,Smart MX with Mifare 4K emulation,0902"); |
100 | add("04,,,Smart MX with Mifare 4K emulation,0A02"); |
101 | add("04,,,Smart MX with Mifare 4K emulation,0B02"); |
102 | add("04,,,Smart MX with Mifare 4K emulation,0C02"); |
103 | add("04,,,Smart MX with Mifare 4K emulation,0D02"); |
104 | add("04,,,Smart MX with Mifare 4K emulation,0E02"); |
105 | add("04,,,Smart MX with Mifare 4K emulation,0F02"); |
106 | add("04,,,Smart MX with Mifare 1K emulation,0004"); |
107 | add("04,,,Smart MX with Mifare 1K emulation,0104"); |
108 | add("04,,,Smart MX with Mifare 1K emulation,0204"); |
109 | add("04,,,Smart MX with Mifare 1K emulation,0304"); |
110 | add("04,,,Smart MX with Mifare 1K emulation,0404"); |
111 | add("04,,,Smart MX with Mifare 1K emulation,0504"); |
112 | add("04,,,Smart MX with Mifare 1K emulation,0604"); |
113 | add("04,,,Smart MX with Mifare 1K emulation,0704"); |
114 | add("04,,,Smart MX with Mifare 1K emulation,0804"); |
115 | add("04,,,Smart MX with Mifare 1K emulation,0904"); |
116 | add("04,,,Smart MX with Mifare 1K emulation,0A04"); |
117 | add("04,,,Smart MX with Mifare 1K emulation,0B04"); |
118 | add("04,,,Smart MX with Mifare 1K emulation,0C04"); |
119 | add("04,,,Smart MX with Mifare 1K emulation,0D04"); |
120 | add("04,,,Smart MX with Mifare 1K emulation,0E04"); |
121 | add("04,,,Smart MX with Mifare 1K emulation,0F04"); |
122 | add("04,,,Smart MX with 7 byte UID,0048"); |
123 | add("04,,,Smart MX with 7 byte UID,0148"); |
124 | add("04,,,Smart MX with 7 byte UID,0248"); |
125 | add("04,,,Smart MX with 7 byte UID,0348"); |
126 | add("04,,,Smart MX with 7 byte UID,0448"); |
127 | add("04,,,Smart MX with 7 byte UID,0548"); |
128 | add("04,,,Smart MX with 7 byte UID,0648"); |
129 | add("04,,,Smart MX with 7 byte UID,0748"); |
130 | add("04,,,Smart MX with 7 byte UID,0848"); |
131 | add("04,,,Smart MX with 7 byte UID,0948"); |
132 | add("04,,,Smart MX with 7 byte UID,0A48"); |
133 | add("04,,,Smart MX with 7 byte UID,0B48"); |
134 | add("04,,,Smart MX with 7 byte UID,0C48"); |
135 | add("04,,,Smart MX with 7 byte UID,0D48"); |
136 | add("04,,,Smart MX with 7 byte UID,0E48"); |
137 | add("04,,,Smart MX with 7 byte UID,0F48"); |
138 | </script> |
139 | |
61caacda |
140 | <style> |
141 | * { |
142 | background-color: #2F3440; |
143 | background-color:#232323; |
144 | color : #F5E5C0; |
62a95012 |
145 | xtext-transform: uppercase; |
61caacda |
146 | font-size: 1.05em; |
147 | font-family: monospace,Arial; |
148 | } |
149 | table{ |
150 | float:left; |
151 | border: 1px solid white; |
152 | } |
62a95012 |
153 | td { |
154 | empty-cells: show; |
57d38400 |
155 | } |
62a95012 |
156 | td.blockzero, .turqoise{ |
61caacda |
157 | color: rgb(140, 245, 193); |
158 | } |
62a95012 |
159 | td.key_a, .yellow{ |
61caacda |
160 | color : #F8CA4D; |
161 | } |
62a95012 |
162 | td.key_b, .blue{ |
61caacda |
163 | color : #3F5666; |
164 | } |
62a95012 |
165 | td.accessconditions, .red{ |
61caacda |
166 | color : #EA6045; |
167 | } |
168 | |
169 | td.sectorhdr{ |
170 | border-top: 1px solid white; |
171 | } |
172 | </style> |
173 | <script> |
62a95012 |
174 | /** Jquery for the poor **/ |
61caacda |
175 | function dc(x){return document.createElement(x)} |
176 | |
62a95012 |
177 | function tr(table){ |
178 | var row = dc('tr'); |
179 | table.appendChild(row); |
180 | return row; |
181 | } |
182 | function td(row, text){ |
183 | var tdata = dc('td'); |
184 | row.appendChild(tdata); |
185 | tdata.appendChild(document.createTextNode(text)) |
186 | return tdata; |
187 | } |
188 | |
189 | /** |
190 | * The identifiers that determine how to highlight data and present information |
191 | **/ |
192 | var identifiers = [ |
193 | function(data) |
61caacda |
194 | { |
62a95012 |
195 | // Should be 32 characters long ( 16 bytes per block) |
196 | if(data[0].length != 32) { return false; } |
197 | // ... add more checks if necessary ... |
61caacda |
198 | |
62a95012 |
199 | var info = {Type : "Mifare"} |
200 | info['Size'] = (data[0].length / 2 * data.length) + " Bytes"; |
201 | info['UID'] = data[0].substring(0,8); |
202 | info['SAK'] = data[0].substring(10,12); |
203 | info['ATQA'] = data[0].substring(12,16); |
61caacda |
204 | |
62a95012 |
205 | info['Name'] = lookup(info.ATQA, info.SAK); |
206 | return {info: info, highlighter : mifareHighlighter } |
207 | }, |
208 | function(data) |
61caacda |
209 | { |
62a95012 |
210 | // Should be 8 characters long ( 4 bytes per block) |
211 | if(data[0].length != 8) { return false; } |
212 | // ... add more checks if necessary ... |
213 | var info = {Type : "NDEF"} |
214 | info['Size'] = (data[0].length / 2 * data.length) + " Bytes"; |
61caacda |
215 | |
62a95012 |
216 | return {info: info, highlighter : ndefHighligheter } |
217 | }, |
218 | function(data) |
219 | {//This is the catch-all |
220 | return {info: {type : "Unknown"}, highlighter : noHighlighter} |
61caacda |
221 | } |
62a95012 |
222 | ] |
223 | |
61caacda |
224 | |
62a95012 |
225 | /** |
226 | * Helper function to convert bin-data into printable chars |
227 | **/ |
61caacda |
228 | |
61caacda |
229 | function to_ascii(hexval) |
230 | { |
231 | var intval = parseInt(hexval,16); |
232 | if(intval > 31 && intval < 127) |
233 | { |
234 | return String.fromCharCode(intval); |
235 | } |
236 | return "."; |
237 | } |
238 | |
62a95012 |
239 | |
240 | function loadIntoTable(data, info, ascii) |
61caacda |
241 | { |
61caacda |
242 | var t = dc("table") |
243 | for(var i = 0 ; i < data.length ; i++) |
244 | { |
245 | line = data[i]; |
62a95012 |
246 | var row = tr(t); |
61caacda |
247 | var bytes = line.match(/(.{1,2})/g); |
248 | for(var b = 0 ; b < bytes.length ; b++) |
249 | { |
62a95012 |
250 | var elem = td(row, ascii ? to_ascii(bytes[b]) : bytes[b]); |
251 | info.highlighter.addClass(elem,i,b, bytes[b]); |
61caacda |
252 | } |
253 | } |
254 | document.body.appendChild(t); |
255 | } |
62a95012 |
256 | function loadGeneralInfo(data, info) |
257 | { |
258 | var t = dc("table"); |
259 | for (var key in info) |
260 | { |
261 | var row = tr(t); |
262 | td(row,key); |
263 | td(row,info[key]); |
264 | } |
265 | document.body.appendChild(t); |
266 | } |
61caacda |
267 | |
62a95012 |
268 | function handle(dump) |
61caacda |
269 | { |
62a95012 |
270 | var data = dump.data; |
271 | var info = null; |
272 | for(var i = 0; i < identifiers.length && !info; i++) |
273 | info = identifiers[i](data); |
274 | |
275 | console.log(info); |
276 | |
277 | loadIntoTable(data, info, false); |
278 | loadIntoTable(data, info, true); |
279 | loadGeneralInfo(data, info.info); |
280 | |
61caacda |
281 | } |
62a95012 |
282 | var noHighlighter = { |
283 | addClass : function(el ,line, byte) |
284 | { |
285 | return; |
286 | } |
287 | }; |
288 | var ndefHighligheter = { |
289 | addClass : function(el ,line, byte, value) |
290 | { |
291 | if(line < 3) |
292 | { |
293 | el.className += " red"; |
294 | } |
295 | if ( line == 3) |
296 | { |
297 | console.log(value); |
298 | if( byte == 0 && "e1" == value.toLowerCase()) el.className += " turqoise"; |
299 | if( byte == 1 ) el.className += " yellow"; |
300 | if( byte == 2 ) el.className += " blue"; |
301 | return; |
302 | } |
303 | } |
304 | }; |
305 | var mifareHighlighter = { |
306 | addClass : function(el ,line, byte) |
307 | { |
308 | if (line == 0) |
309 | { |
310 | el.className += " blockzero"; |
311 | } |
312 | |
313 | if(line < 128){ |
314 | linesPerSector = 4; |
315 | }else |
316 | { |
317 | //Quadruple size sectors |
318 | linesPerSector = 16; |
319 | line = line - 128; |
320 | |
321 | } |
322 | |
323 | if(line % linesPerSector == 0) |
324 | { |
325 | el.className += " sectorhdr"; |
326 | } |
327 | if(line % linesPerSector == (linesPerSector -1)) |
328 | { |
329 | el.className += " sectortrailer"; |
330 | if(byte == undefined) |
331 | { |
332 | return; |
333 | } |
334 | |
335 | if(byte < 6) el.className += " key_a"; |
336 | else if(byte < 10) el.className += " accessconditions"; |
337 | else el.className += " key_b"; |
338 | } |
339 | |
340 | } |
341 | }; |
342 | |
343 | |
344 | |
61caacda |
345 | </script> |
346 | |
347 | </head> |
b11542a7 |
348 | <body></body> |
61caacda |
349 | <script> |
62a95012 |
350 | var x = { data : |
61caacda |
351 | ]] |
352 | local skel_2 = [[ |
353 | |
62a95012 |
354 | }; |
355 | handle(x); |
61caacda |
356 | </script> |
357 | </html> |
62a95012 |
358 | |
61caacda |
359 | ]] |
360 | local function getHTML(data) |
361 | return skel_1 .. data .. skel_2 |
362 | end |
363 | |
364 | return {getHTML = getHTML} |