Changeset 2366419 in thomson


Ignore:
Timestamp:
Mar 20, 2016, 10:03:34 PM (8 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
15d3e8a
Parents:
f7d1bc3
Message:

binxploder: allow to list only, without dumping to file.

git-svn-id: svn://localhost/thomson@67 85ae3b6b-dc8f-4344-a89d-598714f2e4e5

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/binxploder.cpp

    rf7d1bc3 r2366419  
    1313int main(int argc, char* argv[])
    1414{
    15         if (argc < 2)
     15        bool listOnly = false;
     16
     17        if (argc < 2 || strcmp(argv[1], "--help") == 0)
    1618        {
    17                 fprintf(stderr, "%s file.bin\n", argv[0]);
     19                fprintf(stderr,
     20                        "%s file.bin [-l]\n(-l: list only, don't write sections)\n",
     21                        argv[0]);
    1822                return 1;
    1923        }
     24
     25        if (argc > 2)
     26                listOnly = true; // FIXME use getopt or something
    2027
    2128        FILE* f1, * f2;
    2229        uint8_t i = 0;
    2330        DECB_Chunk h;
     31        char* buf = NULL;
    2432
    2533        f1 = fopen(argv[1], "rb");
    26         char* buf = (char*)malloc(strlen(argv[1] + 3));
     34
     35        if (f1 < 0)
     36        {
     37                perror("Could not open input file");
     38                exit(-1);
     39        }
     40
     41        if (!listOnly)
     42                buf = (char*)malloc(strlen(argv[1] + 3));
    2743
    2844        while(DECB_ReadChunk(f1, h))
    2945        {
    30                 printf("Type: %02x - Size: %04x - Load: %04x\n", h.type, h.length, h.addr);
     46                printf("Type: %02x - Size: %04x - %s: %04x\n", h.type, h.length,
     47                        h.type == 0xFF ? "Exec" : "Load", h.addr);
    3148
    32                 sprintf(buf, "%s.%02x", argv[1], i++);
    33                 f2 = fopen(buf, "wb");
     49                if (!listOnly)
     50                {
     51                        sprintf(buf, "%s.%02x", argv[1], i++);
     52                        f2 = fopen(buf, "wb");
    3453
    35                 fwrite(&h.data[0], h.length, 1, f2);
     54                        fwrite(&h.data[0], h.length, 1, f2);
    3655
    37                 fclose(f2);
     56                        fclose(f2);
     57                }
    3858        }
    3959
    4060        free(buf);
    41 
    4261        fclose(f1);
    43 
    4462        return 0;
    4563}
Note: See TracChangeset for help on using the changeset viewer.