| | 479 | } |
| | 480 | |
| | 481 | // Special case for developer mode of this tool: |
| | 482 | // With "--create filename offset size" the tool will output |
| | 483 | // a search entry for the specifed data in the specified file. |
| | 484 | if (!strcmp(argv[1], "--create")) { |
| | 485 | if (argc < 5) { |
| | 486 | printf("Developer usage: %s --create input_file hex_offset hex_size\n", argv[0]); |
| | 487 | return -1; |
| | 488 | } |
| | 489 | |
| | 490 | uint offset, size; |
| | 491 | sscanf(argv[3], "%x", &offset); |
| | 492 | sscanf(argv[4], "%x", &size); |
| | 493 | |
| | 494 | FILE *input = fopen(argv[2], "rb"); |
| | 495 | if (!input) |
| | 496 | error("Couldn't open file '%s'", argv[2]); |
| | 497 | |
| | 498 | byte *buffer = new byte[size]; |
| | 499 | fseek(input, offset, SEEK_SET); |
| | 500 | if (fread(buffer, 1, size, input) != size) { |
| | 501 | delete[] buffer; |
| | 502 | error("Couldn't read from file '%s'", argv[2]); |
| | 503 | } |
| | 504 | |
| | 505 | fclose(input); |
| | 506 | |
| | 507 | SearchData d = SearchCreator::create(buffer, size); |
| | 508 | delete[] buffer; |
| | 509 | |
| | 510 | printf("{ 0x%.08X, 0x%.08X, { {", d.size, d.byteSum); |
| | 511 | for (int j = 0; j < 16; ++j) { |
| | 512 | printf(" 0x%.2X", d.hash.digest[j]); |
| | 513 | if (j != 15) |
| | 514 | printf(","); |
| | 515 | else |
| | 516 | printf(" } } }\n"); |
| | 517 | } |
| | 518 | |
| | 519 | return 0; |