Codebase list mfterm / b06dedd
Merge tag 'upstream/1.0.4' Upstream version 1.0.4 Sophie Brun 8 years ago
4 changed file(s) with 47 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
104104 return;
105105 }
106106
107 void print_tag_head() {
108 print_tag_block_range(0, 3);
109 return;
110 }
111
107112 void print_tag_byte_bits(size_t byte, size_t first_bit, size_t last_bit) {
108113
109114 // The byte to show parts of
497502
498503 return -1; // End marker for 4k state
499504 }
500
5858
5959 // Output tag data
6060 void print_tag();
61 void print_tag_head();
6162 void print_tag_block_range(size_t first, size_t last);
6263 void print_tag_data_range(size_t byte_offset, size_t bit_offset,
6364 size_t byte_len, size_t bit_len);
4949 { "write unlocked", com_write_tag_unlocked, 0, 1, "On pirate cards, write 1k tag with block 0" },
5050
5151 { "print", com_print, 0, 1, "1k|4k : Print tag data" },
52 { "print head", com_print_head, 0, 1, "Print first sector" },
5253 { "print keys", com_print_keys, 0, 1, "1k|4k : Print tag's keys" },
5354 { "print ac", com_print_ac, 0, 1, "Print access conditions" },
5455
5556 { "set", com_set, 0, 1, "#block #offset = xx xx xx : Set tag data" },
57 { "setuid", com_setuid, 0, 1, "xx xx xx xx: Set tag UID" },
5658
5759 { "keys load", com_keys_load, 1, 1, "Load keys from a file" },
5860 { "keys save", com_keys_save, 1, 1, "Save keys to a file" },
278280 return 0;
279281 }
280282
283 int com_print_head(char* arg) {
284 print_tag_head();
285 return 0;
286 }
287
281288 int com_set(char* arg) {
282289 char* block_str = strtok(arg, " ");
283290 char* offset_str = strtok(NULL, " ");
329336 current_tag.amb[block].mbd.abtData[offset++] = (uint8_t)byte;
330337
331338 } while((byte_str = strtok(NULL, " ")) != (char*)NULL);
339
340 return 0;
341 }
342
343 int com_setuid(char* arg) {
344 char* byte_str = strtok(arg, " ");
345 int block = 0;
346
347 /// TODO : Check arg size (display warning if < 4)
348 if (!byte_str) {
349 printf("Too few arguments: xx xx xx xx\n");
350 return -1;
351 }
352
353 // Consume the byte tokens
354 do {
355 long int byte = strtol(byte_str, &byte_str, 16);
356
357 if (byte < 0 || byte > 0xff) {
358 printf("Invalid byte value [0,ff]: %lx\n", byte);
359 return -1;
360 }
361
362 // Write the data
363 current_tag.amb[0].mbd.abtData[block++] = (uint8_t)byte;
364
365 } while(((byte_str = strtok(NULL, " ")) != (char*)NULL) && (block < 4));
366 // Compute and write BCC
367 current_tag.amb[0].mbd.abtData[4] = (uint8_t)current_tag.amb[0].mbd.abtData[0] ^
368 (uint8_t)current_tag.amb[0].mbd.abtData[1] ^
369 (uint8_t)current_tag.amb[0].mbd.abtData[2] ^
370 (uint8_t)current_tag.amb[0].mbd.abtData[3];
332371
333372 return 0;
334373 }
4242
4343 // Tag print commands
4444 int com_print(char* arg);
45 int com_print_head(char* arg);
4546 int com_print_keys(char* arg);
4647 int com_print_ac(char* arg);
4748
4849 // Tag set (value) command
4950 int com_set(char* arg);
51 int com_setuid(char* arg);
5052
5153 // Key operations
5254 int com_keys_load(char* arg);