Welcome, Guest! Log In | Create Account

Changeset 45603

Show
Ignore:
Timestamp:
11/01/09 22:27:10 (2 months ago)
Author:
lordhoto
Message:

Add command line parameter to automatically create a search table entry from a given file + offset/size pair.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • scummvm/trunk/tools/create_kyradat/create_kyradat.cpp

    r45082 r45603  
    477477                printHelp(argv[0]); 
    478478                return -1; 
     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; 
    479520        } 
    480521