Merge pull request #2656 from hochwasser/patch-1
[RRG-proxmark3.git] / client / lualibs / htmlskel.lua
blobee5f6583e2f692761b3a5ae35ce1a9ea3ce4b074
1 local skel_1 = [[
2 <html>
3 <head>
5 <script>
6 var dictionary = {}
7 function add(commaSeparated)
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];
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)
22 var info = {
23 modelCode : modelCode,
24 modelSubCode : modelSubCode,
25 modelName : modelName,
26 ATQA : ATQA,
27 SAK : SAK
29 console.log("Adding "+modelName+" , "+SAK)
31 dictionary[ATQA] = dictionary[ATQA] || [];
32 dictionary[ATQA].push(info)
34 function lookup(atqa, sak)
36 if (!dictionary[atqa]) return "UNKNOWN";
38 var possibleMatches = [];
39 for(var i = 0 ; i < dictionary[atqa].length ; i++)
42 var info = dictionary[atqa][i];
43 console.log("Comparing "+sak+ " with "+ info.SAK);
44 if(sak && info.SAK == sak)//exact match
46 return info.modelName;
47 // possibleMatches.push(info.modelName);
48 }else //SAK unknown
50 possibleMatches.push(info.modelName);
53 if(possibleMatches.length > 0)
54 return possibleMatches.join(" or ");
55 return "UNKNOWN"
58 add("04,,,Mifare TNP3xxx Activision 1K,0f01,01");
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>
140 <style>
142 background-color: #2F3440;
143 background-color:#232323;
144 color : #F5E5C0;
145 xtext-transform: uppercase;
146 font-size: 1.05em;
147 font-family: monospace,Arial;
149 table{
150 float:left;
151 border: 1px solid white;
153 td {
154 empty-cells: show;
156 td.blockzero, .turqoise{
157 color: rgb(140, 245, 193);
159 td.key_a, .yellow{
160 color : #F8CA4D;
162 td.key_b, .blue{
163 color : #3F5666;
165 td.accessconditions, .red{
166 color : #EA6045;
169 td.sectorhdr{
170 border-top: 1px solid white;
172 </style>
173 <script>
174 /** Jquery for the poor **/
175 function dc(x){return document.createElement(x)}
177 function tr(table){
178 var row = dc('tr');
179 table.appendChild(row);
180 return row;
182 function td(row, text){
183 var tdata = dc('td');
184 row.appendChild(tdata);
185 tdata.appendChild(document.createTextNode(text))
186 return tdata;
190 * The identifiers that determine how to highlight data and present information
192 var identifiers = [
193 function(data)
195 // Should be 32 characters long ( 16 bytes per block)
196 if(data[0].length != 32) { return false; }
197 // ... add more checks if necessary ...
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);
205 info['Name'] = lookup(info.ATQA, info.SAK);
206 return {info: info, highlighter : mifareHighlighter }
208 function(data)
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";
216 return {info: info, highlighter : ndefHighligheter }
219 function(data)
220 {//This is the catch-all
221 return {info: {type : "Unknown"}, highlighter : noHighlighter}
227 * Helper function to convert bin-data into printable chars
230 function to_ascii(hexval)
232 var intval = parseInt(hexval,16);
233 if(intval > 31 && intval < 127)
235 return String.fromCharCode(intval);
237 return ".";
241 function loadIntoTable(data, info, ascii)
243 var t = dc("table")
244 for(var i = 0 ; i < data.length ; i++)
246 line = data[i];
247 var row = tr(t);
248 var bytes = line.match(/(.{1,2})/g);
249 for(var b = 0 ; b < bytes.length ; b++)
251 var elem = td(row, ascii ? to_ascii(bytes[b]) : bytes[b]);
252 info.highlighter.addClass(elem,i,b, bytes[b]);
255 document.body.appendChild(t);
257 function loadGeneralInfo(data, info)
259 var t = dc("table");
260 for (var key in info)
262 var row = tr(t);
263 td(row,key);
264 td(row,info[key]);
266 document.body.appendChild(t);
269 function handle(dump)
271 var data = dump.data;
272 var info = null;
273 for(var i = 0; i < identifiers.length && !info; i++)
274 info = identifiers[i](data);
276 console.log(info);
278 loadIntoTable(data, info, false);
279 loadIntoTable(data, info, true);
280 loadGeneralInfo(data, info.info);
283 var noHighlighter = {
284 addClass : function(el ,line, byte)
286 return;
289 var ndefHighligheter = {
290 addClass : function(el ,line, byte, value)
292 if(line < 3)
294 el.className += " red";
296 if ( line == 3)
298 console.log(value);
299 if( byte == 0 && "e1" == value.toLowerCase()) el.className += " turqoise";
300 if( byte == 1 ) el.className += " yellow";
301 if( byte == 2 ) el.className += " blue";
302 return;
306 var mifareHighlighter = {
307 addClass : function(el ,line, byte)
309 if (line == 0)
311 el.className += " blockzero";
314 if(line < 128){
315 linesPerSector = 4;
316 } else {
317 //Quadruple size sectors
318 linesPerSector = 16;
319 line = line - 128;
322 if(line % linesPerSector == 0)
324 el.className += " sectorhdr";
326 if(line % linesPerSector == (linesPerSector -1))
328 el.className += " sectortrailer";
329 if(byte == undefined)
331 return;
334 if(byte < 6) el.className += " key_a";
335 else if(byte < 10) el.className += " accessconditions";
336 else el.className += " key_b";
342 </script>
344 </head>
345 <body></body>
346 <script>
347 var x = { data :
349 local skel_2 = [[
352 handle(x);
353 </script>
354 </html>
357 local function getHTML(data)
358 return skel_1 .. data .. skel_2
361 return {getHTML = getHTML}