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